redis主从哨兵
配置主从
相关配置文件,
daemonize yes
protected-mode no
port 7001
#bind 127.0.0.1
dir /usr/local/redis-cluster/7001/
appendonly yes
pidfile /var/run/redis_7001.pid
slave-read-only yes
启动redis
redis-server ./7001/redis_7001.conf
redis-server ./7002/redis_7002.conf
redis-server ./7003/redis_7003.conf
配置主从
[root@localhost redis-cluster]# redis-cli -h 127.0.0.1 -p 7002
127.0.0.1:7002> SLAVEOF 127.0.0.1 7001
OK
127.0.0.1:7002> exit
[root@localhost redis-cluster]# redis-cli -h 127.0.0.1 -p 7003
127.0.0.1:7003> SLAVEOF 127.0.0.1 7001
配置哨兵
[root@localhost redis-cluster]# cat sentinel.conf
protected-mode yes
bind 127.0.0.1
daemonize yes
port 26379
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 127.0.0.1 7001 1 #这个1是由多少个哨兵同意就切换主从 半数以上 如果是3个哨兵配置为2 我只有一个哨兵
logfile "./sentinel.log"
dir "/usr/local/redis-cluster"
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 1800
启动哨兵
redis-sentinel sentinel.conf
查看哨兵状态
127.0.0.1:26379> info Sentinel
Sentinel
127.0.0.1:26379> info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:7001,slaves=2,sentinels=1
现在我们停止7001这个节点redis 查看主从切换 可以发现现在的master节点变成了7002
127.0.0.1:26379> info Sentinel
Sentinel
127.0.0.1:26379> info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:7002,slaves=2,sentinels=1
redis主从哨兵
http://www.jcwit.com/article/136/