redis哨兵模式

redis持久化

Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为"半持久化模式"RDB);也可以把每一次数据变化都写入到一个 append only file(AOF)里面(这称为"全持久化模式")。

下载redis: yum install -y redis
启动redis:systemctl start redis
编译文件:vim /etc/redis.conf (搜索APPEND)

编译文件:vim /etc/redis.conf

重启redis服务:systemctl restart redis

在/etc/下复制文件:cp redis.conf redis_6379.conf

更改文件内309行

355行 改成自己文件名

cp redis_6379.conf redis_6380.conf

编辑文件 vim redis_6380.conf(改自己文件名,两处)

端口号138行

533行 写主的IP端口号

创建目录:mkdir /etc/redis

mv redis_63* redis

创建6381:cp redis_6379.conf redis_6381.conf

更改6381文件:sed -i 's/6379/6381/' redis_6381.conf

启动所有redis服务:for i in 6379 6380 6381; do redis-server /etc/redis/redis_${i}.conf;done
注意!!!其他IP地址改从同理

创建哨兵文件:mkdir redis_sentinel

cp /etc/redis-sentinel.conf /etc/redis_sentinel/

mv redis-sentinel.conf redis-sentinel_26379.conf (更改3处)

再复制两个文件

cp redis-sentinel_26379.conf redis-sentinel_26380.conf

cp redis-sentinel_26379.conf redis-sentinel_26381.conf

sed -i 's/6379/6380/' redis-sentinel_26380.conf

sed -i 's/6379/6381/' redis-sentinel_26381.conf

sed -i 's/127.0.0.1 6379/192.168.11.133 6379/' redis-sentinel_26379.conf

sed -i 's/127.0.0.1 6380/192.168.11.133 6379/' redis-sentinel_26380.conf

sed -i 's/127.0.0.1 6381/192.168.11.133 6379/' redis-sentinel_26381.conf

验证

grep -r '192.168.11.133 6379' ./

轮个登录指向主:

redis-cli -h 192.168.11.133 -p 6380

slaveof 192.168.11.133 6379

redis-cli -h 192.168.11.133 -p 6381

slaveof 192.168.11.133 6379

验证:

开启哨兵:

redis-sentinel /etc/redis_sentinel/redis-sentinel_26379.conf

redis-sentinel /etc/redis_sentinel/redis-sentinel_26380.conf

redis-sentinel /etc/redis_sentinel/redis-sentinel_26381.conf

关闭主

验证:


在从的redis-cli中写入slaveof no one就可以摆脱从身份

相关推荐
瑞克-桑切斯21 小时前
4、MySQL 索引与事务
数据库·mysql
二宝哥21 小时前
【问题】本地启动springboot项目启动flowable引擎会提示数据库脚本错误,同事本地启动没有报错(MySQL表明大小写敏感参数)
数据库·mysql
John_Hui21 小时前
第 5 篇:Ubuntu 安装 Redis
数据库·redis·缓存
TDengine (老段)21 小时前
TDengine IDMP 十大实用功能(2)
大数据·数据库·chrome·时序数据库·tdengine·idmp·有问有答
Navicat中国21 小时前
Navicat 连接 Redis 数据库
数据库·redis·数据库开发·navicat
东方佑21 小时前
去魅:工具调用、Agent 调用、A2A、MCP、Harness 到底都是什么
服务器·网络·数据库
瑞克-桑切斯1 天前
2、 MySQL 主从复制与读写分离
数据库·mysql
收纳过往1 天前
数据库加索引的时机:慢查询日志说话
android·开发语言·数据库·python·低代码·rxjava
咖啡八杯1 天前
Redis 工具封装:RedisCache 对 Operations 体系的二次封装
java·数据库·redis·缓存·框架·springboot·若依