簡體   English   中英

NoNodeAvailableException [沒有已配置的節點可用]在Elasticsearch 5.1.2中

[英]NoNodeAvailableException[None of the configured nodes are available] in Elasticsearch 5.1.2

在Google Compute Engine上,我創建了3個VM,並在其上安裝了Elasticsearch 5.1.2 我安裝了用於單播發現的GCE Discovery Plugin

從本地Web瀏覽器(Win7),我可以成功訪問這些Elasticsearch節點。 在Google Cloud Platform上,我添加了接受tcp:9300,tcp:9200的防火牆規則。

現在,我想使用Java傳輸客戶端與本地Java應用程序中的遠程Elasticsearch節點通信。 我確定cluster.name是正確的。

代碼和錯誤如下:

public class NativeClient {

    @SuppressWarnings({ "resource", "unchecked" })
    public static Client createTransportClient() throws UnknownHostException {

        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true)
                .build();

        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("104.100.100.96"), 9300));

        return client;
    }

    private final Node node = null;
    private final Client client = null;
}


public class IndicesOperations {
    private final Client client;

    public IndicesOperations(Client client) {
        this.client = client;
    }

    public boolean checkIndexExists(String name){
        IndicesExistsResponse response=client.admin().indices().prepareExists(name).execute().actionGet();
        return response.isExists();
    }

    public static void main( String[] args ) throws InterruptedException, UnknownHostException {
        Client client =NativeClient.createTransportClient();
        IndicesOperations io=new IndicesOperations(client);
        String myIndex = "test";
        if(io.checkIndexExists(myIndex))
            io.deleteIndex(myIndex);
        io.createIndex(myIndex);
        Thread.sleep(1000);
        io.closeIndex(myIndex);
        io.openIndex(myIndex);
        io.deleteIndex(myIndex);
    }
}


Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{lu8DzekbSWOrNEgFgXxpgQ}{104.100.100.96}{104.100.100.96: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:345)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
    at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1226)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
    at com.packtpub.IndicesOperations.checkIndexExists(IndicesOperations.java:16)
    at com.packtpub.IndicesOperations.main(IndicesOperations.java:49)

elasticsearch.yml

network.host: _gce_

cloud:
  gce:
      project_id: es-cloud
      zone: asia-east1-b
discovery:
      type: gce

編輯

在Google計算引擎上部署我的Java應用程序后,它可以訪問在Google計算引擎上運行的elasticsearch實例。 在此應用程序中,我剛剛修改了InetAddress.getByName("10.140.0.2") 在本地計算機上進行部署時,我使用了該VM的external ip

要在本地計算機上運行它,我還需要修改什么?

我將虛擬機的external ip附加到network.publish_host屬性,然后可以訪問在遠程虛擬機上運行的elasticsearch:

network.host: _gce_
network.publish_host: 104.100.100.96

cloud:
  gce:
      project_id: es-cloud
      zone: asia-east1-b
discovery:
      type: gce

我不太清楚,但是幸運的是它能正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM