ES集群的主節點發現機制采用單播形式,主要配置有三行,如下:
discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.multicast.enabled: false discovery.zen.ping.unicast.hosts: ["localhost:9001","localhost:9101","localhost:9701"]
第一行的配置說明如下:
# Discovery infrastructure ensures nodes can be found within a cluster # and master node is elected. Multicast discovery is the default. # Set to ensure a node sees N other master eligible nodes to be considered # operational within the cluster. This should be set to a quorum/majority of # the master-eligible nodes in the cluster. # discovery.zen.minimum_master_nodes: 2
了解Zookeeper的話,這個配置就比較容易理解了; 數值取值為 (有資格當選為Master的節點個數/2+1), 這樣做是為了防止腦裂現象, 防止某些主節點自成一個集群. 考慮到Zookeeper的一些配置, 主節點的個數最好是奇數個,並且不少於3個;但是會帶來一個問題,如必須至少一半以上的主節點是可用的,如果不能滿足這個要求,則系統就會崩潰.
第二行和第三行的配置說明如下:
# Unicast discovery allows to explicitly control which nodes will be used # to discover the cluster. It can be used when multicast is not present, # or to restrict the cluster communication-wise. # # 1. Disable multicast discovery (enabled by default): # discovery.zen.ping.multicast.enabled: false # # 2. Configure an initial list of master nodes in the cluster # to perform discovery when new nodes (master or data) are started: # discovery.zen.ping.unicast.hosts: ["localhost:9001","localhost:9101","localhost:9701"]
1是關閉多播,采用單播;置為false
2是給出所有的Master節點的IP和Port.端口用數據交換接口即可;
集群的節點打算分三種角色, master節點,僅充當master作用,不存儲數據; data節點, 僅存儲數據,不能當選為master節點; observer節點, 既不充當master,也不存儲數據;