How To Set up ElasticSearch on Centos 7

In this article, we want to teach you How To Set up ElasticSearch on Centos 7.

Elasticsearch is a real-time open-source distributed search and analytics engine built on top of Apache Lucene, a full-text search-engine library and developed in Java.

Set up ElasticSearch on Centos 7

Before you start to install ElasticSearch on Centos 7, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.

Now follow the steps below to install ElasticSearch on your Centos 7.

Install Java on Centos 7

To install ElasticSearch, you need Java installed on your server. First, update your local package index with the following command:

sudo yum -y update

Then, install Java on Centos 7 with the command below:

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

When your installation is completed, check your Java installation by checking its version:

java -version

In your output you will see:

Output
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

Install ElasticSearch on Centos 7

You need to add the ElasticSearch repository to your Centos 7. Create and open the file with your favorite text editor, here we use vi:

sudo vi /etc/yum.repos.d/elasticsearch.repo

Add the following contents to the file:

[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

When you are done save and close the file.

Note: If you want to install Elasticsearch 6, replace all occurrences of 7 with 6.

Now update your local package index:

sudo yum -y update

Then, you can use the following command to install ElasticSearch on Centos 7:

sudo yum -y install elasticsearch-oss

Verify your ElasticSearch installation with the command below:

rpm -qi elasticsearch-oss

In your output you will see:

Output
Name : elasticsearch-oss
Epoch : 0
Version : 7.10.2
Release : 1
Architecture: x86_64
Install Date: Mon 20 Dec 2021 01:27:10 AM EST
Group : Application/Internet
Size : 420252496
License : ASL 2.0
Signature : RSA/SHA512, Tue 12 Jan 2021 10:45:21 PM EST, Key ID d27d666cd88e42b4
Source RPM : elasticsearch-oss-7.10.2-1-src.rpm
Build Date : Tue 12 Jan 2021 07:54:36 PM EST
...

Configure ElasticSearch for Java memory Limits

At this point, you can set JVM options like Java limits in the /etc/elasticsearch/jvm.options.

Open the file with your favorite text editor, here we use vi:

sudo vi /etc/elasticsearch/jvm.options

Find the lines below at the file:

..... 
-Xms1g 
-Xmx1g

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

-Xms256m
-Xmx512m

When you are done, save and close the file.

Now start and enable your ElasticSearch service on boot with the command below:

sudo systemctl enable --now elasticsearch

Verify your ElasticSearch service is active and running on your Centos 7 with the following command:

sudo systemctl status elasticsearch

In your output you will see:

Output
elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-12-20 01:36:44 EST; 5min ago
     Docs: https://www.elastic.co
 Main PID: 22411 (java)
   CGroup: /system.slice/elasticsearch.service
           └─22411 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.ne...
At this point, you can connect to your ElasticSearch on Centos 7 by using the curl command:
curl http://127.0.0.1:9200

You should get the following output:

Output
{
"name" : "centos7.orca",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "XTjU0PtaQ2COK4Q0_OH2uA",
"version" : {
"number" : "7.10.2",
"build_flavor" : "oss",
"build_type" : "rpm",
"build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
"build_date" : "2021-01-13T00:42:12.435326Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

Also, you should be able to create an index with the curl command:

curl -X PUT "http://127.0.0.1:9200/test_index"

In your output you will see:

Output
{"acknowledged":true,"shards_acknowledged":true,"index":"test_index"}

That’s it. You have successfully installed ElasticSearch on your Centos 7.

Conclusion

At this point, you learn to Set up ElasticSearch on your Centos 7.

Elasticsearch powers millions of applications that rely on intensive search operations such as e-commerce platforms and big data applications.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!