This tutorial discusses how to install ElasticSearch 7.x on CentOS 7. Elasticsearch is an open source search and analytics engine that allows you to store, search, and analyze big volumes of data in real time. Elasticsearch powers millions of Applications that rely on intensive search operations such as e-commerce platforms and big data applications.

The latest release of ElasticSearch as of this article update is 7. We will cover the minimum steps you’ll need to install ElasticSearch 7 on CentOS 7 Linux system. So let’s get started.

Step 1: Update CentOS 7 Linux

The server you’re working on should be updated before you install ElasticSearch 7.x on CentOS 7. Just run the commands below to update it.

sudo yum -y update
sudo reboot

Step 2: Install Java on CentOS 7

ElasticSearch requires Java installed for it to run. The default Java installable on CentOS 7 is Java 8. Here are the commands to use for the installation.

sudo yum -y install java-1.8.0-openjdk  java-1.8.0-openjdk-devel

Set Java home

cat <<EOF | sudo tee /etc/profile.d/java8.sh
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF

Source created file to update your environment.

source /etc/profile.d/java8.sh

Step 3: Add ElasticSearch Yum repository

Add the repository for downloading ElasticSearch 7 packages to your CentOS 7 system.

cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

If you want to install Elasticsearch 6, replace all occurrences of 7 with 6. Once the repository is added, clear and update your YUM package index.

sudo yum clean all
sudo yum makecache

Step 4: Install ElasticSearch 7 on CentOS 7

Finally install ElasticSearch 7.x on your CentOS 7 machine. Note that we’ve added an open source repository. Commercial flavor is available on the other repository.

sudo yum -y install elasticsearch-oss

Confirm ElasticSearch 7 installation on CentOS 7:

$ rpm -qi elasticsearch-oss
Name        : elasticsearch-oss
Epoch       : 0
Version     : 7.4.0
Release     : 1
Architecture: x86_64
Install Date: Thu 17 Oct 2019 05:10:43 AM UTC
Group       : Application/Internet
Size        : 395896718
License     : ASL 2.0
Signature   : RSA/SHA512, Fri 27 Sep 2019 10:40:01 AM UTC, Key ID d27d666cd88e42b4
Source RPM  : elasticsearch-oss-7.4.0-1-src.rpm
Build Date  : Fri 27 Sep 2019 08:49:06 AM UTC
Build Host  : packer-virtualbox-iso-1559162487
Relocations : /usr 
Packager    : Elasticsearch
Vendor      : Elasticsearch
URL         : https://www.elastic.co/
Summary     : Distributed RESTful search engine built for the cloud
Description :
Reference documentation can be found at
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
and the 'Elasticsearch: The Definitive Guide' book can be found at
https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html

Configure Java memory Limits

You can set JVM options like memory limits by editing the file: /etc/elasticsearch/jvm.options

Example below sets initial/maximum size of total heap space

$ sudo vi /etc/elasticsearch/jvm.options
.....
-Xms1g
-Xmx1g

If your system has less memory, you can configure it to use small megabytes of ram.

-Xms256m
-Xmx512m

Start and enable elasticsearch service on boot:

sudo systemctl enable --now elasticsearch

Confirm that the service is running.

$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-10-17 05:16:00 UTC; 13s ago
     Docs: http://www.elastic.co
 Main PID: 8774 (java)
   CGroup: /system.slice/elasticsearch.service
           └─8774 /usr/share/elasticsearch/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSI...

Oct 17 05:15:46 cent7.novalocal systemd[1]: Starting Elasticsearch...
Oct 17 05:15:46 cent7.novalocal elasticsearch[8774]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in versio...elease.
Oct 17 05:16:00 cent7.novalocal systemd[1]: Started Elasticsearch.
Hint: Some lines were ellipsized, use -l to show in full.

Check if you can connect to ElasticSearch Service.

$ curl http://127.0.0.1:9200 
{
  "name" : "cent7.novalocal",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "SmGu9eXJRlGzxqEy2brGXQ",
  "version" : {
    "number" : "7.4.0",
    "build_flavor" : "oss",
    "build_type" : "rpm",
    "build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
    "build_date" : "2019-09-27T08:36:48.569419Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

You should be able to create an index with curl.

$ curl -X PUT "http://127.0.0.1:9200/test_index"
{"acknowledged":true,"shards_acknowledged":true,"index":"test_index"}

Step 5: Install Kibana 7 on CentOS 7

Related ElasticSearch Packages such as Kibana, Logstash e.t.c can be installed from the repository added.

sudo yum install kibana-oss logstash

After a successful installation, configure Kibana:

$ sudo vi /etc/kibana/kibana.yml
server.host: "0.0.0.0"
server.name: "kibana.example.com"
elasticsearch.url: "http://localhost:9200"

Change other settings as desired then start kibana service:

sudo systemctl enable --now kibana

If you have an active firewall, you’ll need to allow access to Kibana port:

sudo firewall-cmd --add-port=5601/tcp --permanent
sudo firewall-cmd --reload

Access http://ip-address:5601 to open Kibana Dashboard:

You have installed ElasticSearch 7.x and Kibana on CentOS 7 Server/Desktop. Check other ElasticSearch guides available in our blog.

How to delete Elasticsearch Index data with curl

Install Graylog with ElasticSearch on CentOS 7