Elasticsearch出现Connection reset by peer

Elasticsearch出现Connection reset by peer分析

1.异常:

2024-06-13 13:17:10.539 WARN http-nio-30411-exec-9com.longdaotech.config.ESConfig -onFailure node:host=http://192.168.239.253:9200

2024/6/13 13:17:10 2024-06-13 13:17:10.541 WARN http-nio-30411-exec-9com.longdaotech.config.ESConfig -onFailure node:host=http://192.168.239.249:9200

2024/6/13 13:17:10 2024-06-13 13:17:10.542 WARN http-nio-30411-exec-9com.longdaotech.config.ESConfig -onFailure node:host=http://192.168.239.67:9200

2024/6/13 13:17:10 2024-06-13 13:17:10.543 ERROR http-nio-30411-exec-9com.longdaotech.front.modules.service.impl.GoodsSearchServiceImpl -{"monitorCode":"ESnull500601","message":"商品索引查询失败","contextContent":""}

2024/6/13 13:17:10 java.io.IOException: Connection reset by peer

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:793)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:221)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:221)

2024/6/13 13:17:10 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:205)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1454)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394)

2024/6/13 13:17:10 at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:930)

2024/6/13 13:17:10 at com.longdaotech.front.modules.service.impl.GoodsSearchServiceImpl.goodsSerarch(GoodsSearchServiceImpl.java:361)

2024/6/13 13:17:10 at com.longdaotech.front.modules.controller.GoodsSearchController.searchGoods(GoodsSearchController.java:107)

2024/6/13 13:17:10 at sun.reflect.GeneratedMethodAccessor326.invoke(Unknown Source)

2024/6/13 13:17:10 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

2.分析

为什么服务端会关闭链接?

服务器会有TCP的Keepalive 经过一段时间如果没有操作就会自动断开连接功能,而ES默认就是取服务器的时长配置

linux查看超时时间默认为两小时

注:当ES服务端的keepAlive短于ES客户端的keepAlive,也会导致:服务端已经关闭了连接,客户端继续复用该连接,抛出异常。

3.解决

手动设置KeepAliveStrategy来配置keepAlive,保证客户端keepAlive小于服务端keepAlive,让客户端先于服务端关闭连接

查看服务器超时时间(单位秒)

cat /proc/sys/net/ipv4/tcp_keepalive_time

默认是7200s

解决办法有两个,一是设置keepalive小于服务器的超时时间,这样HttpClient会自己断开连接,下次再重连,由于SpringBoot没有提供设置改属性的地方,配置起来有点小麻烦,可以参考以下链接

ES ElasticSearch Connection reset by peer问题解决_阿里巴巴首席技术官的博客-CSDN博客

方案二是发送心跳,下面贴出代码

复制代码
@Scheduled(fixedRate = 60 * 1000 * 5)
public void heartbeatToES() {
    try {
        RequestOptions requestOptions = RequestOptions.DEFAULT.toBuilder().build();
        boolean result = restTemplate.getClient().ping(requestOptions);
        log.info("es状态: {}", result);
    } catch (Exception e) {

    }
}

方案二 设置ES服务端 tcp_keepalive_time时间大于等于客户端时间

https://blog.csdn.net/weixin_42195284/article/details/122399262

ES ElasticSearch Connection reset by peer问题解决_es connection reset by peer-CSDN博客

相关推荐
光电笑映44 分钟前
网络通信基础:从协议分层到 Socket 编程预备
linux·运维·服务器·网络
微小冷2 小时前
用Mermaid画时序图
运维·流程图·时序图·mermaid·生命线
其实防守也摸鱼2 小时前
Codex 下载与本地部署实战:从安装到运行全指南
android·大数据·运维·安全·自动化
wdfk_prog2 小时前
ROS教程07:从 ros::start() 顺着源码读懂 Master、XML-RPC 与 Topic 注册发现
运维·缓存·docker·容器·ros
吴声子夜歌2 小时前
Shell编程实例——与解析相关的任务(二)
linux·运维·shell
倔强的石头1063 小时前
【Linux指南】动静态库系列(八):ELF 加载与进程地址空间:程序还没运行,为什么已经有地址
linux·运维
两点王爷3 小时前
常用的 Docker 镜像拉取地址仓库及常用命令详解
运维·服务器·容器
wdfk_prog3 小时前
用 Git Submodule + Sparse Checkout 管理 RT-Thread:内核、BSP、第三方库与业务代码分层实践
运维·缓存·docker·容器·ros
神.秘.人4 小时前
【BIOS/UEFI 与 MBR/GPT 的区别详解】
运维·服务器
懂软件的胡子个哥4 小时前
微信二次开发如何接入 AI,真正可用的不是简单自动回复
运维·微信·wechatapi·个人微信号二次开发·微信群管理