关于ES NoNodeAvailableException 原因一种及解决

问题

服务器上部署了一个应用 需要连接ES 配置的是内网地址

<elasticsearch:transport-client id="client" cluster-nodes="10.28.70.38:9300" cluster-name="foo"/>

telnet 10.28.70.38 9300 OK 但是实际调用接口的时候 还是报了下面的错

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{10.28.70.38}{10.28.70.38:9300}]]
        at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)

感觉有点奇怪? 内网地址是通的啊 怎么还报了这样的错呢?

执行 lsof -p pid 发现存在下面这样的连接 变成了连ES的外网地址(106.14.XXX.XXX)了呢?但该服务器连ES外网地址不通

java    15847 root   74u  IPv4         1131084443      0t0        TCP 139.196.XXX.XXX:36706->106.14.XXX.XXX:vrace (SYN_SENT)

最后定位到的原因是 elasticsearchTemplate的配置项中有"client.transport.sniff" -> "true"
图片描述

而client.transport.sniff的含义是

The Transport client comes with a cluster sniffing feature which allows it to dynamically add new hosts and remove old ones. When sniffing is enabled, the transport client will connect to the nodes in its internal node list, which is built via calls to addTransportAddress. After this, the client will call the internal cluster state API on those nodes to discover available data nodes. The internal node list of the client will be replaced with those data nodes only. This list is refreshed every five seconds by default. Note that the IP addresses the sniffer connects to are the ones declared as the publish address in those node’s Elasticsearch config.
参考文档: https://www.elastic.co/guide/...

解决
显式将client-transport-sniff置为false

<elasticsearch:transport-client id="client" cluster-nodes="10.28.70.38:9300" cluster-name="foo" client-transport-sniff="false"/>

此时执行lsof -p pid

java    32650 root  271u  IPv4         1131368694      0t0        TCP iZ11jteew8eZ:57671->10.28.70.38:vrace (ESTABLISHED)

或者也可以修改网络配置 使得访问ES外网也是通的

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值