有了主从复制,如果我想想对主从服务器进行监控,在redis2.6后提供了哨兵机制,2.6有哨兵1.0版本,并不稳定。2.8以后的哨兵功能才稳定起来。
顾名思义,哨兵就是监控Redis系统的运行状况,其主要功能有两点:
- 监控主数据库和从数据库是否正常运行
- 主数据库出现故障时,可以自动将从数据转换为主数据,实现自动切换
实现步骤:
- 在其中一台从服务器配置sentinel.conf
- copy文件sentinel.conf文件到/usr/local/redis/etc/中
- 修改sentinel.conf文件
sentinel monitor mymaster 192.168.1.17 6379 1 #名称 ip 端口 选票次数
sentinel down-after-milliseconds mymaster 5000 #默认1s检测一次,这里配置超时5000毫秒
sentinel failover-timeout mymater 800000
sentinel parallel-syncs mymaster 2
sentinel can-failover mymaster yes
- 启动sentinel哨兵 :/usr/local/redis/bin/redis-server /usr/local/redis/etc/sentinel.conf --sentinel &
- 查看哨兵相关信息命令
/usr/local/redis/bin/redis-cli -h 192.168.17 -p 26379 info sentinel
- 关闭主服务器查看集群信息
/usr/local/redis/bin/redis-cli -h 192.168.1.17 -p 6379 shutdown
架构师养成记--33.Redis哨兵
原文:http://www.cnblogs.com/sigm/p/6507545.html