Redis哨兵安裝步驟redis
----------------------------------ide
以前的redis6379.conf的配置不變,作爲主節佔,而且複製出兩個配置文件redis6380.conf, redis6381.conf,這兩個配置文件啓動後的redis作爲6379節點的從節點。:測試
注意:redis6380.conf和redis6381.conf 加上slaveof 127.0.0.1 6379ui
修改 requirepass 12345678 ,註釋掉bind 127.0.0.1, 加上masterauth 12345678spa
redis sentinel哨兵機制配置(也是3個節點):.net
/usr/local/bin/conf/sentinel_26379.conf 日誌
/usr/local/bin/conf/sentinel_26380.confserver
/usr/local/bin/conf/sentinel_26381.conf進程
將三個文件的端口改爲: 26379 26380 26381資源
而後:sentinel monitor mymaster 127.0.0.1 6379 2 //監聽主節點6379
sentinel auth-pass mymaster 12345678 //鏈接主節點時的密碼
三個配置除端口外,其它同樣。
啓動sentinel服務:
./redis-sentinel conf/sentinel_26379.conf &
./redis-sentinel conf/sentinel_26380.conf &
./redis-sentinel conf/sentinel_26381.conf &
殺掉進程
ps -ef|grep redis-server |grep 6379 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-server |grep 6380 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-server |grep 6381 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26379 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26380 | grep -v grep | awk '{print $2}' | xargs kill -9
ps -ef|grep redis-sentinel |grep 26381 | grep -v grep | awk '{print $2}' | xargs kill -9
啓動進程
../redis-server redis6379.conf &
../redis-server redis6380.conf &
../redis-server redis6381.conf &
../redis-sentinel sentinel_26379.conf &
../redis-sentinel sentinel_26380.conf &
../redis-sentinel sentinel_26381.conf &
測試:
kill -9 6379 殺掉6379的redis服務
看日誌是分配6380 仍是6381作爲主節點,當6379服務再啓動時,已變成從節點
若是6380升級爲主節點:進入6380>info replication 能夠看到role:master
打開sentinel_26379.conf等三個配置,sentinel monitor mymaster 127.0.0.1 6380 2
外部應用鏈接sentinel時, sentinel.conf的protected-mode no改爲no
./redis-cli -p 26380 shutdown //關閉