2017-10-20 199 views
1

这可能是一个愚蠢的问题,但我无法找到答案。 如果我的集群中有3个节点,那么在创建传输客户端时需要提供每个节点的IP和端口,以便我可以与每个节点通信?Elasticsearch集群连接

new PreBuiltTransportClient(settings, AuthenticationPlugin.class).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 
         Integer.parseInt("9300"))) 
         .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 
         Integer.parseInt("9301"))) 
InetSocketTransportAddress(InetAddress.getByName("localhost"), 
         Integer.parseInt("9302")));; 

有什么办法,我不需要提供每个节点的IP和端口? 请帮忙

回答

0

如果所有三个节点都在一个集群中,您只能与其中的一个进行通信。他们将在现场进行所有必要的沟通。

您还可以设置群集以使负载均衡器节点没有数据并始终连接到此节点。更多详情here

更新:

让说你要在同一台服务器上运行同一个集群的三个节点: node1.local node2.local node3.local

配置文件看起来像这样

node1.local

cluster.name: BillyMiligan 
node.name: "node1.local" 
network.host: "localhost" 
transport.tcp.port: 9301 
http.port: 9201 
discovery.zen.ping.unicast.hosts: ["node1.local:9301", "node2.local:9302", "node3.local:9303"] 
discovery.zen.minimum_master_nodes: 2 

node2.local

cluster.name: BillyMiligan 
node.name: "node2.local" 
network.host: "localhost" 
transport.tcp.port: 9302 
http.port: 9202 
discovery.zen.ping.unicast.hosts: ["node1.local:9301", "node2.local:9302", "node3.local:9303"] 
discovery.zen.minimum_master_nodes: 2 

node3.local

cluster.name: BillyMiligan 
node.name: "node3.local" 
network.host: "localhost" 
transport.tcp.port: 9303 
http.port: 9203 
discovery.zen.ping.unicast.hosts: ["node1.local:9301", "node2.local:9302", "node3.local:9303"] 
discovery.zen.minimum_master_nodes: 2 
+0

如果我连接到节点1(本地主机,9300),但一些如何ES节点出现故障,有2个节点端口仍然运行[(本地主机,9301)和(localhost,9302)。所有节点都在单个集群中,那么我的传输客户端将自动连接到正在运行的节点之一(9301或9302)? – Wolverine

+0

每个elasticsearch节点至少使用2个端口(transport.tcp.port:9300 默认为http.port:9200) 如果您在同一台服务器上启动多个节点,请确保您覆盖这两个端口 – pkhlop

+0

约定elasticsearch对每个端口使用2个端口1为tcp和1为http,但我仍然不清楚我的问题 \t **如果我连接到节点1(本地主机,9300),但一些ES节点如何关闭,并有2个节点仍在运行端口[(localhost,9301)和(localhost,9302)。所有节点都在单个集群中,那么我的传输客户端将自动连接到正在运行的节点之一(9301或9302)?? ** – Wolverine