记录生产环境SpringBoot Redis哨兵模式:JedisConnectionException: Could not get a resource from the pool

问题由来

应工作需要,进行修改一个老项目,修改完后进行投产,发现登陆时无法获取到Redis连接,无法进行登陆,然后项目进行了回滚。

错误提示:
2021-08-18 21:44:08.130 ERROR 24558 [http-nio-8089-exec-9] --- .a.c.l.AbstractPhoneClientRequestHandler : Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:204)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348)
	at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:92)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:194)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:157)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at redis.clients.util.Pool.getResource(Pool.java:53)
	at redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:209)
	at redis.clients.jedis.JedisSentinelPool.getResource(JedisSentinelPool.java:17)
	at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
	at redis.clients.jedis.Connection.connect(Connection.java:207)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
	at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
	at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
	at redis.clients.util.Pool.getResource(Pool.java:49)
	at redis.clients.jedis.Connection.connect(Connection.java:184)
问题排查

初步怀疑代码可能存在问题,然后进行了排查,发现使用Redis的地方全局只有登录的时候一块代码用到(这次修改触发了这一块的业务执行导致暴露出问题),经过多次测试,发现本地环境以及Test环境均正常。
本地debug 在JedisConnectionFactory中fetchJedisConnector方法进行问题追踪,首先获取链接池中的连接数据进行查看,发现如下数据:
在这里插入图片描述

我配置的哨兵节点为:192.168.16.14:26379,192.168.16.11:26379,192.168.16.13:26379,debug发现当前选举的Master为192.168.16.13:6379,然后进一步排查发现:
在这里插入图片描述
通过哨兵配置的地址进行Socket连接获取到的Master确实为192.168.16.13:6379,然后去翻生产日志,试图找到以下日志内容,找到生产Redis初始化哨兵的日志
在这里插入图片描述
日志文件如下:

2021-08-18 21:43:22.817  INFO 24558 [main] --- redis.clients.jedis.JedisSentinelPool    : Trying to find master from available Sentinels...
2021-08-18 21:43:22.850  INFO 24558 [main] --- redis.clients.jedis.JedisSentinelPool    : Redis master running at 10.*.*.26:6379, starting Sentinel listeners...
2021-08-18 21:43:22.866  INFO 24558 [main] --- redis.clients.jedis.JedisSentinelPool    : Created JedisPool to master at 10.*.*.26:6379

则去找运维验证10...26:6379相关Ip以及端口访问权限确实没有打开,完美破案!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值