centos6.5 redis sentinel主從模式配置

redis版本爲3.0

192.168.1.133 主節點 

192.168.1.136 從節點 

主節點(192.168.1.133) 

配置redis.conf

daemonize yes                                   #讓redis後臺運行
pidfile /apps/run/redis/redis.pid       #指定redis的pid文件存放位置
port 6379                                             #redis使用端口                                           
logfile "/apps/logs/redis/redis.log"  #log文件的位置。如果爲空,則默認打印到/dev/null

設置密碼的請參考下面
requirepass 123456                          #redis的密碼,如果不需要密碼驗證,則可以不做修改
masterauth 123456                           #如果上面設置了redis的密碼,則這裏必須設置,而且要和他一樣。當該節點作爲從節點連接主節點時,要用到這個密碼和主節點做校驗。

啓動redis:

redis-server redis.conf

查看當前主從狀態:

redis-cli  -h 192.168.1.133 info Replication

配置sentinel.conf

port 26379                                                                            #sentinel使用的端口
daemonize yes                                                                    #sentinel後臺運行。這行配置是添加的
logfile "/apps/logs/redis/sentinel.log"                              #log文件地址,這行配置是添加的
sentinel monitor mymaster 192.168.1.133 6379 1       #指定master。後面的數字表示,當有幾個節點認爲主節點down時才認爲主節點進入ODOWN狀態,就是真正掛了。
sentinel down-after-milliseconds mymaster 5000        #當多久,連接不上節點時,認爲被連接節點進入S_DOWN(主觀認爲它down了);
sentinel failover-timeout mymaster 15000                     #這個配置有很多作用。1、重新執行failover的時間是該值的2倍;2、取消一個沒更改配置的failover3、failover中等待所有slave更改新的配置的最大時間。
sentinel auth-pass mymaster 123456                             #設置校驗的密碼。如果redis設置了密碼,這個一定要設置

啓動sentinel

redis-sentine sentinel.conf 

查看Sentinel的狀態

redis-cli -h192.168.1.133 -p 26379 info Sentinel




從節點(192.168.1.136)

redis.conf的配置與主節點只有一點不同,增加下面一行: 
slaveof 192.168.1.133  6379 
啓動redis 

src/redis-server redis.conf 
從節點查看主、從狀態: 
redis-cli -h 192.168.1.136  info Replication

sentinel的配置和主節點保持一致就可以

啓動sentinel: 
redis-sentine sentinel.conf 

查看sentinel狀態:

redis-cli -h 192.168.1.136  -p 26379 info Sentinel


參考文獻鏈接:http://blog.csdn.net/sdlyjzh/article/details/50274499



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章