首页 > 解决方案 > 没有可用的节点 elasticsearch

问题描述

我在我的项目中使用弹性搜索。但是在服务器上部署项目时出现异常,我阅读了其他相同的问题但没有找到解决方案:我将端口更改为 9300,但没有解决。

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{EEv7PPi1SYqxodHCtCrfEw}{192.168.0.253}{192.168.0.253:9200}]]
        at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:344)
        at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:242)
        at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)

这是我在代码中对 elasticsearch 的配置:

 public static void postConstruct() {
            try {
                Settings settings = Settings.builder()
                        .put("cluster.name","my-application").build();
                client = new PreBuiltTransportClient(settings)
                        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(Bundle.application.getString("ELASTIC_ADDRESS")), Integer.parseInt(Bundle.application.getString("9200"))));
                try {
                    client.admin().indices().prepareCreate("tempdata").get();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }

我的项目和服务器上的elasticsearch bot版本是一样的。这就是我卷曲' http://xxxx:9200/?pretty '时得到的

{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "5.2.2",
    "build_hash" : "f9d9b74",
    "build_date" : "2017-02-24T17:26:45.835Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}

当我将端口更改为 9300 时,几秒钟后我看到的异常是:

MasterNotDiscoveredException[null]
        at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$4.onTimeout(TransportMasterNodeAction.java:211)
        at org.elasticsearch.cluster.ClusterStateObserver$ContextPreservingListener.onTimeout(ClusterStateObserver.java:307)
        at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:237)
        at org.elasticsearch.cluster.service.ClusterService$NotifyTimeout.run(ClusterService.java:1157)

这是elasticsearch的日志,我不知道host1和host2是什么:

   [2018-07-16T15:40:59,476][DEBUG][o.e.a.a.i.g.TransportGetIndexAction] [gCJIhnQ] no known master node, scheduling a retry
[2018-07-16T15:41:29,478][DEBUG][o.e.a.a.i.g.TransportGetIndexAction] [gCJIhnQ] timed out while retrying [indices:admin/get] after failure (timeout [30s])
[2018-07-16T15:41:29,481][WARN ][r.suppressed             ] path: /bad-request, params: {index=bad-request}
org.elasticsearch.discovery.MasterNotDiscoveredException: null
        at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$4.onTimeout(TransportMasterNodeAction.java:211) [elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cluster.ClusterStateObserver$ContextPreservingListener.onTimeout(ClusterStateObserver.java:307) [elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:237) [elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.cluster.service.ClusterService$NotifyTimeout.run(ClusterService.java:1157) [elasticsearch-5.2.2.jar:5.2.2]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:527) [elasticsearch-5.2.2.jar:5.2.2]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_91]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_91]

标签: javaelasticsearchsearch

解决方案


由于评论的数量有所增加,这里有一些提示可能会有所帮助。我假设您正在使用一个独立的 elasticsearch 实例,该实例使用 ES_HOME/bin/elasticsearch 作为服务器机器上的主节点启动。

  1. 确保服务器上的 elasticsearch 配置为主节点。有关 elasticsearch 中节点的更多详细信息,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/6.3/modules-node.html
  2. 确保服务器上的 elasticsearch 绑定到非环回地址。有关这方面的详细信息,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/network.host.html
  3. 检查传输客户端版本是否与服务器版本兼容。
  4. 如他们所说,增加 mmap计数。在 Linux 中通过运行命令:sysctl -w vm.max_map_count=262144
  5. 检查服务器上的传输端口号,它可以从外部访问。默认为 9300-9400
  6. 检查服务器上的 elasticsearch 服务日志,确保它已按照您的方式进行配置!

推荐阅读