有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Elasticsearch群集连接

这可能是个愚蠢的问题,但我找不到答案。 如果我的集群中有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和端口?? 请帮忙


共 (1) 个答案

  1. # 1 楼答案

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

    您还可以将群集设置为具有无数据的loadbalancer节点,并始终连接到此节点。更多详情here

    更新:

    假设您希望在同一台服务器上运行同一群集的3个节点: 点头。本地节点2。本地节点3。本地的

    配置文件如下所示

    点头。本地的

    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
    

    点头。本地的

    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
    

    点头。本地的

    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