Redis exception; nested exception is io.lettuce.core.RedisException java.io.IOException 远程主机

编辑/etc/ssh/sshd_config,添加配置项:

ClientAliveInterval 600      
ClientAliveCountMax 10

配置完后保存,重启服务:

service sshd restart

ClientAliveCountMax
sshd(8) 在未收到任何客户端回应前最多容许发送多少个"alive"消息。默认值是 3 。
到达这个上限后,sshd(8) 将强制断开链接、关闭会话。
须要注意的是,"alive"消息与 TCPKeepAlive 有很大差别。
"alive"消息是经过加密链接发送的,所以不会被欺骗;而 TCPKeepAlive 倒是能够被欺骗的。
若是 ClientAliveInterval 被设为 15 而且将 ClientAliveCountMax 保持为默认值,
那么无应答的客户端大约会在45秒后被强制断开。这个指令仅能够用于SSH-2协议。

ClientAliveInterval
设置一个以秒记的时长,若是超过这么长时间没有收到客户端的任何数据,
sshd(8) 将经过安全通道向客户端发送一个"alive"消息,并等候应答。
默认值 0 表示不发送"alive"消息。这个选项仅对SSH-2有效。

以下是整个经过:

本地开发是发现隔一段时间没请求redis就会报错:

2022/11/15 21:31:35 ERROR [com.SpringLearn.common.redis.JedisUtils] - Redis exception; nested exception is io.lettuce.core.RedisException: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.get(LettuceStringCommands.java:68)
at org.springframework.data.redis.connection.DefaultedRedisConnection.get(DefaultedRedisConnection.java:253)
at org.springframework.data.redis.core.DefaultValueOperations$1.inRedis(DefaultValueOperations.java:57)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
at com.SpringLearn.common.redis.JedisUtils.get(JedisUtils.java:114)
at com.SpringLearn.common.framework.securi

网上看了很多解决办法,都是timeout和tcp-keepalive的配置,多次试验后都无效,最奇怪的是putty链接服务器也是过一会就断开了,mysql出现了这种情况,于是猜测不是redis的配置问题,开启本地虚拟机测试发现没有出现断开链接的问题,查了putty自动断开链接的解决方案(文章开头),修改完后上面的问题竟然解决了,本地服务的输出日志出现了下面的日志:

2020/07/09 20:20:02 INFO  [io.lettuce.core.protocol.ConnectionWatchdog] - Reconnecting, last destination was /139.xxx.xx.xx:6666
2020/07/09 20:20:03 INFO  [io.lettuce.core.protocol.ReconnectionHandler] - Reconnected to 139.xxx.xx.xx:6666
2020/07/09 20:20:03 INFO  [io.lettuce.core.protocol.ConnectionWatchdog] - Reconnecting, last destination was /139.xxx.xxx.xx:6666
2020/07/09 20:20:03 INFO  [io.lettuce.core.protocol.ReconnectionHandler] - Reconnected to 139.xxx.xxx.xxx:6666
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值