Blog Detail

Covid-19 Tracker Ask Question

preview image DevOps
by Anurag Srivastava, Apr 6, 2019, 8:41:41 PM | 4 minutes |

Creating Elasticsearch Cluster

Many times people ask me the question about configuring an Elasticsearch cluster where they can distribute the load on different servers. There are too many other questions like how to decide on server configuration, which architecture to follow, how many shards to keep, etc, etc. I will explain these in other blogs but here I want to focus on just to configure an Elasticsearch cluster using three different servers on AWS running CentOS.

I am assuming that Elasticsearch is installed and running on all of the servers using which you want to create the cluster. If you have any doubt on that you may refer to my previous blog on installing Elasticsearch. So before creating the cluster you need to ensure that all of your Elasticsearch nodes are running on the same version in order to avoid any further version compatibility conflict. Here in three nodes, I want to create a master cum data node and two data nodes but you can create two nodes as the data node with one dedicated master node. It all depends upon the type of infrastructure you are having and the kind of requirement you are having.

Now let's configure the master node first and for that, we need to stop the Elasticsearch service on the server and open “elasticsearch.yml” file. You need to follow the same for all other nodes as well.

To stop the service execute the following command

sudo systemctl stop elasticsearch.service

To open the configuration file:

sudo vim /etc/elasticsearch/elasticsearch.yml

Now change the cluster name with a meaningful name and ensure that the same cluster name is configured in all of your Elasticsearch nodes: bqcluster

Also, add node name and for each node, we need to provide different names through which we can identify it.
First node: bqnode-1

For other nodes, we can give the node names as "bqnode-2" and "bqnode-3"

Now set the first node as a master node using the following configuration:

node.master: true true
node.ingest: true

In the other two nodes you can add the following configuration:

node.master: false true
node.ingest: true

Now set the network host using the private IP of the server: [your_private_ip_address]

Now set the initial list of hosts to perform discovery under discovery section on elasticsearch configuration file: [node1_private_ip, node2_private_ip, node3_private_ip]]

After updating the “elasticsearch.yml” file you can start the elasticsearch service using the following command:

sudo systemctl start elasticsearch.service

After setting all three nodes we can check the status by executing the following command:

curl -XGET http://ip_address:9200/_cluster/health?pretty

Above command results the following output:

  "cluster_name" : "bqcluster",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 256,
  "active_shards" : 279,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 233,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 54.4921875

This way we can configure different nodes to work as an Elasticsearch cluster.

Other Blogs on Elastic Stack:
Introduction to Elasticsearch

Elasticsearch Installation and Configuration on Ubuntu 14.04
Log analysis with Elastic stack 
Elasticsearch Rest API
Basics of Data Search in Elasticsearch
Elasticsearch Rest API
Wildcard and Boolean Search in Elasticsearch
Configure Logstash to push MySQL data into Elasticsearch
Configure Logstash to push MongoDB data into Elasticsearch
Load CSV Data into Elasticsearch
Metrics Aggregation in Elasticsearch
Bucket Aggregation in Elasticsearch
How to create Elasticsearch Cluster

If you found this article interesting, then you can explore “Mastering Kibana 6.0”, “Kibana 7 Quick Start Guide”, “Learning Kibana 7”, and “Elasticsearch 7 Quick Start Guide” books to get more insight about Elastic Stack, how to perform data analysis, and how you can create dashboards for key performance indicators using Kibana.

You can also follow me on:

- LinkedIn:

- Twitter:

- Medium:

Comments (0)

Leave a comment

Related Blogs

Introduction to Cloud Computing

Sep 23, 2020, 2:38:00 PM | Anurag Srivastava

Monitoring website uptime using Kibana

Sep 6, 2020, 5:20:33 PM | Anurag Srivastava

Monitoring Application using Elastic APM

Jan 16, 2020, 11:43:29 AM | Anurag Srivastava

Configuring Django application with Elastic APM

Jan 14, 2020, 10:22:34 AM | Anurag Srivastava

Introduction to Elastic APM

Jan 7, 2020, 7:15:34 PM | Anurag Srivastava

Why monitoring is important?

Jan 6, 2020, 7:30:13 PM | Anurag Srivastava

Top Blogs

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Importing MongoDB data into Elasticsearch

Mar 9, 2019, 8:20:38 AM | Anurag Srivastava

Importing MySQL data into Elasticsearch

Feb 9, 2019, 12:06:18 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

Deploying Angular code using Python script

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava