Day24 Redis架构实战-Sentinel丛集架构

sentinel.conf

# 高可用配置搭配Sentinel机制
                           --->   Redis (Replica)
client ---> Redis (Master)
                           --->   Redis (Replica)
-------------------------------------------------
                sentinel
  • 依照以上的配置,Master与Replica间会自动同步资料,Sentinel则为持续的监控Master是否正常,当Master挂掉时,会把Replica依照优先权与健康程度选取合适的切换为Master提供用户端服务.但是目前Sentinel只有一台,代表如果Sentinel挂掉的时候又会发生单点异常造成整个Redis 服务不会自动切换Master,而造成服务因此中断的问题,故在正式环境中建议sentinel也是要有丛集的配置.
# 高可用配置搭配Sentinel丛集架构
                           --->   Redis (Replica)
client ---> Redis (Master)
                           --->   Redis (Replica)
-------------------------------------------------
       sentinel    sentinel    sentinel

# 复制三份设定档,结尾用Port命名
cp sentinel_26379.conf sentinel_26380.conf 
cp sentinel_26379.conf sentinel_26381.conf 

# 修改各个设定档中的port与monitor需要设定成2,搭配目前redis server (Master) 127.0.0.1 6380
# sentinel_26379.conf
vi sentinel_26379.conf
port 26379
daemonize yes
logfile "/tmp/redis-sentinel_26379.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

# sentinel_26380.conf
vi sentinel_26380.conf
port 26380
daemonize yes
logfile "/tmp/redis-sentinel_26380.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

# sentinel_26381.conf
vi sentinel_26381.conf
port 26381
daemonize yes
logfile "/tmp/redis-sentinel_26381.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

# 启动三个sentinel
./redis-sentinel sentinel_26379.conf
./redis-sentinel sentinel_26380.conf
./redis-sentinel sentinel_26381.conf

# 确认是否正常运作
ps -ef|grep redis-se

https://ithelp.ithome.com.tw/upload/images/20211009/2011165897duG4ZZXw.png

  • 实际Sentinel Monitor 运作机制
    • 每10秒,每个Sentinel 会对Redis Server的Master与Replica连接并送出info取得目前状态
    • 每2秒,每个Sentinel 会对Redis Server的Master连接并通过channel做pub/sub来测试是否服务正常
    • 每1秒,每个Sentinel 会对Redis Server的Master与Replica,还有自身以外的Sentinel进行ping的动作

https://ithelp.ithome.com.tw/upload/images/20211009/201116587Cw44my32H.png

  • 为什麽sentinel monitor 组态需要特别设定2个以上(多数) 的sentinel才可以决定选出新的Redis Server 的Master,因为有可能因爲网路的延迟造成某个sentinel监控Redis Server Master时发生误判,进而直接就切换到了别台Redis Master.

  • Master离线机制

    • 主观离线
      • 由某个Sentinel侦测到Master离线,并会要求其他Sentinel侦测是否Master已经离线.
    • 客观离线
      • 当多个Sentinel侦测Master离线的数量达到Sentinel Monitor设定的quorun数量时,则会进行选举Replice切换Master的机制.
      • 首先多个Sentinel之间会先选出Sentinel Leader的角色来进行後续的动作,某个Sentinel侦测到Master离线时,会向其他Sentinel发起投票要求选自己成为Sentinel Leader,需要达到设定的quorun数量才会完成此次选举,当结果选出多个Leader时,则会重新选举直到选出唯一的Sentinel Leader.

<<:  30天打造品牌特色电商网站 Day.24 电商必用的各类提示

>>:  Day 27 Realm的练习-使用者注册系统(1/3)

人脸辨识-day29

在模型训练完成後,最终需要可以即时在侦测到人脸後辨识出来,可先设定当摄影机开启後的画面长宽与一些影像...

LeetCode解题 Day23

1328. Break a Palindrome https://leetcode.com/prob...

Day14 - 动态 新增/删除 Collection 项目(二) - Html Helper

这篇调整的方向是 透过 Partial View 来 Render Collection 项目 透过...

第19车厢-娃!网页必备的响应式轮播效果怎麽刻?

本篇分享简易版的RWD的轮播效果功能 上一篇我们有简约的使用tab做轮播,但一般想做的轮播应该会是...

Day 15 - Ping Sweeping 与 Port Scanning

出於书本 Chapter 8. Network Infrastructure 撑过一半了加油加油加油...