Centos7 部署 redis-sentinel
三个节点
11.0.8.15 master sentinel
11.0.8.16 slave sentinel
11.0.8.17 slave sentinel
1、安装redis
yum install -y redis
2、修改redis配置文件
$ vim /etc/redis.conf
protected-mode no
daemonize yes
appendonly yes
slaveof 11.0.8.15 6379
3、启动redis
systemctl enable redis --now
4、查看复制信息
$ redis-cli -h 11.0.8.15
11.0.8.15:6379> set name keith
OK
11.0.8.15:6379> get name
"keith"
11.0.8.15:6379> keys *
1) "name"
11.0.8.15:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=11.0.8.16,port=6379,state=online,offset=128,lag=1
slave1:ip=11.0.8.17,port=6379,state=online,offset=142,lag=1
master_repl_offset:142
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:141
5、修改sentinel配置文件
$ vim /etc/redis-sentinel.conf
sentinel monitor mymaster 11.0.8.15 6379 2
6、启动sentinel
systemctl enable redis-sentinel --now
7、查看状态信息
> sentinel masters
> sentinel master mymaster
> sentinel replicas mymaster
> sentinel sentinels mymaster
8、测试故障转移
> sentinel failover mymaster
> sentinel get-master-addr-by-name mymaster
参考文档