无节点可用异常Elasticsearch 5.0.2

时间:2017-02-02 11:44:57

标签: java elasticsearch elasticsearch-java-api

首先,对不起我的英语。 我的Java API传输客户端有问题。我有一个主节点和三个数据节点。我的Elasticsearch版本是5.0.2,我使用的是5.0.2 API。

我尝试使用Transport Client连接到我的群集,然后我回复

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{8SAZOxXXTU61DuDDMN-vGw}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-2}{Fv3729YgTGClRBo5T2mWpA}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-3}{Fr98ApBbRv29Xv6Mc8L4TQ}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-4}{JOmpSH4LRzuP_XInxQtD9Q}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}]]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:328)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:226)
    at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:339)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
    at nn.Main.main(Main.java:57)

这是我的客户代码:

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;

public class Main {
    private static String[] hosts = new String[] {
            "XX.XX.X.XXX"
            ,"XX.XX.X.XXX"
            ,"XX.XX.X.XXX"
            ,"XX.XX.X.XXX"          
            };

    private static final Settings settings = Settings.builder()
            .put("cluster.name", "myCluster")
            .put("client.transport.sniff", true)
            .put("transport.tcp.port", 9300)
            .put("xpack.security.user", "transport_client_user:changeme")
            .build();
    private static final String index = "myIndex";
    private static final String type = "myType";
    private static TransportClient client;


    public static void main(String[] args) throws UnknownHostException {

        InetSocketTransportAddress[] ista = new InetSocketTransportAddress[hosts.length]; 

        for (int i = 0; i < hosts.length; i++) {
        ista[i] = new InetSocketTransportAddress(InetAddress.getByName(hosts[i]), 9300);
    }

        client = new PreBuiltXPackTransportClient(settings).addTransportAddresses(ista);        

        SearchRequestBuilder rb = client
                .prepareSearch(index)
                .setTypes(type)
                .setSearchType(SearchType.DEFAULT)
                .setQuery(QueryBuilders.termQuery("_id", 3524598));


        SearchResponse sResponse = rb.get();
        System.out.println(sResponse.toString());
    }
}

传输客户端端口 - 9300,我的所有节点都在此端口下进行通信。我看到很多像我的问题,我试图遵循他们所包含的建议。但我有同样的例外。

如果需要更多信息或我弹性的任何文件或设置 - 我已准备好回答。

如果重要的话,这是elasticsearch.yml的内容

cluster.name: myCluster
node.name: elastic-0

path.data: /var/db/elasticsearch
path.logs: /var/log/elasticsearch
path.scripts: /usr/local/libexec/elasticsearch

network.host: _vmx0_

node.master: true 
node.data: false 
node.ingest: false 

node.attr.rack_id: rack_one
cluster.routing.allocation.awareness.attributes: rack_id

discovery.zen.minimum_master_nodes: 3
discovery.zen.ping.unicast.hosts: ["XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX"]

bootstrap.memory_lock: false

xpack.monitoring.exporters:
  id1:
    type: http
    host: ["XX.XX.X.XXX:9200"] 
    auth.username: remote_monitor 
    auth.password: changeme

我尝试仅在TransportClient更改Client,并停用client.transport.sniff,但没有结果。

我将非常感谢任何帮助或想法。

2 个答案:

答案 0 :(得分:1)

我找到了收到&#34; NoNodeAvailableException&#34;的原因。

原因是transport_client的角色没有授予在默认情况下查看所有索引中的数据的权限。 我将建立我的角色来访问索引中的数据。

链接:https://www.elastic.co/guide/en/x-pack/5.0/built-in-roles.html

答案 1 :(得分:0)

当我们尝试将ES与TranscientClient(9300)而非API(9200)一起使用时,通常会发生此异常。

这些可能是背后原因:

  1. 我们的IP地址或提供的端口错误。默认情况下,传输通信通过9300进行,直到并且除非我们明确更改elastisearch.yml

  2. 无法从运行Java应用程序的计算机上访问IP地址和端口。根本无法从客户端计算机访问ES机器,因此我们需要打开客户端的端口和IP。

  3. 如果我们更改“ transport.host”,则ES会视为产品环境并进行引导检查。但是,在环境不是生产环境且我们在一台机器上运行ES并试图通过传输客户端(Java应用程序)从另一台机器上运行ES的情况下,我们只需添加'discovery.type:single-node'。 / p>

按如下所示更改Elastic Search yaml:

Array
(
    [0] => Array
        (
            [city] => Berlim
            [value] => 23
            [option] => 5
        )

    [1] => Array
        (
            [city] => Rio
            [value] => 18
            [option] => 3
        )

    [2] => Array
        (
            [city] => Tokyo
            [value] => 20
            [option] => 4
        )

)