相信通过前面4篇笔记,大家对redis的基本概念及配置已经有了解,本篇笔记重点说明如何通过官方发布的redis sentinel工具来监控redis的运行状态。另外,对sentinel使用过程中的注意事项做些讨论。
1. Redis Sentinel功能Redis Sentinel是一套用于管理Redis实例的分布式系统,主要完成3项任务:
1) Monitoring:持续监控Redis master或slave实例的运行情况是否符合预期
2) Notification:若被监控的Redis实例运行异常,sentinel会通过API通知外界(人或程序)
3) Automation failover:若master实例故障,sentinel会重新选主并启动自动故障切换:选择slave-priority最小的那个slave实例并将其提升为master,同时修改其它slave的配置,使其master配置项指向新的master,当old master恢复重启后,会自动降级为new master的slave。最后,根据配置,Redis Sentinel还会将新的master地址通知给当前正在访问Redis的应用程序。
2. Redis Sentinel部署
Sentinel作为一个分布式系统工具,建议多机房多机部署。
每个sentinel实例主要有6个配置项,按Redis集群的实际部署情况进行配置即可,示例如下:
port 26329
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster
sentinel notification-script <master-name> <script-path>
其中:port: 指定sentinel的侦听端口(即与redis se