elasticsearch - 如何为每台机器上有两个节点的集群设置两台机器

标签 elasticsearch

我有两台专用于 ES (2.2.0) 的机器。两台机器具有相同的规范。每个都在 Windows Server 2012 R2 上运行并具有 128GB 内存。关于 ES,我计划在集群的每台机器上有两个节点。

我正在查看 elasticsearch.yml 以查看如何配置每个节点以形成集群。

同一网络上的两台机器具有以下服务器名称和 IP 地址:

SRC01, 172.21.0.21
SRC02, 172.21.0.22

我正在查看 elasticsearch.yml,但不确定如何设置。我想我需要为 elasticsearch.yml 中的 Network 和 Discovery 部分设置适当的值:

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# --------------------------------- Discovery ----------------------------------
#
# Elasticsearch nodes will find each other via unicast, by default.
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#

我在网上和 SO 上搜索,希望找到一个完整的配置示例供我开始使用,但没有找到。

更新

在 Val 的帮助下,这是测试后我在四个节点(每台机器 2 个)上拥有的最小 elasticsearch.yml:

#----------SRC01, node 1---------
cluster.name: elastic
node.name: elastic_src01_1
network.host: 172.21.0.21
discovery.zen.ping.unicast.hosts: ["172.21.0.21","172.21.0.22"]


#----------SRC01, node 2---------
cluster.name: elastic
node.name: elastic_src01_2
network.host: 172.21.0.21
discovery.zen.ping.unicast.hosts: ["172.21.0.21","172.21.0.22"]


#----------SRC02, node 1---------
cluster.name: elastic
node.name: elastic_src02_1
network.host: 172.21.0.22
discovery.zen.ping.unicast.hosts: ["172.21.0.21","172.21.0.22"]


#----------SRC02, node 2---------
cluster.name: elastic
node.name: elastic_src02_2
network.host: 172.21.0.22
discovery.zen.ping.unicast.hosts: ["172.21.0.21","172.21.0.22"]

这是我得到的问题:

  1. 我启动了 Node elastic_src01_1,然后是 Node elastic_src01_2,它们在同一台机器上。启动 elastic_src01_2 时,我能够看到 ES 生成的消息如下 (detected_master)

日志摘录:

[2016-02-28 12:38:33,155][INFO ][node                     ] [elastic_src01_2] version[2.2.0], pid[4620], build[8ff36d1/2016-01-27T13:32:39Z]
[2016-02-28 12:38:33,155][INFO ][node                     ] [elastic_src01_2] initializing ...
[2016-02-28 12:38:33,546][INFO ][plugins                  ] [elastic_src01_2] modules [lang-expression, lang-groovy], plugins [], sites []
[2016-02-28 12:38:33,562][INFO ][env                      ] [elastic_src01_2] using [1] data paths, mounts [[Data (E:)]], net usable_space [241.7gb],
net total_space [249.9gb], spins? [unknown], types [NTFS]
[2016-02-28 12:38:33,562][INFO ][env                      ] [elastic_src01_2] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-02-28 12:38:35,077][INFO ][node                     ] [elastic_src01_2] initialized
[2016-02-28 12:38:35,077][INFO ][node                     ] [elastic_src01_2] starting ...
[2016-02-28 12:38:35,218][INFO ][transport                ] [elastic_src01_2] publish_address {172.21.0.21:9302}, bound_addresses {172.21.0.21:9302}
[2016-02-28 12:38:35,218][INFO ][discovery                ] [elastic_src01_2] elastic/N8r-gD9WQSSvAYMOlJzmIg
[2016-02-28 12:38:39,796][INFO ][cluster.service          ] [elastic_src01_2] detected_master {elastic_src01_1}{UWGAo0BKTQm2f650nyDKYg}{172.21.0.21}{1
72.21.0.21:9300}, added {{elastic_src01_1}{UWGAo0BKTQm2f650nyDKYg}{172.21.0.21}{172.21.0.21:9300},{elastic_src01_1}{qNDQjkmsRjiIVjZ88JsX4g}{172.21.0.2
1}{172.21.0.21:9301},}, reason: zen-disco-receive(from master [{elastic_src01_1}{UWGAo0BKTQm2f650nyDKYg}{172.21.0.21}{172.21.0.21:9300}])
[2016-02-28 12:38:39,843][INFO ][http                     ] [elastic_src01_2] publish_address {172.21.0.21:9202}, bound_addresses {172.21.0.21:9202}
[2016-02-28 12:38:39,843][INFO ][node                     ] [elastic_src01_2] started

但是,当我在 SRC02 机器上启动节点 1 时,我没有看到 detected_master 消息。这是 ES 生成的内容:

[2016-02-28 12:22:52,256][INFO ][node                     ] [elastic_src02_1] version[2.2.0], pid[6432], build[8ff36d1/2016-01-27T13:32:39Z]
[2016-02-28 12:22:52,256][INFO ][node                     ] [elastic_src02_1] initializing ...
[2016-02-28 12:22:52,662][INFO ][plugins                  ] [elastic_src02_1] modules [lang-expression, lang-groovy], plugins [], sites []
[2016-02-28 12:22:52,693][INFO ][env                      ] [elastic_src02_1] using [1] data paths, mounts [[Data (E:)]], net usable_space [241.6gb], net total_
space [249.8gb], spins? [unknown], types [NTFS]
[2016-02-28 12:22:52,693][INFO ][env                      ] [elastic_src02_1] heap size [910.5mb], compressed ordinary object pointers [true]
[2016-02-28 12:22:54,193][INFO ][node                     ] [elastic_src02_1] initialized
[2016-02-28 12:22:54,193][INFO ][node                     ] [elastic_src02_1] starting ...
[2016-02-28 12:22:54,334][INFO ][transport                ] [elastic_src02_1] publish_address {172.21.0.22:9300}, bound_addresses {172.21.0.22:9300}
[2016-02-28 12:22:54,334][INFO ][discovery                ] [elastic_src02_1] elastic/SNvuAfnxQV-RW430zLF6Vg
[2016-02-28 12:22:58,912][INFO ][cluster.service          ] [elastic_src02_1] new_master {elastic_src02_1}{SNvuAfnxQV-RW430zLF6Vg}{172.21.0.22}{172.21.0.22:9300
}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-02-28 12:22:58,943][INFO ][gateway                  ] [elastic_src02_1] recovered [0] indices into cluster_state
[2016-02-28 12:22:58,959][INFO ][http                     ] [elastic_src02_1] publish_address {172.21.0.22:9200}, bound_addresses {172.21.0.22:9200}
[2016-02-28 12:22:58,959][INFO ][node                     ] [elastic_src02_1] started

SRC02机器上的节点真的和SRC01机器上的节点组成集群吗?

  1. 在同一台机器上(SRC01),如果我添加

discovery.zen.minimum_master_nodes: 3

到节点elastic_src01_1、elastic_src01_2的elasticsearch.yml文件, 然后在机器 SRC01 上启动第二个节点 elastic_src01_2 时,我无法在 ES 生成的消息中看到 detected_master

这是否意味着elastic_src01_1和elastic_src01_2不构成集群?

更新2

SRC01 和 SRC02 机器可以互相看到。以下是从 SRC02 到 SRC01 的 ping 结果:

C:\Users\Administrator>ping 172.21.0.21

Pinging 172.21.0.21 with 32 bytes of data:
Reply from 172.21.0.21: bytes=32 time<1ms TTL=128
Reply from 172.21.0.21: bytes=32 time<1ms TTL=128
Reply from 172.21.0.21: bytes=32 time<1ms TTL=128
Reply from 172.21.0.21: bytes=32 time<1ms TTL=128

更新3

问题已解决。我的设置之前无法正常工作的原因是服务器的防火墙阻止了端口 9300/9200 的通信。

最佳答案

基本上您只需要配置网络设置以确保所有节点都可以在网络上看到彼此。此外,由于您在同一台机器上运行两个节点并且您仍然需要高可用性,因此您希望防止主分片及其副本落在同一台物理机器上。

最后,由于集群中总共有四个节点,因此您需要 prevent split brain situations ,因此您还需要设置 discovery.zen.minimum_master_nodes

SRC01 上的节点 1/2:

# cluster name
cluster.name: Name_of_your_cluster

# Give each node a different name (optional but good practice if you don't know Marvel characters)
node.name: SRC01_Node1/2

# The IP that this node will bind to and publish
network.host: 172.21.0.21

# The IP of the other nodes
discovery.zen.ping.unicast.hosts: ["172.21.0.22"]

# prevent split brain
discovery.zen.minimum_master_nodes: 3    

# to prevent primary/replica shards to be on the same physical host 
# see why at http://stackoverflow.com/questions/35677741/proper-value-of-es-heap-size-for-a-dedicated-machine-with-two-nodes-in-a-cluster
cluster.routing.allocation.same_shard.host: true

# prevent memory swapping
bootstrap.mlockall: true

SRC02 上的节点 1/2:

# cluster name
cluster.name: Name_of_your_cluster

# Give each node a different name (optional but good practice if you don't know Marvel characters)
node.name: SRC02_Node1/2

# The IP that this node will bind to and publish
network.host: 172.21.0.22

# The IP of the other nodes
discovery.zen.ping.unicast.hosts: ["172.21.0.21"]

# prevent split brain
discovery.zen.minimum_master_nodes: 3    

# to prevent primary/replica shards to be on the same physical host 
# see why at http://stackoverflow.com/questions/35677741/proper-value-of-es-heap-size-for-a-dedicated-machine-with-two-nodes-in-a-cluster
cluster.routing.allocation.same_shard.host: true

# prevent memory swapping
bootstrap.mlockall: true

关于elasticsearch - 如何为每台机器上有两个节点的集群设置两台机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677833/

相关文章:

datetime - Elasticsearch如何在日期时间字段中按时间搜索

具有多个父/子关系的 Elasticsearch

elasticsearch - 在 Elastic Search 中对数组元素进行查询字符串搜索

ruby-on-rails - 如何从Rails on Rails应用程序内的设置更改elasticsearch max结果窗口?

elasticsearch - 如何为多值属性添加动态范围过滤器?

java - Elasticsearch自定义插件: Add extra query parameter before search

.net - IClrTypeMapping 与 ClrTypeMappingDescriptor

elasticsearch - 如何从构面中排除过滤器?

elasticsearch - 按找到的文档中的字段分组

html - 如何在Elasticsearch中将CURL转换为URI