Database

How to Install and Configure Elasticsearch on Rocky Linux 8

Pinterest LinkedIn Tumblr

In this guide, we will learn how to install and configure Elasticsearch on Rocky Linux 8. This guide will also work on other RHEL 8 based distros like Alma Linux 8 and Oracle Linux 8.

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. Elasticsearch has quickly become the most popular search engine and is commonly used for log analytics, full-text search, security intelligence, business analytics, and operational intelligence use cases.

Related Content

Prerequisites

To follow along, ensure that you have:

  • An updated Rock Linux8 server with at least 2 GB of RAM and 2 cores
  • Root access to the server or user with sudo access
  • Access to the internet from the server

Table of Content

  1. Ensure the server is up to date
  2. Installing Java on the server
  3. Import the elasticsearch gpg key
  4. Install Elasticsearch from the RPM Repo
  5. Start and enable the Elasticsearch service
  6. Verify Elasticsearch installation
  7. Performing simple operations with Elasticsearch

1. Ensuring that the server is up to date

Before proceeding, let us ensure that our server is up to date and all the packages are the latest version. Use these commands to achieve this:

sudo dnf -y update

If there are packages to upgrade, the above command may take a couple of minutes.

2. Install Java on the server

Elasticsearch depends on Java to run. Install java 11 runtime

sudo dnf install java-11-openjdk

Verify the installed version.

$ java -version
openjdk version "11.0.13" 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)

3. Import the Elasticsearch GPG Key

Elasticsearch signs all of our packages with the Elasticsearch Signing Key (PGP key D88E42B4, available from https://pgp.mit.edu) with fingerprint:

4609 5ACC 8548 582C 1A26 99A9 D27D 666C D88E 42B4

Download and install the public signing key:

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

4. Install Elasticsearch from the RPM repository

Create a file called elasticsearch.repo in the /etc/yum.repos.d/ . Use your text editor to open the file:

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

Then add the following the content:

[elasticsearch]
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=0
autorefresh=1
type=rpm-md

And your repository is ready for use. You can now install Elasticsearch.

Use this command to install elasticsearch

sudo dnf install --enablerepo=elasticsearch -y elasticsearch

Confirm

$ rpm -qi elasticsearch
Name        : elasticsearch
Epoch       : 0
Version     : 7.16.3
Release     : 1
Architecture: x86_64
Install Date: Fri 14 Jan 2022 09:21:53 AM UTC
Group       : Application/Internet
Size        : 517226057
License     : Elastic License
Signature   : RSA/SHA512, Fri 07 Jan 2022 02:57:25 AM UTC, Key ID d27d666cd88e42b4
Source RPM  : elasticsearch-7.16.3-1-src.rpm
Build Date  : Thu 06 Jan 2022 11:49:11 PM UTC
Build Host  : packer-virtualbox-iso-1636998457
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

5. Start and enable the Elasticsearch service

The Elasticsearch service won’t be started by default. Use this command to start:

sudo systemctl start elasticsearch

Confirm the service status using this command:

$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-01-14 09:22:41 UTC; 16min ago
     Docs: https://www.elastic.co
 Main PID: 68286 (java)
    Tasks: 64 (limit: 23176)
   Memory: 2.2G
   CGroup: /system.slice/elasticsearch.service
           ├─68286 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=tr>
           └─68485 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Jan 14 09:22:18 dev-rockysrv.inv.re systemd[1]: Starting Elasticsearch...
Jan 14 09:22:41 dev-rockysrv.inv.re systemd[1]: Started Elasticsearch.

The above output shows that the service is up and running. Enable the service using this command:

sudo systemctl enable elasticsearch

If Elasticsearch fails to start for any reason, it will print the reason for failure to STDOUT. Log files can be found in /var/log/elasticsearch/.

By default the Elasticsearch service doesn’t log information in the systemd journal. To enable journalctl logging, the --quiet option must be removed from the ExecStart command line in the elasticsearch.service file.

When systemd logging is enabled, the logging information are available using the journalctl commands:

To tail the journal:

sudo journalctl -f

To list journal entries for the elasticsearch service:

sudo journalctl --unit elasticsearch

To list journal entries for the elasticsearch service starting from a given time:

sudo journalctl --unit elasticsearch --since  "2016-10-30 18:17:16"

6. Verify Elasticsearch Installation

At this point, ElasticSearch is started and listening on port 9200. You can check it with the following command:

ss -antpl | grep 9200

You should see the following output:

$ ss -antpl | grep 9200
LISTEN 0      128    [::ffff:127.0.0.1]:9200             *:*
LISTEN 0      128                 [::1]:9200          [::]:*

you can also verify ElasticSearch with the following command.

curl -X GET "localhost:9200/"

output:

$ curl -X GET "localhost:9200/"
{
  "name" : "dev-rockysrv.inv.re",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "td67jm-zSvKlKsnP4sIrxw",
  "version" : {
    "number" : "7.16.3",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "4e6e4eab2297e949ec994e688dad46290d018022",
    "build_date" : "2022-01-06T23:43:02.825887787Z",
    "build_snapshot" : false,
    "lucene_version" : "8.10.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

7. Performing simple operations with Elasticsearch

You can use the Curl command to add data to the ElasticSearch as shown below:

curl -H 'Content-Type: application/json' -X POST 'http://localhost:9200/todo/task/1' -d '{ "name": "Go to the mall." }'

You should see the following output:

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

You can now retrieve your data using the GET request:

curl -X GET 'http://localhost:9200/todo/task/1'

You should see the following output:

{"_index":"todo","_type":"task","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{ "name": "Go to the mall." }}

To retrieve the data in human-readable format, run the following command:

curl -X GET 'http://localhost:9200/todo/task/1?pretty'

You should get the following output:

{
  "_index" : "todo",
  "_type" : "task",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "name" : "Go to the mall."
  }
}

Conclusion

That’s it. In this guide, you we learned how to install and use ElasticSearch on Rocky Linux 8 server. You can now easily add, read, delete, and update data in Elasticsearch.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment