在主從架構(gòu)狀態(tài)下,如果master節(jié)點宕機,則不可以進行寫操作,所以需要引入哨兵機制,重新選取master節(jié)點,保證Redis主從架構(gòu)正常運行。
1.在三個節(jié)點上分別修改配置文件sentinel.conf

image.png
1.bind: 如果redis暴露在公網(wǎng),需要配置bind ip
2.修改# protected-mode no 為 protected-mode no
3.修改daemonize no 為 daemonize yes
4.logfile /usr/local/redis/sentinel/redis-sentinel.log
5.dir /usr/local/redis/sentinel/
6.sentinel monitor mymaster 127.0.0.1 6379 2
mymaster為sentinel的昵稱
127.0.0.1 為master的ip,需要根據(jù)自己的環(huán)境進行修改
2 為哨兵的數(shù)量
7.修改sentinel auth-pass mymaster ’password‘
8.修改# sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds mymaster 10000
9.sentinel parallel-syncs mymaster 1
10.sentinel failover-timeout mymaster 180000
主備切換時間
2.啟動哨兵
src/redis-sentinel sentinel.conf