1、在application.properties配置
#配置集群的哨兵模式
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=127.0.0.1:26380,127.0.0.1:26382,127.0.0.1:26384
spring.redis.password=123
2、配置redis6380.conf文件(master)
port 6380
# masterauth <master-password>
masterauth 123
# requirepass foobared
requirepass 123
3、配置redis6382.conf文件(slave)
port 6382
# slaveof <masterip> <masterport>
slaveof 127.0.0.1 6380
# masterauth <master-password>
masterauth 123
# requirepass foobared
requirepass 123
4、配置redis6384.conf文件(slave)
port 6384
# slaveof <masterip> <masterport>
slaveof 127.0.0.1 6380
# masterauth <master-password>
masterauth 123
# requirepass foobared
requirepass 123
5、配置sentinel26380.conf文件(其他两个文件修改端口号就可以)
#当前Sentinel服务运行的端口
port 26380
# 哨兵监听的主服务器
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 3000
# 3s内mymaster无响应,则认为mymaster宕机了
sentinel failover-timeout mymaster 10000
#如果10秒后,mysater仍没启动过来,则启动failover
sentinel auth-pass mymaster 123
# 执行故障转移时, 最多有1个从服务器同时对新的主服务器进行同步
sentinel config-epoch mymaster 0
6、依次启动Redis
redis-server.exe redis6380.conf
redis-server.exe redis6382.conf
redis-server.exe redis6384.conf
redis-server.exe sentinel26380.conf --sentinel
redis-server.exe sentinel26382.conf --sentinel
redis-server.exe sentinel26384.conf --sentinel
7、客户端查看master和哨兵状态
redis-cli.exe -h 127.0.0.1 -p 6380 -a 123
info replication
redis-cli.exe -h 127.0.0.1 -p 26380 -a 123
info sentinel
目录结构如下:
网友评论