0%

springboot集成redis之哨兵模式

pom

1
2
3
4
5
6
7
8
9
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>

application.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 哨兵模式不需要
#spring.redis.host=192.168.1.114
# 哨兵模式不需要
#spring.redis.database=0
# 哨兵模式不需要
#spring.redis.port=6379
spring.redis.password=123456
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=192.168.1.114:26379,192.168.1.114:26378,192.168.1.114:26377

# 最大空闲数
spring.redis.lettuce.pool.max-idle=8
# 最大连接数
spring.redis.lettuce.pool.max-active=50
# 最大的等待毫秒数
spring.redis.lettuce.pool.max-wait=10000
# 最小空闲数
spring.redis.lettuce.pool.min-idle=5

检测成功与失败,断开master,测试是否故障迁移

1
2
3
4
5
6
7
8
9
10
11
12
// 杀死master进程
kill -9 3015


2020-03-25 15:36:38.512 INFO 8795 --- [xecutorLoop-1-3] i.l.core.protocol.ConnectionWatchdog : Reconnecting, last destination was /192.168.1.114:6379
2020-03-25 15:36:38.638 WARN 8795 --- [ioEventLoop-4-4] i.l.core.protocol.ConnectionWatchdog : Cannot reconnect to [192.168.1.114:6379]: Connection refused: /192.168.1.114:6379
2020-03-25 15:36:47.709 INFO 8795 --- [xecutorLoop-1-3] i.l.core.protocol.ConnectionWatchdog : Reconnecting, last destination was 192.168.1.114:6379
2020-03-25 15:36:47.736 WARN 8795 --- [ioEventLoop-4-4] i.l.core.protocol.ConnectionWatchdog : Cannot reconnect to [192.168.1.114:6379]: Connection refused: /192.168.1.114:6379
2020-03-25 15:36:56.010 INFO 8795 --- [xecutorLoop-1-1] i.l.core.protocol.ConnectionWatchdog : Reconnecting, last destination was 192.168.1.114:6379
2020-03-25 15:36:56.037 WARN 8795 --- [ioEventLoop-4-2] i.l.core.protocol.ConnectionWatchdog : Cannot reconnect to [192.168.1.114:6379]: Connection refused: /192.168.1.114:6379
2020-03-25 15:37:12.510 INFO 8795 --- [xecutorLoop-1-3] i.l.core.protocol.ConnectionWatchdog : Reconnecting, last destination was 192.168.1.114:6379
2020-03-25 15:37:12.937 INFO 8795 --- [ioEventLoop-4-4] i.l.core.protocol.ReconnectionHandler : Reconnected to 192.168.1.114:6378

上面控制台出现的信息,已经重连了6378端口,说明sentinel部署成功

-------------本文结束感谢你的阅读---------