Elasticsearch Cluster Install on CentOS 7

This post wont go in to any detail around setting up CentOS itself, but it will cover getting a simple 3 node Elasticsearch cluster up and running, with a couple of helpful plugins.

Install Java and check the install

yum install java-1.8.0-openjdk.x86_64 -y
java -version

Download Elasticsearch (check the site here for the latest versions)

cd /tmp
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.2.1/elasticsearch-2.2.1.rpm

Install Elasticsearch

cd /tmp
sudo rpm -ivh elasticsearch-2.2.1.rpm

This results in Elasticsearch being installed in /usr/share/elasticsearch/ with its configuration files placed in /etc/elasticsearch and its init script added in /etc/init.d/elasticsearch

Enable Elasticsearch on Boot

sudo systemctl enable elasticsearch.service

Configure Elasticsearch

vi /etc/elasticsearch/elasticsearch.yml

Add near the top, and replace anything in < > with your details

cluster.name: <name of the cluster>
#below line dynamically sets the node name based on the server hostname
node.name: ${HOSTNAME}
#below binds elasticsearch to the local (127.0.0.1) and site ip address (e.g. 192.168.1.1)
network.host: [_site_, _local_]
http.port: 9200
bootstrap.mlockall: true
#below sets the nodes the cluster should find
discovery.zen.ping.unicast.hosts: ["<node1_ip_or_fqdn>", "<node2_ip_or_fqdn>", "<node3_ip_or_fqdn>"]

Restart and Verify Elasticsearch status

sudo systemctl restart elasticsearch.service
sudo systemctl status elasticsearch.service

You should be able to access the node now, on: http://<node-ip>:9200

Optional: Install Elastic-HQ and Head Plugins

cd /usr/share/elasticsearch/
bin/plugin install mobz/elasticsearch-head
sudo bin/plugin install royrusso/elasticsearch-HQ
sudo systemctl restart elasticsearch.service
sudo systemctl status elasticsearch.service

Once installed, you can access these plugins via:
Head = http://:9200/plugin/head
HQ = http://:9200/
plugin/hq

Additional Nodes:

Repeat the same process on your other servers, you can add more than 3 nodes to the cluster, but if you do make sure you update discovery.zen.ping.unicast.hosts in your Elasticsearch config to include those additional nodes.

Published 24 Jun 2016

Automation Consultant, currently working at Xtravirt. Interested in all things automation/devops related.
Sam Perrin on Twitter