Redis Sentinel 配置

机器:

172.16.32.25    ---- redis ,sentinel

172.16.32.163  ---- redis , sentinel

一:redis 安装

cd /usr/local

wget http://download.redis.io/releases/redis-4.0.10.tar.gz

tar -xzvf redis-4.0.10.tar.gz

cd redis-4.0.10

修改redis-conf文件

protected-mode yes

bind 172.16.32.25

cd src

redis-server ../redis.conf &


redis 从在机器上操作redis命令

redis-cli -h 172.16.32.163

SLAVEOF 172.16.32.25 6379 

二:sentinel 配置

cd /usr/local/redis-4.0.10/

修改 sentinel.conf

(1)172.16.32.25 机器上

bind 172.16.32.25

sentinel monitor mymaster 172.16.32.25 6379 2

(2)172.16.32.163机器上

bind 172.16.32.163

sentinel monitor mymaster 172.16.32.25 6379 2

三:sentinel 启动

cd /usr/local/redis-4.0.10/src

redis-sentinel ../sentinel.conf

配置文件内容有变更:

(1)172.16.32.25 

sentinel known-slave mymaster 172.16.32.25 6379
sentinel known-sentinel mymaster 172.16.32.163 26379 c9260fb053be7ba987de18e2b2656910e975e0c3
sentinel current-epoch 1

(2)172.16.32.163

sentinel known-slave mymaster 172.16.32.25 6379
sentinel known-sentinel mymaster 172.16.32.25 26379 3e1d9ca9d2aa4a7ac4ca39658aa8d8675422e291
sentinel current-epoch 1

四:模拟故障转移

172.16.32.25 机器 

cd /usr/local/redis-4.0.10/src

redis-cli -h 172.16.32.25 -p 26379 

172.16.32.25:26379> info
# 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=172.16.32.163:6379,slaves=1,sentinels=2
172.16.32.25:26379> sentinel failover mymaster
OK
172.16.32.25:26379> info
# 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=172.16.32.25:6379,slaves=1,sentinels=2





你可能感兴趣的:(redis)