Saturday, November 25, 2017

Elastic Search - Clustering

In the previous post, we saw how to install and run an elasticsearch instance. In this post, we will see how to cluster it. Clustering is required to support high availability and we will be seeing how to cluster 3 nodes of elasticsearch.

  1. Follow my post to install and run an elastic search node. Repeat it to create multiple nodes on different machines / VM in the same network or multiple nodes on the same machine running on different ports. Running multiple nodes on the same machine comes in handy while developing and researching and can be done by changing the http.port value as described in the next step

  2. Navigate to the config folder inside elasticsearch install location of each of the nodes ie: C:\Deploy\elasticsearch-1.7.2\config. Open the elasticsearch.yml file and update the following settings
    • cluster.name:  clusterXXXPool  -- Name of the cluster to be same across all nodes
    • node.name: "NodeXXX" -- Individual node name
    • bootstrap.mlockall: true -- To lock the memory
    • http.port: 9200 -- Port on which elasticsearch will run
    • discovery.zen.minimum_master_nodes: 2 -- Creates a cluster with minimum 2 master nodes
    • discovery.zen.ping.timeout: 10s
    • discovery.zen.ping.unicast.hosts:["Node1_IP:Port",”Node2_IP:Port","Node3_IP:Port"] -- Lists the node names in cluster

    These are the few settings that can be applied. The config file itself has comments for each setting and provides a good self-documentation if you want to learn more about it.

  3. Restart all the elasticsearch services that are part of the cluster for the settings to be applied.

  4. Use the following URLs on the browser to check cluster related settings
    • NodeIP:Port/_cluster/health – Cluster Health
    • NodeIP:Port/_cat/nodes – Nodes in the cluster
    • NodeIP:Port/_cat/master – Master in the cluster
    • NodeIP:Port/_cluster/settings – Settings of the cluster
    • NodeIP:Port/_cluster/nodes/stats – Statistics of each Node

    To verify if the cluster was set up properly and check its health and status, try to bring down one of the nodes by stopping the service and seeing the output of the above commands.

  5. You can also install Head Plugin to visualize the Cluster Health, Indices and Shards.



No comments: