Elasticsearch 集群连接

6
如果我在集群中有三个节点,那么在创建传输客户端时是否需要提供每个节点的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和端口的方法?请帮忙。
2个回答

1
为什么不为这些节点配置一个完全限定域名(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连接到所有节点。


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

1
{btsdaf} - Wolverine
{btsdaf} - pkhlop
2
同意,Elasticsearch使用两个端口,一个用于TCP,一个用于HTTP,但我对我的问题仍然不清楚。如果我连接到节点1(localhost,9300),但是这个ES节点出现故障,而另外两个节点仍在端口上运行(localhost,9301)和(localhost,9302)。所有节点都在同一个集群中,那么我的传输客户端会自动连接到正在运行的节点之一(9301或9302)吗? - Wolverine
{btsdaf} - pkhlop
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端口=9300,http端口=9200),就像这样。 - Wolverine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接