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



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