2015-11-12 15 views
2

更新:希望更清晰的細節和代碼...不能在TransportClient創建InetSocketTransportAddress:NoNodeAvailableException [配置的節點沒有-are可供選擇:[]

我試圖讓我的第一個Java應用交談ElasticSearch,這是此節點上運行(時間戳和log-級移除):

$ bin/elasticsearch 
[bootstrap   ]Unable to lock JVM Memory: error=78,reason=Function not implemented 
[bootstrap   ]This can result in part of the JVM being swapped out. 
[node    ][clustername-node.01] version[2.0.0], pid[49252], build[de54438/2015-10-22T08:09:48Z] 
[node    ][clustername-node.01] initializing ... 
[plugins   ][clustername-node.01] loaded [license, marvel], sites [] 
[env    ][clustername-node.01] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [164.4gb], net total_space [232.5gb], spins? [unknown], types [hfs] 
[node    ][clustername-node.01] initialized 
[node    ][clustername-node.01] starting ... 
[transport   ][clustername-node.01] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300} 
[discovery   ][clustername-node.01] clustername/AM4lm0ZBS_6FofhC0UbNIA 
[cluster.service ][clustername-node.01] new_master {clustername-node.01}{AM4lm0ZBS_6FofhC0UbNIA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received) 
[http    ][clustername-node.01] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200} 
[node    ][clustername-node.01] started 
[license.plugin.core][clustername-node.01] license [3ff50767-f1a5-4bac-8e35-c7a131384fd9] - valid 
[license.plugin.core][clustername-node.01] 
[gateway   ][clustername-node.01] recovered [14] indices into cluster_state 

具有調試-ING,通過@val所建議的,這些額外的行也包括在上面的輸出:

[transport.netty][clustername.01] using profile[default], worker_count[8], port[9300-9400], bind_host[null], publish_host[null], compress[false], connect_timeout[30s], connections_per_node[2/3/6/1/1], receive_predictor[512kb->512kb] 
[transport.netty][clustername.01] binding server bootstrap to: 127.0.0.1 
[transport.netty][clustername.01] Bound profile [default] to address {127.0.0.1:9300} 

地址部分:

publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300} 
clustername/AM4lm0ZBS_6FofhC0UbNIA 
new_master {clustername-node.01}{AM4lm0ZBS_6FofhC0UbNIA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received) 
publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200} 

confirmed the IP and port運行:

$ bin/elasticsearch --version 
Version: 2.0.0, Build: de54438/2015-10-22T08:09:48Z, JVM: 1.8.0_45 
$ telnet 127.0.0.1 9300 
Trying 127.0.0.1... 
Connected to localhost. 
Escape character is '^]'. 

^CConnection closed by foreign host. 
$ telnet 127.0.0.1 9301 
Trying 127.0.0.1... 
telnet: connect to address 127.0.0.1: Connection refused 
telnet: Unable to connect to remote host 
$ 

9300是存在的,9301並非如預期。我是reasonably sure端口9300對於Java TransportClient是正確的。

但無論我如何努力創建InetSocketTransportAddress ...

import org.elasticsearch.action.get.GetResponse; 
import org.elasticsearch.client.Client; 
import org.elasticsearch.client.transport.NoNodeAvailableException; 
import org.elasticsearch.client.transport.TransportClient; 
import org.elasticsearch.common.settings.Settings; 
import org.elasticsearch.common.transport.InetSocketTransportAddress; 

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

public class TrivialClient { 

    public static void main(String[] args) throws UnknownHostException { 
     InetSocketTransportAddress transportAddress = new InetSocketTransportAddress(
      InetAddress.getLocalHost(), 9300); 
     createClientPrintResponse("getLocalHost", transportAddress); 

     transportAddress = new InetSocketTransportAddress(
        InetAddress.getByName("localhost"), 9300); 

     createClientPrintResponse("getByName(\"localhost\")", transportAddress); 

//Does not compile in ElasticSearch 2.0 
//  transportAddress = new InetSocketTransportAddress("localhost", 9300); 
//  createClientPrintResponse("getByName(\"localhost\")", transportAddress); 

     transportAddress = new InetSocketTransportAddress(
      InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), 9300); 
     createClientPrintResponse("getByAddress(new byte[] {127, 0, 0, 1})", transportAddress); 

     transportAddress = 
      new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)); 
     createClientPrintResponse("InetSocketAddress", transportAddress); 
    } 

    private static void createClientPrintResponse(String description, 
             InetSocketTransportAddress transportAddress) { 
     Settings settings = Settings.settingsBuilder() 
      .put("cluster.name", "clustername").build(); 
     Client client; 
     client = TransportClient.builder().settings(settings).build(). 
      addTransportAddress(transportAddress); 
     try { 
     GetResponse response = client.prepareGet("comicbook", "superhero", "1").get(); 
     System.out.println(description + ": " + response); 
     } catch (NoNodeAvailableException e) { 
     System.out.println(description + ": " + e); 
     //e.printStackTrace(); 
     } 
    } 
} 

...它失敗:

getLocalHost: NoNodeAvailableException[None of the configured nodes are available: []] 
getByName("localhost"): NoNodeAvailableException[None of the configured nodes are available: []] 
getByAddress(new byte[] {127, 0, 0, 1}): NoNodeAvailableException[None of the configured nodes are available: []] 
InetSocketAddress: NoNodeAvailableException[None of the configured nodes are available: []] 

堆棧跟蹤:

NoNodeAvailableException[None of the configured nodes are available: []] 
getLocalHost: NoNodeAvailableException[None of the configured nodes are available: []] 
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:280) 
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197) 
    at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55) 
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:272) 
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347) 
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85) 
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59) 
    at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:67) 
    at springes.esonly.TrivialClient.createClientPrintResponse(TrivialClient.java:47) 
    at springes.esonly.TrivialClient.main(TrivialClient.java:19) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 

什麼我錯過了嗎?

+0

可能這已經回答了,[查看答案】(http://stackoverflow.com/問題/ 33522581/elasticsearch-2-0-transport-client-no-node-available-exception/33568326)#33568326 –

+0

我不明白這個答案。我的設置:'network.host:127.0.0.1',這是我在啓動節點時在elasticsearch日誌中列出的IP,並且是我在Java代碼中使用的。我在elasticsearch.yml中沒有看到任何其他'主機'相關的配置設置。 – aliteralmind

+0

在你的'config/logging.yml'文件中,你可以在記錄器部分添加'transport:DEBUG',然後用你所看到的更新你的啓動日誌? – Val

回答

相關問題