Skip to content
欢迎扫码关注公众号

ElasticSearch NoNodeAvailableException[None of the configured nodes are available]

ElasticSearch 偶尔会报下面的错误

系统发生异常 (NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{192.168.xxx.xxx}{192.168.xxx.xxx:9300}]])


可能有以下几个原因:

  1. 端口错误

    java
    client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(ipAddress, 9300));

    端口 9300 写成 9200 的报错 No node available 或者查看连接的是不是本地计算机,如果是远程的话查看一下 IP 地址是否正确。

  2. jar 包报错误的话可能是引用包不匹配,开启的服务是什么版本最好对应相应的 jar 包。

  3. 修改了集群名称,设置了集群名字导致出现问题,设置操作如下:

    java
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "yoodb").build();  
    client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(ipAddress, 9300));
  4. 集群超过 5s 没有响应,解决方式如下:

    1. 设置 client.transport.ping_timeout 超时时间,增大一些

    2. 代码内嵌入,如下:

      java
      while (true) {
          try {
              bulk.execute().actionGet(getRetryTimeout());
              break;
          } catch (NoNodeAvailableException cont) {
              Thread.sleep(5000);
              continue;
          }
      }

因为只是偶尔报错,排除了上面 1、2、3 的可能,可能是网络原因或者服务器原因导致获取 node 超时了。

准备先将 client.transport.ping_timeout 设置成 60s 看看效果。

java
//设置集群的名字
Settings settings = Settings.settingsBuilder()
        .put("cluster.name", clusterName)
        .put("client.transport.sniff", false)
        .put("client.transport.ping_timeout", "60s")
        .build();
//创建集群 client 并添加集群节点地址
transportClient = TransportClient.builder()
        .settings(settings)
        .build();
//添加 IP
for (String ip : ips) {
    transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), 9300));
}

参照:

ElasticSearch 使用问题及解决方案汇总
生产环境使用 elasticsearch 遇到的一些问题以及解决方法(不断更新)


Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.