Install and Configure Elasticsearch Cluster on CentOS 7 nodes

Jun 18, 2016 Linux

Install and Configure Elasticsearch Cluster on CentOS 7 nodes
Elasticsearch is a search server/engine based on Apache Lucene. It provides a multi-node distributed full-text search engine with an HTTP web interface and sophisticated RESTful API. Elasticsearch is developed in Java and is released as open source under the terms of the Apache License.

There are several types of nodes in Elasticsearch architecture:

  • Master-eligible node – eligible to be elected as Master node, which controls the cluster.
  • Data node – holds data and performs data related operations such as search, and aggregations
  • Client node – acts as a “router” forwarding cluster-level requests to the master node and data-related requests (such as search) to the data nodes
  • Tribe node – special type of client node that can connect to multiple clusters and perform data-related operations across clusters

In this tutorial we will install Elasticsearch Cluster on three Centos 7 based nodes: Master-eligible node, Data node and Client node.

Environment used:

  • es-master: CentOS 7.2 64bit, IP: 192.168.2.61
  • es-data: CentOS 7.2 64bit, IP: 192.168.2.62
  • es-client: CentOS 7.2 64bit, IP: 192.168.2.60

Steps:

1. Install Oracle Java on all nodes
Elasticsearch (version 2.3.3) requires Oracle JDK version >= 1.8

1.1 Master node

[root@es-master ~]# yum install wget
[root@es-master ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
[root@es-master ~]# yum localinstall jdk-8u91-linux-x64.rpm

1.2 Data node

[root@es-data ~]# yum install wget
[root@es-data ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
[root@es-data ~]# yum localinstall jdk-8u91-linux-x64.rpm

1.3 Client node

[root@es-client ~]# yum install wget
[root@es-client ~]# wget http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
[root@es-client ~]# yum localinstall jdk-8u91-linux-x64.rpm

2. Install Elasticsearch engine on all nodes
Elasticsearch website provides software RPMs for RedHat based distros, so we will install Elasticsearch from RPM on all CentOS 7 nodes:

2.1 Master node

[root@es-master ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.3/elasticsearch-2.3.3.rpm
[root@es-master ~]# yum localinstall elasticsearch-2.3.3.rpm

2.2 Data node

[root@es-data ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.3/elasticsearch-2.3.3.rpm
[root@es-data ~]# yum localinstall elasticsearch-2.3.3.rpm

2.3 Client node

[root@es-client ~]# wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.3/elasticsearch-2.3.3.rpm
[root@es-client ~]# yum localinstall elasticsearch-2.3.3.rpm

3. Configure Elasticsearch on each node

3.1 Configure Master node
Modify /etc/hosts file on Master node:

[root@es-master ~]# vim /etc/hosts
127.0.0.1      localhost localhost.localdomain localhost4 localhost4.localdomain4
::1            localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.61   es-master
192.168.2.62   es-data
192.168.2.60   es-client

Edit elasticsearch.yml file on Master node and modify the following lines:

[root@es-master ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-tuxfixer-cluster
node.name: es-master
node.master: true
node.data: false
network.host: ["es-master", "localhost"]
discovery.zen.ping.unicast.hosts: ["es-master", "es-data", "es-client"]

View whole elasticsearch.yml file from our Master node.

3.2 Configure Data node
Modify /etc/hosts file on Data node:

[root@es-data ~]# vim /etc/hosts
127.0.0.1      localhost localhost.localdomain localhost4 localhost4.localdomain4
::1            localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.61   es-master
192.168.2.62   es-data
192.168.2.60   es-client

Edit elasticsearch.yml file on Data node and modify the following lines:

[root@es-data ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-tuxfixer-cluster
node.name: es-data
node.master: false
node.data: true
network.host: ["es-data", "localhost"]
discovery.zen.ping.unicast.hosts: ["es-master", "es-data", "es-client"]

View whole elasticsearch.yml file from our Data node.

3.3 Configure Client node
Modify /etc/hosts file on Client node:

[root@es-client ~]# vim /etc/hosts
127.0.0.1      localhost localhost.localdomain localhost4 localhost4.localdomain4
::1            localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.61   es-master
192.168.2.62   es-data
192.168.2.60   es-client

Edit elasticsearch.yml file on Client node and modify the following lines:

[root@es-client ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-tuxfixer-cluster
node.name: es-client
node.master: false
node.data: false
network.host: ["es-client", "localhost"]
discovery.zen.ping.unicast.hosts: ["es-master", "es-data", "es-client"]

View whole elasticsearch.yml file from our Client node.

4. Enable Elasticsearch service on all nodes

4.1 Master node

[root@es-master ~]# systemctl daemon-reload
[root@es-master ~]# systemctl start elasticsearch
[root@es-master ~]# systemctl enable elasticsearch
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@es-master ~]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-06-18 19:38:37 CEST; 2h 51min ago
     Docs: http://www.elastic.co
 Main PID: 4658 (java)
   CGroup: /system.slice/elasticsearch.service
           └─4658 /bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupanc...

Jun 18 19:38:39 es-master elasticsearch[4658]: [2016-06-18 19:38:39,553][WARN ][env                      ] [es-master] max file descriptors [65535] for elasticsearch ...ast [65536]
Jun 18 19:38:42 es-master elasticsearch[4658]: [2016-06-18 19:38:42,033][INFO ][node                     ] [es-master] initialized
Jun 18 19:38:42 es-master elasticsearch[4658]: [2016-06-18 19:38:42,033][INFO ][node                     ] [es-master] starting ...
Jun 18 19:38:42 es-master elasticsearch[4658]: [2016-06-18 19:38:42,388][INFO ][transport                ] [es-master] publish_address {es-master/192.168.2.61:9300}, ....2.61:9300}
Jun 18 19:38:42 es-master elasticsearch[4658]: [2016-06-18 19:38:42,392][INFO ][discovery                ] [es-master] es-tuxfixer-cluster/6iSaanCMQLSTeUKlJlE8Sw
Jun 18 19:38:45 es-master elasticsearch[4658]: [2016-06-18 19:38:45,524][INFO ][cluster.service          ] [es-master] new_master {es-master}{6iSaanCMQLSTeUKlJlE8Sw}{...s received)
Jun 18 19:38:45 es-master elasticsearch[4658]: [2016-06-18 19:38:45,621][INFO ][http                     ] [es-master] publish_address {es-master/192.168.2.61:9200}, ....2.61:9200}
Jun 18 19:38:45 es-master elasticsearch[4658]: [2016-06-18 19:38:45,621][INFO ][node                     ] [es-master] started
Jun 18 19:38:45 es-master elasticsearch[4658]: [2016-06-18 19:38:45,654][INFO ][gateway                  ] [es-master] recovered [0] indices into cluster_state
Jun 18 22:29:19 es-master systemd[1]: Started Elasticsearch.
Hint: Some lines were ellipsized, use -l to show in full.

4.2 Data node

[root@es-data ~]# systemctl daemon-reload
[root@es-data ~]# systemctl start elasticsearch
[root@es-data ~]# systemctl enable elasticsearch
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@es-data ~]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-06-18 22:31:22 CEST; 9s ago
     Docs: http://www.elastic.co
 Main PID: 2488 (java)
   CGroup: /system.slice/elasticsearch.service
           └─2488 /bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupanc...

Jun 18 22:31:24 es-data elasticsearch[2488]: [2016-06-18 22:31:24,317][INFO ][env                      ] [es-data] using [1] data paths, mounts [[/ (rootfs)]], net us...es [rootfs]
Jun 18 22:31:24 es-data elasticsearch[2488]: [2016-06-18 22:31:24,317][INFO ][env                      ] [es-data] heap size [1015.6mb], compressed ordinary object pointers [true]
Jun 18 22:31:24 es-data elasticsearch[2488]: [2016-06-18 22:31:24,317][WARN ][env                      ] [es-data] max file descriptors [65535] for elasticsearch proc...ast [65536]
Jun 18 22:31:27 es-data elasticsearch[2488]: [2016-06-18 22:31:27,320][INFO ][node                     ] [es-data] initialized
Jun 18 22:31:27 es-data elasticsearch[2488]: [2016-06-18 22:31:27,320][INFO ][node                     ] [es-data] starting ...
Jun 18 22:31:27 es-data elasticsearch[2488]: [2016-06-18 22:31:27,606][INFO ][transport                ] [es-data] publish_address {es-data/192.168.2.62:9300}, bound_....2.62:9300}
Jun 18 22:31:27 es-data elasticsearch[2488]: [2016-06-18 22:31:27,611][INFO ][discovery                ] [es-data] es-tuxfixer-cluster/funkYGAHRuien67kUH48dQ
Jun 18 22:31:30 es-data elasticsearch[2488]: [2016-06-18 22:31:30,763][INFO ][cluster.service          ] [es-data] detected_master {es-master}{6iSaanCMQLSTeUKlJlE8Sw}{192.168.2....
Jun 18 22:31:30 es-data elasticsearch[2488]: [2016-06-18 22:31:30,837][INFO ][http                     ] [es-data] publish_address {es-data/192.168.2.62:9200}, bound_....2.62:9200}
Jun 18 22:31:30 es-data elasticsearch[2488]: [2016-06-18 22:31:30,837][INFO ][node                     ] [es-data] started
Hint: Some lines were ellipsized, use -l to show in full.

4.3 Client node

[root@es-client ~]# systemctl daemon-reload
[root@es-client ~]# systemctl start elasticsearch
[root@es-client ~]# systemctl enable elasticsearch
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@es-client ~]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-06-18 22:35:06 CEST; 9s ago
     Docs: http://www.elastic.co
 Main PID: 10914 (java)
   CGroup: /system.slice/elasticsearch.service
           └─10914 /bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupan...

Jun 18 22:35:08 es-client elasticsearch[10914]: [2016-06-18 22:35:08,119][INFO ][node                     ] [es-client] version[2.3.3], pid[10914], build[218bdf1/2016...T15:40:04Z]
Jun 18 22:35:08 es-client elasticsearch[10914]: [2016-06-18 22:35:08,120][INFO ][node                     ] [es-client] initializing ...
Jun 18 22:35:09 es-client elasticsearch[10914]: [2016-06-18 22:35:09,049][INFO ][plugins                  ] [es-client] modules [reindex, lang-expression, lang-groovy...], sites []
Jun 18 22:35:11 es-client elasticsearch[10914]: [2016-06-18 22:35:11,774][INFO ][node                     ] [es-client] initialized
Jun 18 22:35:11 es-client elasticsearch[10914]: [2016-06-18 22:35:11,774][INFO ][node                     ] [es-client] starting ...
Jun 18 22:35:11 es-client elasticsearch[10914]: [2016-06-18 22:35:11,971][INFO ][transport                ] [es-client] publish_address {es-client/192.168.2.60:9300},....2.60:9300}
Jun 18 22:35:11 es-client elasticsearch[10914]: [2016-06-18 22:35:11,976][INFO ][discovery                ] [es-client] es-tuxfixer-cluster/rjprGGN9TP-iayDrmphF7Q
Jun 18 22:35:15 es-client elasticsearch[10914]: [2016-06-18 22:35:15,161][INFO ][cluster.service          ] [es-client] detected_master {es-master}{6iSaanCMQLSTeUKlJlE8Sw}{192.1...
Jun 18 22:35:15 es-client elasticsearch[10914]: [2016-06-18 22:35:15,255][INFO ][http                     ] [es-client] publish_address {es-client/192.168.2.60:9200},....2.60:9200}
Jun 18 22:35:15 es-client elasticsearch[10914]: [2016-06-18 22:35:15,255][INFO ][node                     ] [es-client] started
Hint: Some lines were ellipsized, use -l to show in full.

5. Verify Elasticsearch Cluster

Verify from Master node, if all nodes joined the cluster:

[root@es-master ~]# curl -XGET 'http://localhost:9200/_cluster/state?pretty'
{
  "cluster_name" : "es-tuxfixer-cluster",
  "version" : 4,
  "state_uuid" : "5urMSACLTgSetfvltpHoEw",
  "master_node" : "6iSaanCMQLSTeUKlJlE8Sw",
  "blocks" : { },
  "nodes" : {
    "6iSaanCMQLSTeUKlJlE8Sw" : {
      "name" : "es-master",
      "transport_address" : "es-master/192.168.2.61:9300",
      "attributes" : {
        "data" : "false",
        "master" : "true"
      }
    },
    "rjprGGN9TP-iayDrmphF7Q" : {
      "name" : "es-client",
      "transport_address" : "192.168.2.60:9300",
      "attributes" : {
        "data" : "false",
        "master" : "false"
      }
    },
    "funkYGAHRuien67kUH48dQ" : {
      "name" : "es-data",
      "transport_address" : "192.168.2.62:9300",
      "attributes" : {
        "master" : "false"
      }
    }
  },
  "metadata" : {
    "cluster_uuid" : "hsvgG-fBS5y9-Fk9AI_OGw",
    "templates" : { },
    "indices" : { }
  },
  "routing_table" : {
    "indices" : { }
  },
  "routing_nodes" : {
    "unassigned" : [ ],
    "nodes" : {
      "funkYGAHRuien67kUH48dQ" : [ ]
    }
  }
}

Verify Cluster health from Master node:

[root@es-master ~]# curl 'localhost:9200/_cat/health?v'
epoch      timestamp cluster             status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 
1466282610 22:43:30  es-tuxfixer-cluster green           3         1      0   0    0    0        0             0                  -                100.0% 

6. (Optional) Open Elasticsearch TCP ports
If You have iptables enabled, then you need to open 9200/TCP and 9300/TCP ports on all nodes:

6.1 Master node

[root@es-master ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
[root@es-master ~]# firewall-cmd --zone=public --add-port=9300/tcp --permanent
[root@es-master ~]# firewall-cmd --reload

6.2 Data node

[root@es-data ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
[root@es-data ~]# firewall-cmd --zone=public --add-port=9300/tcp --permanent
[root@es-data ~]# firewall-cmd --reload

6.3 Client node

[root@es-client ~]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
[root@es-client ~]# firewall-cmd --zone=public --add-port=9300/tcp --permanent
[root@es-client ~]# firewall-cmd --reload

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.