Redis一主二從Sentinel監控配置


本文基於Redis單實例安裝安裝。
https://gper.club/articles/7e7e7f7ff7g5egc4g6b

開啟哨兵模式,至少需要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/soft/redis-5.0.5
mkdir logs
mkdir rdbs
mkdir sentinel-tmp
vim sentinel.conf

sentinle.conf配置文件內容,三台機器相同

daemonize yes
port 26379
protected-mode no
dir "/usr/local/soft/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/soft/redis-5.0.5/src
./redis-server ../redis.conf
./redis-sentinel ../sentinel.conf

在3台機器上查看集群狀態:

redis> info replication

2.png

模擬master宕機,在203執行:

redis> shutdown

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

redis> info replication

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

slave宕機和恢復測試省略。

轉載出處:https://gper.club/articles/7e7e7f7ff7g5egc7g6a


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM