溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

centos7上配置redis哨兵

發(fā)布時間:2020-05-29 08:11:22 來源:網(wǎng)絡(luò) 閱讀:259 作者:劉小潭 欄目:系統(tǒng)運維

1 配置三個redis數(shù)據(jù)庫, 一主兩從

redis-6380.conf #主
redis-6381conf #從
redis-6382.conf #從
寫下以下配置文件

vim redis-6380.conf

port 6380
daemonize yes
pidfile /data/6380/redis.pid
loglevel notice
logfile "/data/6380/redis.log"
dbfilename dump.rdb
dir /data/6380
protected-mode no
再創(chuàng)建兩個配置文件6381和6382

sed "s/6380/6381/g" redis-6380.conf > redis-6381.conf
sed "s/6380/6382/g" redis-6380.conf > redis-6382.conf
創(chuàng)建數(shù)據(jù)文件目錄

mkdir -p /data/{6380,6381,6382}
給兩個從服務(wù)器配置文件再添加一行配置

在6381和6382配置文件添加這一行配置,表示指定主服務(wù)器為6380
slaveof 127.0.0.1 6380

2 啟動三個redis數(shù)據(jù)庫, 確保主從復(fù)制正常運行

redis-server redis-6380.conf
redis-server redis-6381.conf
redis-server redis-6382.conf

3 配置三個哨兵

cd /opt/redis/
vim redis-sentinel-16380.conf
vim redis-sentinel-16381.conf
vim redis-sentinel-16382.conf
寫入以下配置文件

port 16381
dir "/data/16381"
logfile "16381.log"
sentinel myid 3cf63a8e47b2372667013f8cdee7a3a5130d41fc
sentinel deny-scripts-reconfig yes
sentinel monitor qishimaster 127.0.0.1 6381 2
sentinel down-after-milliseconds qishimaster 60000
daemonize yes
哨兵配置文件詳解(不在步驟里面):

Sentinel節(jié)點的端口
port 26379
dir /var/redis/data/
logfile "26379.log"

sentinel announce-ip 127.0.0.1 # 宣告哨兵IP, 此配置只有當使用非127.0.0.1的IP配置哨兵無法成功時加上,同時redis三個服務(wù)端也需要同步修改IP

當前Sentinel節(jié)點監(jiān)控 127.0.0.1:6379 這個主節(jié)點
2代表判斷主節(jié)點失敗至少需要2個Sentinel節(jié)點節(jié)點同意
mymaster是主節(jié)點的別名
sentinel monitor mymaster 127.0.0.1 6379 2

每個Sentinel節(jié)點都要定期PING命令來判斷Redis數(shù)據(jù)節(jié)點和其余Sentinel節(jié)點是否可達,如果超過30000毫秒30s且沒有回復(fù),則判定不可達
sentinel down-after-milliseconds mymaster 30000

當Sentinel節(jié)點集合對主節(jié)點故障判定達成一致時,Sentinel領(lǐng)導(dǎo)者節(jié)點會做故障轉(zhuǎn)移操作,選出新的主節(jié)點,原來的從節(jié)點會向新的主節(jié)點發(fā)起復(fù)制操作,限制每次向新的主節(jié)點發(fā)起復(fù)制操作的從節(jié)點個數(shù)為1
sentinel parallel-syncs mymaster 1

故障轉(zhuǎn)移超時時間為180000毫秒
sentinel failover-timeout mymaster 180000

daemonize yes
創(chuàng)建存放哨兵文件的目錄

mkdir -p /data/{16380,16381,16382}
啟動三個哨兵

redis-sentinel redis-sentinel-16380.conf
redis-sentinel redis-sentinel-16381.conf
redis-sentinel redis-sentinel-16382.conf
查看哨兵是否成功通信

redis-cli -p 16380 info sentinel

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI