防火墙拦截导致Redis连接异常,JedisConnectionException: Could not get a resource from the pool

文章描述了一个由于防火墙拦截导致的OA服务应用访问Redis时出现JedisConnectionException的问题。解决方案是检查和配置防火墙规则,允许特定端口(如8080/tcp)通过,并确保设置在系统重启后仍然生效。通过使用iptables命令和firewall-cmd命令来管理防火墙规则,可以解决服务因防火墙限制而无法正常通信的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题结论&解决方案

防火墙拦截导致,找到服务的端口,然后在防火墙中配置给端口放行,同时设置重启后也生效

在root权限下执行:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

然后执行(即时生效,重启失效)service iptables stop
service iptables start

要想重启后也生效,则执行:

chkconfig iptabels on
chkconfig iptabels off

问题场景

给客户线上排查问题OA服务的应用获取登录框加载异常缓慢,客户有部署Redis,通过分析线程日志发现并结合业务日志锁定到如下报错内容,JedisConnectionException: Could not get a resource from the pool

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.JedisPool.getResource(JedisPool.java:226)
	
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.NoRouteToHostException: 没有到主机的路由 (Host unreachable)
	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 org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
	at redis.clients.util.Pool.getResource(Pool.java:49)

问题分析

根据日志直接判断应该是redis服务不可用,那么要么是服务本身有问题,比如没启动,要么就是服务不可达。然后借助网上的经验判断有了思路,可能是防火墙拦截的原因,客户最近有重启过服务,可能防火墙配置好了,重启又还原了导致

防火墙检测的相关命令


1、查看已经开放的端口

firewall-cmd --list-ports

2、放行端口

firewall-cmd --zone=public --add-port=8080/tcp --permanent

--zone 作用域

--permanent 永久生效

3、重启防火墙

systemctl reload firewalld

4、查询指定端口是否开启成功

firewall-cmd --query-port=5601/tcp

5、停止防火墙

systemctl stop firewalld

或:

systemctl stop firewalld.service

6、启动防火墙

systemctl start firewalld

或:

systemctl start firewalld.service

7、查看防火墙是否在运行

systemctl status firewalld
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值