Elasticsearch 5 Java Client 给出 “NoNodeAvailableException”

2022-09-04 22:17:39

我正在使用Elasticsearch 5.2Spring Boot 1.5.1。我正在通过Spring应用程序中的Java客户端连接到它。当我在端口上连接到它或我得到.在我的Java客户端中,我已将属性设置为.通过端口 9200 上的 cURL 向其发送请求时,它工作正常。我在单个群集中有 4 个节点,我无法连接到其中任何一个节点。我的配置文件具有除法中的所有默认值,但其中的默认值除外。93009200NoNodeAvailableException: None of the configured nodes are availableclient.transport.snifftruenetworknetwork.hosteth0inet addr

我正在使用Gradle。我的依赖关系是:

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.elasticsearch:elasticsearch:5.2.0')
compile('org.elasticsearch.client:transport:5.2.0')
compile('org.apache.logging.log4j:log4j-api:2.7')
compile('org.apache.logging.log4j:log4j-core:2.7')

我用于连接到 Elasticsearch 集群的代码:

@Bean
public TransportClient elasticClient() {
    org.elasticsearch.common.settings.Settings settings = Settings.builder()
        .put("client.transport.sniff", true)
        .put("cluster.name", "TestCluster")
            .build();
    TransportClient client = null;
    try {
        client = new org.elasticsearch.transport.client.PreBuiltTransportClient(settings)
            .addTransportAddress(new org.elasticsearch.common.transport.InetSocketTransportAddress(
                InetAddress.getByName("54.175.155.56"), 9200));
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return client;
}

ES 启动时我的 ES 日志是:

[2017-02-15T10:37:40,664][INFO ][o.e.t.TransportService   ] [ip-10-0-29-2] publish_address {10.0.29.2:9300}, bound_addresses {10.0.29.2:9300}
[2017-02-15T10:37:40,669][INFO ][o.e.b.BootstrapChecks    ] [ip-10-0-29-2] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-02-15T10:37:43,856][INFO ][o.e.c.s.ClusterService   ] [ip-10-0-29-2] detected_master {kafka-stage}{sTIeF8gGTNam0oNW8dkbbA}{TTX6FIRtRp-gDemYY-22Sg}{10.0.20.71}{10.0.20.71:9300}, added {{kafka-stage-2}{jl3oLGgMQ1yxhdMMy65k_g}{ibV8BApjRByUOpDDncddyQ}{10.0.51.31}{10.0.51.31:9300},{ip-10-0-40-144}{t-_THs3wQbC_k9eivDo5eQ}{v-UYoYgXQ265QkdYhtiPYA}{10.0.40.144}{10.0.40.144:9300},{kafka-stage}{sTIeF8gGTNam0oNW8dkbbA}{TTX6FIRtRp-gDemYY-22Sg}{10.0.20.71}{10.0.20.71:9300},}, reason: zen-disco-receive(from master [master {kafka-stage}{sTIeF8gGTNam0oNW8dkbbA}{TTX6FIRtRp-gDemYY-22Sg}{10.0.20.71}{10.0.20.71:9300} committed version [98]])
[2017-02-15T10:37:44,009][INFO ][o.e.h.HttpServer         ] [ip-10-0-29-2] publish_address {10.0.29.2:9200}, bound_addresses {10.0.29.2:9200}
[2017-02-15T10:37:44,009][INFO ][o.e.n.Node               ] [ip-10-0-29-2] started

这些问题的答案并不能解决我的问题:

  1. Java ElasticSearch 没有一个配置的节点可用
  2. Elasticsearch - NoNodeAvailableException
  3. Elasticsearch NoNodeAvailableException issue

答案 1

在配置文件中,您需要确保绑定到正确的主机,并具有以下设置:elasticsearch.yml

network.host: 54.175.155.56

同样在Java代码中,由于您使用的是传输客户端,因此您需要使用端口9300(用于TCP通信),而不是9200,后者用于HTTP通信(例如通过curl)

    client = new org.elasticsearch.transport.client.PreBuiltTransportClient(settings)
        .addTransportAddress(new org.elasticsearch.common.transport.InetSocketTransportAddress(
            InetAddress.getByName("54.175.155.56"), 9300));
                                                     ^
                                                     |
                                                change this

答案 2

我连接到的节点只是一个主节点。它有和作为.在连接到具有 as 的节点并删除 Java 客户端中的设置时,我能够连接到 ES 集群。node.ingestnode.datafalsenode.ingesttrueclient.transport.sniff


推荐