【Redis系列】深入浅出Redis主从复制之哨兵模式【实践】
接上文:深入淺出Redis主從復(fù)制之讀寫分離【一篇搞懂Redis復(fù)制】
在上文簡單的主從復(fù)制中,有一個(gè)這樣的問題,一旦master宕機(jī),就無法在客戶端完成寫操作。而哨兵模式剛好解決了這個(gè)問題。
Redis哨兵模式文檔:http://redis.cn/topics/sentinel.html
1.修改sentinel.conf文件
拷貝一份到指定目錄下:cp sentinel.conf /opt/redis/conf/
重命名:mv sentinel.conf sentinel-common.conf
touch sentinel-26379.conf
touch sentinel-26380.conf
touch sentinel-26381.conf
sentinel-26379.conf
sentinel-26380.conf
sentinel-26381.conf
修改共用的sentinel-common.conf
- 注釋port
- 修改daemonize為yes
- 修改protected-mode為no
- 注釋掉pidfile
- 注釋掉logfile
2.啟動sentinel集群
3.測試
復(fù)制三個(gè)窗口分別執(zhí)行
tail -f /opt/redis/log/sentinel-26379.log
tail -f /opt/redis/log/sentinel-26389.log
tail -f /opt/redis/log/sentinel-26381.log
接著斷開master,等待30s后就會出現(xiàn)重新選舉的主機(jī)。斷開的master會掛到新主機(jī)上作為replica。
總結(jié)
以上是生活随笔為你收集整理的【Redis系列】深入浅出Redis主从复制之哨兵模式【实践】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Redis系列】深入浅出Redis主从
- 下一篇: 【Redis系列】面试官:Redis中的