How to Setup an ElasticSearch Cluster

Samuel Addico
CodeOps
Published in
2 min readFeb 2, 2019

Introduction

In this guide, we will be looking at how to setup an ElasticSearch cluster comprising three nodes. ElasticSearch is a popular open source search server that is used for real-time distributed search and analysis of data.

This guide assumes you have your hostname correctly configured and mapped to the corresponding private IP addresses as show in this tutorial

ElasticSearch Installation

We will install ElasticSearch on all three nodes.Follow the steps below for each of the 3 nodes.

Adding the Repo

We’ll use the Elasticsearch APT repo to fetch and install the packages from. To do this, first add their signing key:

wget -O /tmp/eskey https://packages.elastic.co/GPG-KEY-elasticsearch
sudo apt-key add /tmp/eskey
rm /tmp/eskey

Configure Source List

Add the repo URL to your sources list as shown below :

sudo tee /etc/apt/sources.list.d/elasticsearch-6.x.list <<EOREP
deb https://packages.elastic.co/elasticsearch/6.x/debian stable main
EOREP
sudo apt-get update

Install JDK 8

ElasticSearch is built on Java and requires at least ≥ Java 8 to run. We will therefore install Java by following below guides.

sudo apt-get install openjdk-8-jdk

Please note that the same version should be installed on all Elasticsearch nodes in the cluster.

Install ElasticSearch

Now we are set to install ElasticSearch.

sudo apt-get install elasticsearch

Configure ElasticSearch Cluster

Now it’s time to edit the Elasticsearch configuration file located at

/etc/elasticsearch/elasticsearch.yml#cluster name.cluster.name: my-es-cluster#node name,change for each nodenode.name: "Primary"#this is the master,this will change the secondary nodesnode.master: truenode.data: true#node private ipnetwork.host: 172.31.22.24http.port: 9200#initial list of hosts to perform discovery when new node discovery.zen.ping.unicast.hosts: ["172.31.22.24","172.31.18.11","172.31.24.121"]# to avoid "split brain".
discovery.zen.minimum_master_nodes: 2

Restart all node with :

sudo service elasticsearch restart

If your configuration are done properly below should be the response after running below :

curl -XGET 'http://172.31.22.24:9200/_cluster/state?pretty'

This is a standard cluster setup,to make this more production usable, its is recommended to do some tuning.This will be in the Part 2 of this post.See you soon.Let me know what you think about this.

--

--

Samuel Addico
CodeOps

DevOps | SRE | Java | Kubernetes | AWS | Ansible | Terraform | CI/CD