Elasticsearch集群连接

Wol*_*ine 6 java client elasticsearch elasticsearch-java-api

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

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")));;
Run Code Online (Sandbox Code Playgroud)

有什么方法可以让我不需要提供每个节点的IP和端口吗?请帮忙

pkh*_*lop 0

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

您还可以将集群设置为具有没有数据的负载均衡器节点,并始终连接到该节点。更多详细信息请点击这里

更新:

假设您想在同一台服务器上运行同一集群的 3 个节点:node1.local node2.local node3.local

配置文件将如下所示

节点1.本地

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
Run Code Online (Sandbox Code Playgroud)

节点2.本地

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
Run Code Online (Sandbox Code Playgroud)

节点3本地

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
Run Code Online (Sandbox Code Playgroud)

  • 同意elasticsearch使用2个端口,每个端口1个用于tcp,1个用于http,但我仍然不清楚我的问题**如果我连接到node-1(localhost,9300),但这个ES节点如何关闭并且有2节点仍在端口 [(localhost, 9301) 和 (localhost, 9302) 上运行。所有节点都在单个集群中,那么我的传输客户端将自动连接到在(9301 或 9302)上运行的节点之一?** (2认同)
  • 我觉得有些混乱,我再解释一下。我在同一域中有三台物理服务器,考虑 10.0.0.1、10.0.0.2 和 10.0.0.3。在每个服务器上,elasticsearch 都使用端口运行。在服务器 10.0.0.1 上(ES:- tcp 端口=9300,http 端口=9200) 在服务器 10.0.0.2 上(ES:- tcp 端口=9300,http 端口=9200) 在服务器 10.0.0.3 上(ES:- tcp 端口= 9300,http端口=9200)所有三个ES节点都在集群中。通过java客户端我使用这样的传输客户端连接到服务器10.0.0.1(ES:- tcp port=9300, http port=9200) (2认同)