Elasticsearch Installation How-To (Centos 7)

Published on Author gryzli

Elasticsearch install is pretty straight forward (also making cluster of elastic nodes).The following howto is about installing elasticsearch 6.x, which is the current latest version.

It is good to know some basic concepts of ElasticSearch before using it. 

I’m not going to talk about the hardware requirements, because they strongly depend on the setup and the data that’s going to be inserted into the cluster.There is one thing, that should be always considered and it is : make sure you have enough RAM on your cluster nodes.

There are some guidance about the hardware to use for elasticsearch , which you can find here :

https://www.elastic.co/guide/en/elasticsearch/guide/current/hardware.html

 

In the following setup I assume you have 2 servers :

Server1

IP: 192.168.1.1

hostname: elastic-node1

Big disk mount: /data

elastic cluster name: my-cluster

OS: Centos7

Server2

IP: 192.168.1.2

hostname: elastic-node2

Big disk mount: /data

elastic cluster name: my-cluster

OS: Centos7

 

1/ Installing Elasticsearch

The easiest way for installing elasticsearch is to use the repository for Centos 7.

The following steps should be done on both of your cluster nodes.

Add elastic repo

Adding the repository to yum is as easy as doing :

vim /etc/yum.repos.d/elasticsearch-6.x.repo

[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

 

Install openjdk

yum install java-1.8.0-openjdk

 

Install Elasticsearch

yum install elasticsearch

systemctl enable elasticsearch

 

Make sure you edit your systemd service file and have the following inside:

vim /lib/systemd/system/elasticsearch.service

...
...
LimitMEMLOCK=infinity
MAX_LOCKED_MEMORY=unlimited
....
....

2/ Configuring Elasticsearch

 

Configuring elastic nodes

(Configuration  for elastic-node2 should be the same, you should only change IP/Hostname to the appropriate ones for the second node)

 

1) Editing /etc/elasticsearch/elasticsearch.yml

vim /etc/elasticsearch/elasticsearch.yml

 

Edit the following options:

##################################
cluster.name: my-cluster
node.name: elastic-node1
path.data: /data/elastic/elastic-node1
path.logs: /var/log/elasticsearch

bootstrap.memory_lock: true
network.host: 192.168.1.1
http.port: 9200

# Make sure to add all your nodes host names 
discovery.zen.ping.unicast.hosts: ["elastic-node1", "elastic-node2"]

# If we have more than 2 nodes in our cluster, this setting should be set 
# to '2' or bigger number 
discovery.zen.minimum_master_nodes: 1

##################################

 

2) Configure logging

Logging options of ElasticSearch could be controlled by modifying the following file :

/etc/elasticsearch/log4j2.properties

 

 

3) Configure JVM options

One very important thing is to correctly configure your memory settings inside your JVM config:

vim /etc/elasticsearch/jvm.options

You should change accordingly:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms1g
-Xmx1g

Depending on your setup / use-case you may configure 2,3,4G of memory.

If the machine is going to be elastic-node dedicated machine, you could put up to 80-85% of your memory.

 

4) (Optional) Add hard-coded records to your hosts file

This step is optional, but I’m doing it when setting up elastic cluster in the sake of safety.

I’m adding hard-coded host to IP mappings for all nodes in the cluster to their /etc/hosts files. By doing this I’m making sure that cluster nodes will see each other even if there is some DNS related problem.

These lines should be added to all of the nodes inside your ES cluster:

vim /etc/hosts

192.168.1.1 elastic-node1
192.168.1.2 elastic-node2

 

5) Fix firewall on both nodes (elastic-node1 / elastic-node2)

Make sure to enable connection between your elastic nodes .

Each node should be able to access the TCP port range of 9200 – 9400 of the other nodes.

 

3/ Final

We are done , now you need only to restart your elasticsearch services and make sure everything is okay.

systemctl restart elasticsearch

 

You should check your cluster status and make sure it is working properly:

elastic-node1# curl http://elastic-node1:9200/_cluster/health?pretty

Make sure you see “status”:”green”.

 

Now you can proceed with installing Kibana , which is a great tool for working with your cluster and visualizing data.