redis哨兵
節(jié)點準備 、主從復制配置參考上篇博客
一、從解壓的redis文件夾下拷貝sentinel.conf 哨兵文件至/opt/redis/conf里做公共配置文件
cp sentinel.conf /opt/redis/conf/sentinel-public.conf
二、配置公共文件
# port 26379 注釋哨兵監(jiān)聽端口默認監(jiān)聽自己 sentinel monitor mymaster 127.0.0.1 6379 2 指示sentinel去監(jiān)視一個名為master的主服務器,這個服務器的ip port 而將這個服務器判斷為失效至少需要1個,一般設置為2個 (一般大于等于一半,7個填4,5個填3)
sentinel auth-pass mymaster 123456 設置master和slaves的密碼
sentinel down-after-milliseconds mymaster 30000 sentinel 認為服務器已經(jīng)短線的毫秒數(shù)默認30秒
sentinel failover-timeout mymaster 180000 三分鐘內(nèi)未完成故障遷移即認為失敗
protected-mode no 關閉保護模式
daemonize yes 后臺運行
#################################################
三、創(chuàng)建三個sentinel配置文件
touch sentinel-26379.conf touch sentinel-26380.conf touch sentinel-26381.conf
四、配置文件
# 引用公共文件 include /opt/redis/conf/sentinel-public.conf # 進程端口號 port 26379 # 進程編號記錄文件 pidfile /var/run/sentinel-26379.pid # 日志記錄文件 logfile "/opt/redis/log/sentinel-26379.log"
其余三個文件復制粘貼即可 記得改下端口 替換快捷命令 :%s/舊的/新的
五、啟動哨兵
/usr/local/bin/redis-sentinel /opt/redis/conf/sentinel-26379.conf /usr/local/bin/redis-sentinel /opt/redis/conf/sentinel-26380.conf /usr/local/bin/redis-sentinel /opt/redis/conf/sentinel-26381.conf
[root@iZbp18g9d6dss3gia7kersZ conf]# ps -ef | grep redis root 3354 1 0 18:49 ? 00:00:00 /usr/local/bin/redis-sentinel *:26379 [sentinel] root 3360 1 0 18:49 ? 00:00:00 /usr/local/bin/redis-sentinel *:26380 [sentinel] root 3366 1 0 18:49 ? 00:00:00 /usr/local/bin/redis-sentinel *:26381 [sentinel] root 3372 29683 0 18:49 pts/0 00:00:00 grep --color=auto redis root 31590 1 0 17:10 ? 00:00:05 /usr/local/bin/redis-server *:6379 root 31637 1 0 17:10 ? 00:00:06 /usr/local/bin/redis-server *:6380 root 31678 1 0 17:11 ? 00:00:06 /usr/local/bin/redis-server *:6381 root 32051 31933 0 17:14 pts/1 00:00:00 redis-cli -p 6380 root 32052 32013 0 17:14 pts/2 00:00:00 redis-cli -p 6381
啟動成功
六、驗證
殺掉6379的主服務器 后發(fā)現(xiàn)6380自動切換為主服務器了 當6379重啟后 6379變成從服務器加入節(jié)點

浙公網(wǎng)安備 33010602011771號