Redis 哨兵模式搭建

2022/2/19 19:11:42

本文主要是介绍Redis 哨兵模式搭建,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Redis 哨兵模式搭建

1. 配置

vim sentinel.conf
# 关闭指定 ip 访问
protected-mode no
# 守护进程运行
daemonize yes
# 配置日志文件
logfile /usr/local/redis/sentinel/sentinel.log
# 配置工作目录
dir /usr/local/redis/sentinel
# 配置监听 master ip 为127.0.0.1 端口 6379 2个哨兵发现master 挂了开始切换
sentinel monitor mymaster 127.0.0.1 6379 2 
# 配置密码
sentinel auth-pass mymaster xxxx
# 判定 master 无响应的毫秒数
sentinel down-after-milliseconds mymaster 30000
# 并行同步的数量
sentinel parallel-syncs mymaster 1
# 主备切换超时时间
sentinel failover-timeout master-node 180000
# 启动
redis-sentinel sentinel.conf
# 查看哨兵信息
root@node-master init.d]# redis-cli -p 26379
127.0.0.1:26379> sentinel master master-node
 1) "name"
 2) "master-node"
 3) "ip"
 4) "192.168.31.201"
 5) "port"
 6) "6379"
 7) "runid"
 8) "193e5beda4ae7d9fdc32f5c840093a8b4bb8dc85"
 9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "460"
19) "last-ping-reply"
20) "460"
21) "down-after-milliseconds"
22) "10000"
23) "info-refresh"
24) "867"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "1195355"
29) "config-epoch"
30) "0"
31) "num-slaves"
32) "2"
33) "num-other-sentinels"
34) "2"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "180000"
39) "parallel-syncs"
40) "1"
127.0.0.1:26379>

2. 集成 SpringBoot

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
spring:
  redis:
    sentinel:
      master: master-node # master名
      nodes: master-node:26379,node-1:26379,node-2:26379 # 哨兵 ip:port,多个用逗号分隔
    password: root


这篇关于Redis 哨兵模式搭建的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程