redis 哨兵模式
redis sentinel 模式配置(windows)
1.启动主服务6379: redis-server .exe --port 6379 (这里为了简单没有读取配置文件,且只安装了一个redis服务)
2.启动哨兵模式: redis-server.exe ./sentienl26379.conf --sentinel
sentienl26379.conf 文件配置如下
port 26379 #监控主服务6379,哨兵投票结果查>=1的时候进行故障转移 sentinel monitor s1 127.0.0.1 6379 1
3. 启动从服务6380 ,6381:
redis-server.exe --port 6380 --slaveof 127.0.0.1 6379
redis-server.exe --port 6381 --slaveof 127.0.0.1 6379
查看 哨兵模式日志,6379服务下面有两个从服务6380,6381
现在停止6379服务,哨兵会从6380,6381下面选举一个成为主服务。查看哨兵日志
看出来6380成为了主服务,6381为从服务,6379尝试成为从服务,但是失败了。
重启启动6379服务,哨兵会检测到6379服务,并将它变为6380的从服务
客户端连接6379,尝试set
至此,单个sentinel模式配置完成。