Redis 的主从复制模式下,一旦主节点由于故障不能提供服务,需要人工将从节点晋升为主节点,同时还要通知应用方更新主节点地址,对于很多应用场景这种故障处理的方式是无法接受的。Redis 从2.8 开始,正式提供了 Redis Sentinel 架构来解决这个问题。
1. 参考
- 《Redis 开发与运维》
https://learnku.com/articles/30506https://learnku.com/articles/56442
2. Redis 主从复制配置文档
- url 地址:
https://juejin.cn/post/6965133752846680071
3. Redis Sentinel 物理结构
| 角色 | ip | port | 配置文件名 | 备注 |
|---|---|---|---|---|
| master | 192.168.51.145 | 6379 | redis.conf | 主节点 |
| slave | 192.168.51.146 | 6379 | redis.conf | 从节点 |
| slave | 192.168.51.147 | 6379 | redis.conf | 从节点 |
| slave | 192.168.51.148 | 6379 | redis.conf | 从节点 |
| slave | 192.168.51.149 | 6379 | redis.conf | 从节点 |
| sentinel-1 | 192.168.51.145 | 26379 | sentinel.conf | sentinel-1 节点 |
| sentinel-2 | 192.168.51.146 | 26379 | sentinel.conf | sentinel-2 节点 |
| sentinel-3 | 192.168.51.147 | 26379 | sentinel.conf | sentinel-3 节点 |
| sentinel-4 | 192.168.51.148 | 26379 | sentinel.conf | sentinel-4 节点 |
| sentinel-5 | 192.168.51.149 | 26379 | sentinel.conf | sentinel-5 节点 |
4. 配置文件
- sentinel 配置文件,各个服务器上面都是一样的
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
logfile "/usr/local/redis/log/sentinel.log"
dir "/usr/local/redis/data"
sentinel monitor mymaster 192.168.51.145 6379 3
sentinel auth-pass mymaster foobared
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
requirepass sentinel_foobared
sentinel sentinel-pass sentinel_foobared
5. 运行 sentinel
/usr/local/redis/sentinel /usr/local/redis/conf/sentinel.conf
- 配置文件百度网盘地址
链接:
https://pan.baidu.com/s/1cBNyRH-iMq5PA7R-CZkLAQ提取码:
c0ak