【Redis系列】深入浅出Redis主从复制之哨兵模式【实践】
接上文:深入淺出Redis主從復制之讀寫分離【一篇搞懂Redis復制】
在上文簡單的主從復制中,有一個這樣的問題,一旦master宕機,就無法在客戶端完成寫操作。而哨兵模式剛好解決了這個問題。
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.測試
復制三個窗口分別執行
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后就會出現重新選舉的主機。斷開的master會掛到新主機上作為replica。
總結
以上是生活随笔為你收集整理的【Redis系列】深入浅出Redis主从复制之哨兵模式【实践】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Redis系列】深入浅出Redis主从
- 下一篇: 【Redis系列】面试官:Redis中的