Install Elasticsearch on Rocky Linux 8 / AlmaLinux 8

Elasticsearch is an open source full text search and analytics engine tool used in storing, searching and analysing big volumes of data real time. It supports RESTful operations i.e you can use HTTP methods in combisnation with a HTTP URI to manipulate data. This guide demonstrates how to install and configure Elasticsearch on Rocky and AlmaLinux.

Elastic search is popular due to its amazing features such as:

  1. Scalability and resiliency.
  2. Easy to use.
  3. REST APIs.
  4. Has improved security.
  5. Automatic node recovery.
  6. Automatic data balancing.

For Cluster setup setup checkout: Setup Three Node Elasticsearch Cluster on Rocky Linux 8 Using Ansible

Step 1: Install Java runtime

One of the dependencies that Elasticsearch uses is Java. In this guide, we will install Java OpenJDK 17.

sudo dnf install java-17-openjdk-devel

Dependency tree:

...
Transaction Summary
================================================================================
Install  3 Packages

Total download size: 43 M
Installed size: 177 M
Is this ok [y/N]: y

Verify the installed version.

$ java -version
openjdk version "17.0.11" 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.11.0.9-3) (build 17.0.11+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.11.0.9-3) (build 17.0.11+9-LTS, mixed mode, sharing)

Step 2: Install Elasticsearch

First install GPG key fro Elasticsearch rpm packages.

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

Second, create a yum repository for Elasticsearch as below:

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

In the file, paste the below lines:

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

With the created repository file, we an now install Elasticsearch using the below command:

sudo dnf install elasticsearch

Dependency tree:

...
Transaction Summary
================================================================================
Install  1 Package

Total download size: 312 M
Installed size: 520 M
Is this ok [y/N]: y

Step 3: Configure Elasticsearch

With a complete installation, we edit the configurations in /etc/elasticsearch/elasticsearch.yml

sudo vi /etc/elasticsearch/elasticsearch.yml

Set the node.name and cluster.name, they are set by finding these lines and uncomment them then edit them as below.

Edit the file as below:

cluster.name: my new cluster
     node.name: node-1
     path.data: /var/lib/elasticsearch
     network.host: 127.0.0.1

You can also specifiy a different path.data by uncommenting the path.data and changing the directory as

path.data: /path/to/media

Start and enable Elasticsearch service

sudo systemctl enable --now elasticsearch

Check the status of the service;

systemctl status elasticsearch

Step 4: Test Elasticsearch installation

Now we test and see if the installed Elasticsearch is working. Elasticsearch should be running on port 9200. Test this using the curl command as below.

  • Elasticsearch 7
curl -X GET 'http://localhost:9200'
  • Elasticsearch 8
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200

With the above response, Elasticserach is working properly on port 9200

Step 5: Using Elasticsearch

Here we will add we add some data and use manual queries.

Using CURL, we will add this entry:

curl -H 'Content-Type: application/json' -X POST 'http://localhost:9200/tutorial/helloworld/1' -d '{ "message": "Hello World!" }'

Output:

{"_index":"tutorial","_type":"helloworld","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1

We sent a HTTP POST request to the Elasticsearch server with the URI tuitorial/helloworld/1. There are parameters in the URI, tuitorial is the index of the data, helloworld is the type and 1 is the ID of the entry

Now lets retrieve the entry using HTTP GET request

curl -X GET 'http://localhost:9200/tutorial/helloworld/1'

Output:

{"_index":"tutorial","_type":"helloworld","_id":"1","_version":3,"_seq_no":2,"_primary_term":1,"found":true,"_source":{ "message": "Hello World!" }

We can modify the existing entry using HTTP PUT as below

curl -H 'Content-Type: application/json' -X PUT 'localhost:9200/tutorial/helloworld/1?pretty' -d '
{
  "message": "Welcome Back!"
}'

Output:

{
  "_index" : "tutorial",
  "_type" : "helloworld",
  "_id" : "1",
  "_version" : 4,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 3,
  "_primary_term" : 1
}

From the output, we have modified the message to “Welcome Back!” and the version number now increases to 2

The output of GET can be changed to a more readable/human-language by using the pretty argument

curl -X GET 'http://localhost:9200/tutorial/helloworld/1?pretty'

Output:

{
  "_index" : "tutorial",
  "_type" : "helloworld",
  "_id" : "1",
  "_version" : 4,
  "_seq_no" : 3,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "message" : "Welcome Back!"
  }
}

Explore More with CloudSpinx

Looking to streamline your tech stack? At CloudSpinx, we deliver robust solutions tailored to your needs.

Learn more about how we can support your journey with CloudSpinx.

Check out our other articles:


Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

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

Related Post

Complete development environments can be constructed with the help of Vagrant. The “it works on my machine” justification is rendered […]

Virtualization is a technology that allows the creation of virtual instances or environments of computer hardware, operating systems, storage devices, […]

Zimbra Collaboration Suit (ZCS) is an open-source collaborative suite providing an email server and a web client. Among other services […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.