elasticsearch 是非常流行的全文搜索引擎,但网上的教程多是初次使用,并没有一些高级用法demo。这次遇到需要跨网段组网问题,自己摸索了文档很久,发现确实可行,于是着手做了个实验,最终实验成功。在跨网段下实现了自动发现和组网。
总共运行了三个节点,一个节点IP是192.168.45.67,另外两个节点IP都是172.20.5.161三个文件的配置文件都改为如下配置文件,先后启动三个节点,记录日志在后面。
192.168.45.67节点启动后,自动用9300作为通信端口,将自身作为master节点存在。
172.20.5.161节点启动后,自动用9300作为通信端口,发现hosts列表中有master存在,master将其加入集群中。
172.20.5.161节点启动后,发现9300被占用,自动用9301作为通信端口,发现hosts列表中有master存在,master将其加入集群中。
192.168.45.67:9300添加日志
172.20.5.161:9300添加日志
172.20.5.161:9301添加
elasticsearch-1.5.2/config/elasticsearch.yml需要修改部分为
discovery.zen.ping.multicast.enabled和discovery.zen.ping.unicast.hosts,修改如下:
################################## Discovery ################################## # 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: 1 # Set the time to wait for ping responses from other nodes when discovering. # Set this option to a higher value on a slow or congested network # to minimize discovery failures: # #discovery.zen.ping.timeout: 3s # For more information, see # <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html> # 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: ["192.168.45.67", "172.20.5.161:9300"] # EC2 discovery allows to use AWS EC2 API in order to perform discovery. # # You have to install the cloud-aws plugin for enabling the EC2 discovery. # # For more information, see # <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html> # # See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/> # for a step-by-step tutorial. # GCE discovery allows to use Google Compute Engine API in order to perform discovery. # # You have to install the cloud-gce plugin for enabling the GCE discovery. # # For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>. # Azure discovery allows to use Azure API in order to perform discovery. # # You have to install the cloud-azure plugin for enabling the Azure discovery. # # For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
配置的中文注释请看: