# 绑定端口,开启后特定端口允许访问
bind 0.0.0
# 关闭保护模式
protected-mode no
# 端口号
port 26379
# 开启后台运行
daemonize yes
# pid文件路径:
pidfile /var/run/redis-sentinel.pid
# 日志文件
logfile /usr/local/redis/sentinel/redis-sentinel.log
# 工作目录
dir /usr/local/redis/sentinel
# 给master起名为mymaster,它的ip,端口号,哨兵的数量
#(2台发现不能ping通,故障转移,比如5个哨兵,2个发现,就更换主节点)
# master monitor <master-name> <ip> <redis-port> <quorum>
sentinel monitor mymaster 192.168.1.191 6379 2
# 配置连接master服务的密码
# sentinel-auth-pass <master-name> <password>
sentinel-auth-pass mymaster 123456
# 指定多少毫秒之后,主节点没有应答哨兵,此时哨兵主观上认为主节点下线 — 主节点下线
# sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds mymaster 30000
# 表示允许并行同步的slave个数,当master挂了后,哨兵会选出新的master,剩余的slave会向新的master发起同步数据
# (配置为1指,slave 1个接1个去同步master的数据,并行的数量)
# sentinel parallel-syncs <master-name> <nums>
sentinel parallel-syncs mymaster 1
# 故障转移的超时时间,进行故障转移时,如果超过设置的毫秒,表示故障转移失败,相当于选举成功,但是数据转移失败了
# sentinel failover-timeout <master-name> <milliseconds>
sentinel failover-timeout mymaster 180000
# 配置当某一事件发生时所需要执行的脚本
sentinel notification-script <master-name> <script-path>
# 客户端重新配置主节点参数脚本
sentinel client-reconfig-script <master-name> <script-path>
主要用到的配置
# base
protected-mode no
port 26379
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /usr/local/redis/sentinel/redis-sentinel.log
dir /usr/local/redis/sentinel
# core
sentinel monitor mymaster 192.168.1.191 6379 2
sentinel-auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
哨兵信息检查
# 查看mymaster 下的master节点信息
sentinel master mymaster
# 查看mymaster 下的slaves节点信息
sentinel slaves mymaster
# 查看mymaster 下的哨兵节点信息
sentinel sentinels mymaster
SpringBoot 集成Redis哨兵-配置
spring:
redis:
database: 1
password: 123456
sentinel:
master: mymaster
nodes: 192.168.1.191:26379,192.168.1.192:26379,192.168.1.193:26379