缓存中间件Redis Sentinel高可用组件
2022-09-19 本文已影响0人
右耳菌
1. Redis Sentinel 简介
1.1 什么是Redis Sentinel?
Redis Sentinel provides high availability for Redis.Inpractical terms this means that using Sentinel you cancreate a Redis deployment that resists without humanintervention certain kinds of failures.
即 : 只负责Redis主从高可用自动化运维的官方组件
1.2 Redis Sentinel 解决了什么?
- 异常监测
对于主从状态的实时探活,监测异常状态,为故障切换提供依据 - 故障切换
当监测到异常发生时,如何进行切换:
a. 执行主从状态角色变更
b. 故障切换后,通知用户客户端发生切换 - 故障恢复
恢复到主从多副本的高可用状态
a. 人工运维,重新恢复副本数
b. 自动感知,恢复副本数
1.3 Redis Sentinel优缺点
-
客户端无感知型
1

- 客户端感知型

- 对比

2. Redis Sentinel 高可用原理
2.1 Redis Sentinel 相关配置
- sentinel monitor <master-name><ip><redis-port>quorum
sentinel监听地址为ip:port的master,这里的master-name可以自定义,quorum是一个数字,指明当有多少个sentinel认为一个master失效时,master才算真正失效
例如:
sentinel monitor mymaster 127.0.0.1 6379 2
- sentinel down-after-milliseconds <master-name><milliseconds>
指定了需要多少失效时间,一个master才会被这个sentinel主观地认为是不可用的
默认:
sentinel down-after-milliseconds mymaster 30000
- sentinel parallel-syncs <master-name> <numslaves>
指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行同步,这个数字越小,完成failover所需的时间就越长,但是如果这个数字越大,就意味着越多的slave因为主从同步而不可用。
默认:
sentinel parallel-syncs mymaster 1
- sentinel failover-timeout<master-name><milliseconds>
failover-timeout可以用在以下这些方面:
1.同一个sentinel对同一个master两次failover之间的间隔时间。2.当想要取消一个正在进行的failover所需要的时间。
其他一些情况可以不用了解
默认:
sentinel failover-timeout mymaster 180000
2.2 Redis Sentinel 故障监测
-
Redis 实例发现
-
Sentinel实例发现
-
心跳探活
-
自动failover
-
手动failover
2.3 Redis Sentinel 故障恢复
- Slave挂了
直接拉起原有的slave实例,ip和port相关没有变化,sentinel会自动感知,并加入主从group中 - Master挂了
直接拉起原有的master实例,ip 和port相关没有变化,sentinel会自动感知,并加入主从group中 - 新增节点
直接slaveof到新的master即可,sentinel会自动感知,并加入主从group中
如果觉得有收获就点个赞吧,更多知识,请点击关注查看我的主页信息哦~