1

我有一个在 google-compute-engine(VM) 中运行的 elasticsearch 集群,我正在尝试从我的 Java 程序进行连接。

谷歌云中的 ES instante 有一个外部 IP 和内部 IP。我已经配置了用于连接的外部 IP,并且所有防火墙设置都启用了连接。

仍然看起来,客户端在将 myd 数据写入 ES 时正在某个地方使用内部 IP。

10.240.0.237 是内部 IP

Caused by: java.net.ConnectException: Connection timed out: no further information: /10.240.0.237:9300
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
    at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:152)
    at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)
    at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)
    at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
    at org.elasticsearch.common.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)
    at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
    at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)

代码

public class ESClient {
        final static Node[] esNodes = new Node[1];
        static String indexName = "sa-sonarshock-log";
        public static Client getClient(){
            if(esNodes[0] == null){
                esNodes[0] = _setupNode();
            }
            return esNodes[0].client();
        }
        public static Node _setupNode(){
            Settings settings = ImmutableSettings.settingsBuilder()
                    .put("cluster.name", "es-tifc-retro-testing")
                    .put("http.enabled", false)
                    .put("transport.tcp.port", "9300-9400")
                    .put("discovery.zen.ping.multicast.enabled", false)
                    .put("discovery.zen.ping.unicast.hosts", "estifcretrotest-es-tifc-retro-testing-1-vm")
                    .build();    

            return nodeBuilder().settings(settings).client(true).node();
        }   
        public static Map<String, Object> putJsonDocument(String title, String content, Date postDate, 
                String[] tags, String author){
            Map<String, Object> jsonDocument = new HashMap<String, Object>();
            jsonDocument.put("title", title);
            jsonDocument.put("conten", content);
            jsonDocument.put("postDate", postDate);
            jsonDocument.put("tags", tags);
            jsonDocument.put("author", author);
            return jsonDocument;
        }   
        public static void main(String[] args) {
            Client esClient = getClient();
            CreateIndexRequestBuilder createIndexRequestBuilder = esClient.admin().indices().prepareCreate(indexName);
            createIndexRequestBuilder.execute().actionGet();
            esClient.prepareIndex(indexName, "default", "1")
            .setSource(putJsonDocument("ElasticSearch: Java API",
                                       "ElasticSearch provides the Java API, all operations "
                                       + "can be executed asynchronously using a client object.",
                                       new Date(),
                                       new String[]{"elasticsearch"},
                                       "Remis Haroon")).execute().actionGet();
            esNodes[0].close();
        }
}
4

1 回答 1

0

看起来您正在连接端口 9300,但我认为您想要端口 9200。

于 2016-10-14T20:43:22.087 回答