Elasticsearch集群连接

问题描述 投票:0回答:2

这可能是一个愚蠢的问题,但我找不到答案。 如果我的集群中有 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")));;

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

java elasticsearch client elasticsearch-java-api
2个回答
0
投票

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

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

更新:

假设您想在同一台服务器上运行同一集群的 3 个节点: 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
投票

为什么不为这些节点配置 FQDN,例如:

upstream elasticsearch_cluster {
    server 192.168.0.1:9200;
    server 192.168.0.2:9200;
    server 192.168.0.3:9200;
    server 192.168.0.4:9200;
    server 192.168.0.5:9200;
    server 192.168.0.6:9200;
}

server {
    listen 80;
    server_name elasticsearch.example.com;

    location / {
        proxy_pass http://elasticsearch_cluster;
    }
}

然后使用

elasticsearch.example.com
连接到所有节点。

© www.soinside.com 2019 - 2024. All rights reserved.