2017-02-04 1 views
0

Google Compute Engineでは、3台のVMを作成してElasticsearch 5.1.2をインストールしました。 ユニキャスト検出用にGCE Discovery Pluginをインストールしました。NoNodeAvailableException Elasticsearch 5.1.2

私のローカル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 Compute Engineで実行されているelasticsearchインスタンス。このアプリケーションでは、InetAddress.getByName("10.140.0.2")を変更しました。ローカルマシンにデプロイするときは、そのVMのexternal ipを使用しました。

私のローカルマシン上で実行するには、他に何を変更する必要がありますか?

答えて

1

私はその後、私はリモートVM上で実行されているelasticsearchにアクセスすることができ、elasticsearch.ymlでnetwork.publish_hostプロパティに私のVMのexternal ipを追加:

network.host: _gce_ 
network.publish_host: 104.100.100.96 

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

私は正確に理解していないが、幸いそれは動作します。

関連する問題