(查看Redis信息和狀態,https://my.oschina.net/tongyufu/blog/405612)html
教程步驟:https://my.oschina.net/u/2331760/blog/2243505redis
cd /usr/local/redis-ms/ vim
mkdir -p ./sentinel/26001/tmp測試
cp /usr/local/redis/sentinel.conf ./sentinel/26001/spa
cd /usr/local/redis-ms/sentinel/.net
vim ./26001/sentinel.conf命令行
#修改以下鍵值對rest
# bind 127.0.0.1 192.168.1.1#註釋掉或者值爲0.0.0.0server
protected-mode no#關閉保護模式htm
port 26001#端口號
daemonize yes#後臺運行
dir /usr/local/redis-ms/sentinel/26001/tmp#解除掛載信息目錄
sentinel monitor mymaster 192.168.194.131 6381 1#設置 主名稱 ip地址 端口號 參入選舉的哨兵數
sentinel down-after-milliseconds mymaster 3000#sentinel心跳檢測主3秒內無響應,視爲掛掉,開始切換其餘從爲主
sentinel parallel-syncs mymaster 1#每次最多能夠有1個從同步主。一個從同步結束,另外一個從開始同步。
sentinel failover-timeout mymaster 18000#主從切換超時時間
1.先啓主從redis
/usr/local/redis/src/redis-server /usr/local/redis-ms/6381/redis.conf
/usr/local/redis/src/redis-server /usr/local/redis-ms/6382/redis.conf
/usr/local/redis/src/redis-server /usr/local/redis-ms/6383/redis.conf
ps -ef|grep redis
如圖已經啓動
且信息正確
/usr/local/redis/src/redis-cli -p 6381
info
/usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26001/sentinel.conf
ps -ef|grep redis
如圖已經啓動
且信息正確
/usr/local/redis/src/redis-cli -p 26001
info
/usr/local/redis/src/redis-cli -p 6381 shutdown
/usr/local/redis/src/redis-cli -p 26001
info
/usr/local/redis/src/redis-server /usr/local/redis-ms/6381/redis.conf
/usr/local/redis/src/redis-cli -p 6381
info
cd /usr/local/redis-ms/sentinel/
cp -r 26001 26002
vim 26002/sentinel.conf
#將文本中26001替換爲26002
:%s/26001/26002/g
/usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26002/sentinel.conf
info
/usr/local/redis/src/redis-cli -p 26002
注:redis開機啓動參照https://www.cnblogs.com/zwcry/p/9046207.html
mkdir /usr/local/redis-ms/sentinel/script
cd /usr/local/redis-ms/sentinel/script/
vim start.sh
#!/bin/sh /usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26001/sentinel.conf /usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26002/sentinel.conf
vim stop.sh
#!/bin/sh /usr/local/redis/src/redis-cli -p 26001 shutdown /usr/local/redis/src/redis-cli -p 26002 shutdown
vim restart.sh
#!/bin/sh systemctl stop redis-sentinel systemctl start redis-sentinel
cd /usr/lib/systemd/system/
vim redis-sentinel.service
[Unit] Description=redis-sentinel After=redis-ms.service [Service] Type=forking ExecStart=/usr/local/redis-ms/sentinel/script/start.sh ExecStop=/usr/local/redis-ms/sentinel/script/stop.sh ExecReload=/usr/local/redis-ms/sentinel/script/restart.sh [Install] WantedBy=multi-user.target
#建議啓動redis服務後,再啓動哨兵
改變權限
chmod 777 redis-sentinel.service
chmod 777 /usr/local/redis-ms/sentinel/script/*
進程服務重加載
systemctl daemon-reload
開機啓動哨兵
systemctl enable redis-sentinel.service
啓動哨兵
systemctl start redis-sentinel.service
關閉哨兵
systemctl stop redis-sentinel.service
重啓哨兵
systemctl restart redis-sentinel.service
若是測試sentinel的時候,始終沒有在sentinel的窗口中看到slave,宕掉master,亦不能進行主從切換,那麼可能的緣由是:redis.conf中配置了密碼,而sentinel裏面沒有配置密碼項,致使監測不到redis,這個時候必須加上密碼受權配置,
而且此sentinel monitor <master-name> <ip> <redis-port> <quorum>
需放在sentinel auth-pass <mymaster> <0123passw0rd>的前面。
備註:哨兵集羣服務自主關聯響應,若是須要更多哨兵集羣,按照26002的方式複製26003...26006便可