文章目錄
- 一、概念架構簡述
- 1. Redis Sentinel簡述
- 2. Redis Sentinel優點
- 3. Redis Sentinel缺點
- 二、哨兵搭建實作
- 2.1. 編寫配置檔案
- 2.2. 啟動rendis
- 2.3. 啟動sentinel服務
- 2.4. 檢視哨兵啟動日志
- 2.5. 日志詳情
一、概念架構簡述
1. Redis Sentinel簡述
Redis Sentinel是分布式系統中監控Redis主從伺服器,并從主伺服器下顯示自動故障轉移的模式。
其中4個特性為監控、提醒、自動故障轉移、配置提供者。
2. Redis Sentinel優點
- 哨兵 是基于主從模式的,所有主從的優點,哨兵模式都有。
- 主從可以自動切換,系統更健壯,可用性高。
- Sentinel會不斷的檢查你的主伺服器是否運作正常。當被監控的某一個Redis 出現問題是,Sentinel可以通過API向管理者或者其他應用程式發送通知。
3. Redis Sentinel缺點
- 主從切換需要時間,丢失資料
- 還是沒有解決主節點寫的壓力
- 主節點的寫能力,存儲能力受到單機的限制;動态擴充困難複雜,對于叢集,容量- 達到上限時再現擴容會變得很複雜。
二、哨兵搭建實作
2.1. 編寫配置檔案
三個節點分别建立sentinel.conf,依次執行下面指令:
vim /usr/local/redis/conf/sentiel.conf
并添加以下配置(3個節點配置一樣)
# 放行所有ip限制
bind 0.0.0.0
# 程序端口号
port 26379
# 背景啟動
daemonize yes
# 日志記錄檔案
logfile "/usr/local/redis/log/sentinel.log"
# 程序編号記錄檔案
pidfile /var/run/redis-sentinel.pid
# 提示Sentinel 去監視一個名為 mymaster 的主伺服器 仲裁 =環境3/2+1
sentinel monitor mymaster xxx.xxx.92.100 6379 2
# 通路主節點的密碼
sentinel auth-pass mymaster 123456
# Sentinel 認為伺服器已經斷線所需要的毫秒數 預設30秒 這裡示範10秒
sentinel down-after-milliseconds mymaster 10000
# 若Sentinel 在改配置值内未能完成 failover(故障轉移) 操作,則認為本次 failover 失敗180秒 3分鐘
2.2. 啟動rendis
# 檢視redis程序
ps -ef |grep redis
# 啟動redis服務
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
#檢視主從節點資訊
2.3. 啟動sentinel服務
/usr/local/redis/bin/redis-sentinel /usr/local/redis/conf/sentiel.conf
2.4. 檢視哨兵啟動日志
tail
2.5. 日志詳情
[root@bigdata01 ~]# tail -f /usr/local/redis/log/sentinel.log
13787:X 04 Jul 2021 22:20:34.112 # Configuration loaded
13787:X 04 Jul 2021 22:20:34.117 * Increased maximum number of open files to 10032 (it was originally set to 1024).
13787:X 04 Jul 2021 22:20:34.117 * monotonic clock: POSIX clock_gettime
13787:X 04 Jul 2021 22:20:34.121 * Running mode=sentinel, port=26379.
13787:X 04 Jul 2021 22:20:34.122 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
13787:X 04 Jul 2021 22:20:34.124 # Sentinel ID is 25a49df0916d6745eabf1fcfb56f150b345554a5
13787:X 04 Jul 2021 22:20:34.125 # +monitor master mymaster xxx.xxx.92.100 6379 quorum 2