1. 程式人生 > 其它 >Redis一主二從Sentinel監控配置

Redis一主二從Sentinel監控配置

本文基於Redis單例項安裝安裝。
CentOS7安裝Redis單例項

開啟哨兵模式,至少需要3個Sentinel例項(奇數個,否則無法選舉Leader)。
本例通過3個Sentinel例項監控3個Redis服務(1主2從)。

IP地址 節點角色&埠
192.168.8.203 Master:6379 / Sentinel : 26379
192.168.8.204 Slave :6379 / Sentinel : 26379
192.168.8.205 Slave :6379 / Sentinel : 26379

防火牆記得關閉!!!

網路結構圖:

在204和205的redis.conf配置中新增一行

slaveof 192.168.8.203 6379

在203、204、205建立sentinel配置檔案(單例安裝後根目錄下預設有sentinel.conf,可以先備份預設的配置)

cd /usr/local/redis-5.0.5
mkdir logs
mkdir rdbs
mkdir sentinel-tmp
cp sentinel.conf sentinel.conf.bak
vim sentinel.conf

sentinel.conf配置檔案內容,三臺機器相同

daemonize yes
port 26379
protected-mode no
dir “/usr/local/redis-5.0.5/sentinel-tmp”

sentinel monitor redis-master 192.168.8.203 6379 2
sentinel down-after-milliseconds redis-master 30000
sentinel failover-timeout redis-master 180000
sentinel parallel-syncs redis-master 1

按著原有的順序更改,不要更改順序!!!

在3臺機器上分別啟動Redis和Sentinel

cd /usr/local/redis-5.0.5/src
./redis-server ../redis.conf
./redis-sentinel ../sentinel.conf

哨兵節點的另一種啟動方式:

./redis-server ../sentinel.conf --sentinel

在3臺機器上檢視叢集狀態:

$ /usr/local/soft/redis-5.0.5/src/redis-cli
redis> info replication

模擬master宕機,在203執行:

redis> shutdown

注意看sentinel.conf裡面的redis-master被修改了,變成了當前master的IP埠。

$ /usr/local/soft/redis-5.0.5/src/redis-cli
redis> info replication

這個時候會有一個slave節點被Sentinel設定為master。
再次啟動master,它不一定會被選舉為master。

slave宕機和恢復測試省略。

注意這裡有的同學遇到了坑,
1、slave可以顯示master資訊,而master沒有slave資訊。
2、master宕機後slave沒有被提升為master。

可能有幾個主要原因:
1、master資訊配置不正確。
2、還有偶陣雨Miao同學碰到的,需要配置auth-pass。
3.防火牆沒有關閉,主從都要關閉

原文:https://gper.club/articles/7e7e7f7ff2g51gc9g66