安装环境准备
- centos7
- redis-4.0.6
- 三台虚拟机
host | port | 节点属性 |
---|---|---|
192.168.42.100 | 6379 | master |
192.168.42.101 | 6379 | slave |
192.168.42.102 | 6379 | slave |
- 默认已经安装了了主从, 如果要看主从去楼主的另外一篇文章 https://blog.csdn.net/qq_22986265/article/details/107687876
端口开启
开启26379端口
firewall-cmd --zone=public --add-port=26379/tcp --permanent
firewall-cmd --reload
配置文件
- sentinel.conf文件配置
protected-mode no # 关闭保护模式
port 26379
sentinel monitor mymaster 192.168.42.100 6379 2
sentinel down-after-milliseconds mymaster 20000
sentinel failover-timeout mymaster 15000
sentinel auth-pass mymaster 123456
启动哨兵
建议copy一份配置文件出来执行
./redis-sentinel sentinel-copy.conf
测试
- 杀死主节点的redis
-
在101主机上登录redis客户端, 输入 info replication
当前节点已经为master了 -
重新启动100节点上的redis
当前节点的主节点为101上的redis