准备
假设ip是192.168.1.30-35
修改30-32配置(如/etc/redis/redis.conf,改为你设置的路径)
3个都修改
bind 0.0.0.0
在31-32中执行
redis-cli slaveof 192.168.1.30 6379 info(验证主从是否设置成功)
## 修改33-35配置(使用源码提供的sentinel配置)
bind 0.0.0.0 sentinel monitor mymaster 192.168.1.30 6379 2
## 启动sentinel
redis-sentinel /path/to/sentinel.conf
## 在30中执行
sudo kill -s SIGTERM $(pgrep redis)
## 等sentinel中出现
827:X 18 Feb 08:20:28.205 # +switch-master mymaster 192.168.1.31 6379 192.168.1.32 6379
## 进入31执行
redis-cli info (查看主从情况,验证是否切换为31,因为31priority 更低,也就是优先级更高)