redis主从与sentinel哨兵配置

reids主重配置
拷贝redis.conf 为redis6388.conf redis6389.conf
启动主服务器
修改重两个配置文件
port 6388 //对应端口修改
pidfile /var/run/redis_6388.pid //对应pid文件修改
replicaof localhost 6379 //连接主服务器 masterauth 12345 //主服务器密码
分别启动两台重服务器
info replication 查看服务器状态是否有重服务器连接



redis数据恢复
copy aof文件进行启动




运行动态主重修改(主服务器挂掉了)
修改一台slave为master
1:slaveof no one //不做任何其他redis的slave
2:salve-red-only no //修改为可写 config set salve-read-only no
slave服务器
slaveof localhost 6380




利用哨兵sentinel监控master自动切换
1:redis源码文件copy sentinel.conf 哨兵配置文件到redis下
2:修改哨兵配置文件sentinel.conf

//sentinel去监听地址为ip:port的一个master,这里的mymaster 可以自定义,quorum是一个数字,指明当有多少个sentinel认为一个master失效时,master才算真正失效
sentinel monitor mymaster 127.0.0.1 6379 2

//设定密码
sentinel auth-pass mymaster 123

//这个配置项指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的。 单位是毫秒,默认为30秒
sentinel down-after-milliseconds mymaster 30000

//这个配置项指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行 同步,这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越 多的slave因为replication而不可用。可以通过将这个值设为 1 来保证每次只有一个slave 处于不能处理命令请求的状态
sentinel parallel-syncs mymaster 1

如果需要制定某个重机器为首选master 可以调整该节点下的配置文件优先级
slave-priority 100 //数越大权重越高


取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论