Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: recv failed
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:151)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
at redis.clients.jedis.BinaryJedis.select(BinaryJedis.java:523)
at com.ll.Charter01.run(Charter01.java:21)
at com.ll.Charter01.main(Charter01.java:15)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:127)
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196)
... 8 more
总之就是没有连接上,连接抛出了异常。
1、反复检查连接的端口号以及ip地址的准确;
Jedis conn = new Jedis("192.168.234.6");
Jedis conn = new Jedis("others", 6379);
2、检查linux主机上的防火墙是否关闭;
CentOS6使用命令:查看防火墙状态 : service iptables status
关闭防火墙: service iptables stop
开启防火墙: service iptables start
永久关闭防火墙:service iptables off
CentOS7使用命令 :查看防火墙状态:firewall-cmd --state
关闭防火墙:systemctl stop firewalld.service
开机禁止启动防火墙:systemctl disable firewalld.service
开启防火墙:systemctl start firewalld.service
如果开启防火墙遇到:unit is masked 执行以下指令
systemctl unmasked firewalld.service
更多请参考linux社区网址:(https://www.linuxidc.com/Linux/2016-12/138979.htm)
3、最后就是因为redis配置文件没有修改好(我的问题就是这个):
需要修改的位置如下: