redis3哨兵配置

绝地灬酷狼 2022-04-11 09:51 283阅读 0赞

linux下安装redis 启动,停止,连接 编辑 删除

http://happyqing.iteye.com/blog/2348255

linux安装redis主备安装配置

http://happyqing.iteye.com/blog/2353516

建议最少配3个哨兵,

如果只有两台服务器,(一个服务器也可装多个redis,端口不同)

主redis服务器,1个哨兵

从redis服务器,2个哨兵

java端配置连接池,连接多个哨兵

http://blog.csdn.net/csolo/article/details/53196293

在一台机器上测试

sentinel26379.conf

  1. #保护模式
  2. protected-mode no
  3. #端口
  4. port 26379
  5. #守护进程
  6. #daemonize yes
  7. #设置pid文件路径
  8. pidfile /opt/redis/sentinel_26379.pid
  9. #工作路径,不用改
  10. dir /tmp
  11. #设置日志文件路径
  12. #logfile /opt/redis/logs/sentinel26379.log
  13. # 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
  14. # (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
  15. # slaves是自动发现,不用指定slaves。
  16. sentinel monitor mymaster 192.168.2.11 6379 2
  17. # master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
  18. sentinel down-after-milliseconds mymaster 10000
  19. #选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
  20. sentinel parallel-syncs mymaster 1
  21. #若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
  22. sentinel failover-timeout mymaster 180000
  23. #设置master和slaves的密码
  24. sentinel auth-pass mymaster redis2016

sentinel26380.conf

  1. #保护模式
  2. protected-mode no
  3. #端口
  4. port 26380
  5. #守护进程
  6. #daemonize yes
  7. #设置pid文件路径
  8. pidfile /opt/redis/sentinel_26380.pid
  9. #工作路径,不用改
  10. dir /tmp
  11. #设置日志文件路径
  12. #logfile /opt/redis/logs/sentinel26380.log
  13. # 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
  14. # (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
  15. # slaves是自动发现,不用指定slaves。
  16. sentinel monitor mymaster 192.168.2.11 6379 2
  17. # master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
  18. sentinel down-after-milliseconds mymaster 10000
  19. #选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
  20. sentinel parallel-syncs mymaster 1
  21. #若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
  22. sentinel failover-timeout mymaster 180000
  23. #设置master和slaves的密码
  24. sentinel auth-pass mymaster redis2016

sentinel26381.conf

  1. #保护模式
  2. protected-mode no
  3. #端口
  4. port 26381
  5. #守护进程
  6. #daemonize yes
  7. #设置pid文件路径
  8. pidfile /opt/redis/sentinel_26381.pid
  9. #工作路径,不用改
  10. dir /tmp
  11. #设置日志文件路径
  12. #logfile /opt/redis/logs/sentinel26381.log
  13. # 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
  14. # (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
  15. # slaves是自动发现,不用指定slaves。
  16. sentinel monitor mymaster 192.168.2.11 6379 2
  17. # master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
  18. sentinel down-after-milliseconds mymaster 10000
  19. #选项指定了在执行故障转移时, 最多可以有多少个从服务器同时对新的主服务器进行同步, 这个数字越小, 完成故障转移所需的时间就越长。
  20. sentinel parallel-syncs mymaster 1
  21. #若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
  22. sentinel failover-timeout mymaster 180000
  23. #设置master和slaves的密码
  24. sentinel auth-pass mymaster redis2016

sentinel monitor mymaster 192.168.2.11 6379 2

这个要配局域网IP,否则远程连不上,

最后的quorum最后配成2,否则容易切换失败

模拟

可以同时结束redis6379,sentinel26379的进程

查看redis6380日志

查看sentinel26380和sentinel26381的日志,

可以看到主从切换的过程

启动

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26379.conf

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26380.conf

/opt/redis/bin/redis-sentinel /opt/redis/conf/sentinel26381.conf

连接

/opt/redis/bin/redis-cli -h 192.168.2.11 -p 26379 -a redis2016

停止

/opt/redis/bin/redis-cli -h 192.168.2.11 -p 26379 -a redis2016 shutdown

发表评论

表情:
评论列表 (有 0 条评论,283人围观)

还没有评论,来说两句吧...

相关阅读