关于ES NoNodeAvailableException 原因一种及解决

发布时间:2019-06-15 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了关于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"

关于ES NoNodeAvailableException 原因一种及解决

而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外网也是通的

脚本宝典总结

以上是脚本宝典为你收集整理的关于ES NoNodeAvailableException 原因一种及解决全部内容,希望文章能够帮你解决关于ES NoNodeAvailableException 原因一种及解决所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。