尝试使用TransportClient连接到ES时出现NoNodeAvailableException

时间:2017-01-26 16:59:00

标签: java elasticsearch

亲爱的StackOverflow同胞们!

尝试使用TransportClient连接到受Search Guard保护的远程ElasticSearch集群我一直遇到NoNodeAvailableException

Caused by: org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{e7l0vv0zRhaeESmQBBmR1w}{remote.cluster.de}{127.0.0.1:9300}]

在阅读了很多有关此问题的帖子后,我尝试过:

  • client.transport.sniff设为truefalse
  • cluster.name设置为远程名称,任意名称,而不是
  • http.enabled设为truefalse

不幸的是我不知道剩下要检查的内容。有人可以帮我找到问题吗?

这是我的Spring配置类:

@Configuration
@PropertySource("classpath:elastic.properties")
public class ElasticConfiguration {

    @Value("${searchguard.ssl.transport.keystore_password}")
    private String keystorePassword;

    @Value("${searchguard.ssl.transport.truststore_password}")
    private String truststorePassword;

    @Bean
    public Client elasticClient() throws UnknownHostException {
        Settings settings = Settings.builder()
                .put("cluster.name", "the remote cluster name")
                .put("path.home", ".")
                .put("client.transport.sniff", false)
                .put("http.enabled", false)
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_FILEPATH, "keystore.jks")
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_FILEPATH, "truststore.jks")
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_PASSWORD, keystorePassword)
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_PASSWORD, truststorePassword)
                .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_ENFORCE_HOSTNAME_VERIFICATION, false)
                .build();

        TransportClient tc = new PreBuiltTransportClient(settings, Arrays.asList(SearchGuardSSLPlugin.class));
        tc.addTransportAddress(
                new InetSocketTransportAddress(
                        InetAddress.getByName("remote.cluster.de"), 9300));

        return tc;
    }
}

这是我在Spring CommandLineRunner中调用的保存方法:

@Override
public void save(Employee employee) throws IOException {
    XContentBuilder builder = XContentFactory.jsonBuilder()
            .startObject()
                .field("id", employee.getId())
                .field("name", employee.getName())
                .field("age", employee.getAge())
            .endObject();

    // this.client is above configured TransportClient auto-injected by Spring
    IndexResponse response = this.client.prepareIndex("demo-company", "employee")
            .setSource(builder)
            .get();

}

以下是显示已安装版本的yum info elasticsearch的输出:

Installed Packages
Name        : elasticsearch
Arch        : noarch
Version     : 5.1.1
Release     : 1
Size        : 35 M
Repo        : installed
From repo   : elasticsearch-5.x
Summary     : Elasticsearch is a distributed RESTful search engine built for the cloud. Reference documentation can be found at
        : https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html and the 'Elasticsearch: The Definitive Guide'
        : book can be found at https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
URL         : https://www.elastic.co/
License     : 2009
Description : Elasticsearch subproject :distribution:rpm

这是我的pom.xml的摘录,显示我包含了正确的库版本:

    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>5.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.floragunn</groupId>
        <artifactId>search-guard-ssl</artifactId>
        <version>5.1.1-19</version>
    </dependency>

elasticsearch.yml中,绑定设置为:

network.host: 0.0.0.0

searchguard.ssl.transport.enforce_hostname_verification: false
# omitting ssl.transport trust- and keystore file and pass

searchguard.ssl.http.enabled: true
# omitting ssl.http trust- and keystore file and pass

# omitting searchguard.authcz.admin_dn

这是显示连接的telnet输出:

[oschlueter@B5400 ~]$ telnet 127.0.0.1 9300
Trying ::1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> 

0 个答案:

没有答案