How to install a three-node Elasticsearch Cluster on Ubuntu VPS

Manzeel Uprety
3 min readMay 3, 2020

--

Elasticsearch is a search tool and can be also used for analytics. You can save, find, and structure large chunks of data quickly. By the end of this tutorial, you will be able to make full use of the Elasticsearch.

Prerequisites

  • Ubuntu Webserver
  • sudo user

Step 1:

Consider three elastic nodes with the hostnames.

192.168.74.23 elk-node-1
192.168.74.24 elk-node-2
192.168.74.25 elk-node-3

Add these lines to /etc/hosts/ file

Step 2:

Create a partition for Elasticsearch under root partition.

lsblk | grep vda
vda 252:0 0 10G 0 disk

Now, create a GPT partition table for the secondary disk.

sudo parted -s -a optimal — /dev/vda mklabel gpt
sudo parted -s -a optimal — /dev/vda mkpart primary 0% 100%
sudo parted -s — /dev/vda align-check optimal 1

Now create an LVM volume to create an extended partition.

$ sudo pvcreate /dev/vda1
Physical volume “/dev/vda1” successfully created.$ sudo vgcreate vg10 /dev/vda1
Volume group “vg10” successfully created$ sudo lvcreate -n elasticsearch -l 100%FREE vg10
Logical volume “elasticsearch” created

Now create an ext4 filesystem on the Logical Volume recently created.

sudo mkfs.ext4 /dev/mapper/vg10-elasticsearch 
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 2620416 4k blocks and 655360 inodes
Filesystem UUID: 5d769fb5–68fc-4ee3-a5fa-0f6b5cda5758
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Step 3:

Import the GPG Public key for Elasticsearch for Ubuntu 18.04.

wget -qO — https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Now, add the repository to Ubuntu for installation.

echo “deb https://artifacts.elastic.co/packages/6.x/apt stable main” | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list

Step 4:

You will also need Java to install Elasticsearch. Install OpenJDK using the following command.

sudo apt update
sudo apt install apt-transport-https openjdk-8-jre-headless

Run apt command to install Elasticsearch.

sudo apt updatesudo apt install elasticsearch

Verify the mount point on /etc/fstab.

echo “/dev/mapper/vg10-elasticsearch /var/lib/elasticsearch/data ext4 defaults 0 0” | sudo tee -a /etc/fstab
mkdir /var/lib/elasticsearch/data

Step 5:

Change the permissions and mount the partition.

sudo mount -a 
sudo chown -R elasticsearch:elasticsearch /var/lib/elasticsearch/data
sudo chmod -R 775 /var/lib/elasticsearch/data

Step 6:

Configure your Elasticsearch cluster. Use your favorite editor.

sudo nano /etc/elasticsearch/elasticsearch.yml

Add the following lines to the elasticsearch.yml file.

cluster.name: hostadvice-clusternode.name: elk-node-1 #name for the node

On Node 1

node.name: elk-node-2 #name for the node

On Node 2

node.name: elk-node-3 #name for the node

On Node 3

Step 7:

Make changes in the path.data to /var/lib/elasticsearch/data/. It is the path where you will store the data.

path.data: /var/lib/elasticsearch/data

Now bind the IP address with each node.

network.host: 192.168.74.23 #ON NODE 1network.host: 192.168.74.24 #ON NODE 2network.host: 192.168.74.25 #ON NODE 3

The IP address should be made discoverable. Add the following lines to add the IP address.

discovery.zen.ping.unicast.hosts: [“192.168.74.23”, “192.168.74.24”, “192.168.74.25”]

Now, Specify the number of eligible nodes. Here we have a 3-node cluster.

discovery.zen.minimum_master_nodes: 3

Step 8:

Open port 9200 & 9300 if you have a running firewall.

sudo ufw allow 9200
sudo ufw allow 9300

Step 9:

You can run an elastic search and enable the service to automatically start on the next server reboot.

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl restart elasticsearch.service

===============================

If you find this post helpful, feel free to buy me a virtual coffee 😉👇🏻

buymeacoffee.com/mnzel

--

--

Manzeel Uprety
Manzeel Uprety

No responses yet