我有一个在google-compute-engine(VM)中运行的elasticsearch集群,我正在尝试从我的Java程序连接。
google-cloud中的ES instante有一个外部ip&内部IP。 我已经配置了external-ip进行连接,并且所有防火墙设置都已启用连接。
看起来似乎还有,内部ip正在客户端使用,同时将myd数据写入ES。
10.240.0.237 是internal-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();
}
}
答案 0 :(得分:0)
看起来你在端口9300上连接,但我认为你想要端口9200。