Best Steps To Install Elasticsearch on Rocky Linux 8

In this guide, we want to teach you How To Install Elasticsearch on Rocky Linux 8. Elasticsearch is a modern search and analytics engine which is based on Apache Lucene. Completely open source and built with Java, Elasticsearch is a NoSQL database. That means it stores data in an unstructured way and that you cannot use SQL to query it.

You can now proceed to the guide steps below on the Orcacore website to set up Elasticsearch on Rocky Linux 8.

Steps To Install and Configure Elasticsearch on Rocky Linux 8

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

1. Install Java for Elasticsearch Setup

Elasticsearch needs Java installed on your server. First, update your local package index with the following command:

sudo dnf update -y

To install the OpenJDK package on Rocky Linux 8, run the following command:

sudo dnf install java-11-openjdk-devel -y

Now verify that your Java installation was successful by printing its version:

java -version

In your output you will see:

Output
openjdk version "11.0.17" 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS, mixed mode, sharing)

2. Install Elasticsearch on Rocky Linux 8

As you know, the Elasticsearch package is not available in the default Rocky Linux repository. You need to install it from the Elasticsearch RPM repository.

Import Elasticsearch GPG Key

First, import the GPG key with the following command:

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

Add Elasticsearch 8 Repository

Then, you need to create an Elasticsearch repository file with your favorite text editor, here we use vi text editor:

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

Add the following content to the file:

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

When you are done, save and close the file.

Now you can use the following command to install Elasticsearch on your Rocky Linux server:

sudo dnf install --enablerepo=elasticsearch elasticsearch -y

Verify your Elasticsearch installation by using the command below:

rpm -qi elasticsearch
Elasticsearch Rocky Linux 8

Manage Elasticsearch Service

At this point, you need to start and enable Elasticsearch to start on boot on Rocky Linux 8. To do this, use the following commands:

# sudo systemctl daemon-reload
# sudo systemctl enable elasticsearch.service
# sudo systemctl start elasticsearch.service

Verify that your service is active and running:

sudo systemctl status elasticsearch.service
Output
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vend>
   Active: active (running) since Tue 2022-11-08 05:06:43 EST; 55s ago
     Docs: https://www.elastic.co
 Main PID: 89849 (java)
    Tasks: 90 (limit: 23699)
   Memory: 2.4G
   CGroup: /system.slice/elasticsearch.service
...

By default, the Elasticsearch service listens to port 9200. You can confirm this using the command below:

ss -pnltu | grep 9200
Output
tcp   LISTEN 0      128                     *:9200            *:*    users:(("java",pid=89913,fd=414))

3. Configure Elasticsearch on Rocky Linux 8

At this point, you can make some basic configuration changes.

Elasticsearch data is stored in the default directory location (/var/lib/elasticsearch). To edit the configuration files, you can find them in the directory location (/etc/elasticsearch). The Java start-up options can be configured in the (/etc/default/elasticsearch) configuration file.

If you want to set up a cluster, you need to modify the configuration file to allow remote connections.

By default, Elasticsearch listens on localhost. To change this, you need to open the configuration file with your favorite text editor, here we use vi:

sudo vi /etc/elasticsearch/elasticsearch.yml

Now find the network.host directive and uncomment it by removing the “#”.

You can replace it with your private IP address. Or you can change it to listen to all by entering 0.0.0.0:

network.host: 0.0.0.0

Also, uncomment the cluster.name attribute and specify your own cluster name:

cluster.name: my-application

Next, uncomment node.name:  and specify the name of your node:

node.name: node-1

Finally,  set the xpack.security.enabled security setting to false:

xpack.security.enabled: false

When you are done, save and close the file.

To apply the changes, restart Elasticsearch on Rocky Linux 8 with the following command:

sudo systemctl restart elasticsearch

4. Send an HTTP Request with Elasticsearch

At this point, you can verify your installation was successful by using the curl command to send an HTTP request to port 9200 on localhost:

curl -X GET "localhost:9200/"

In your output you will see:

Test Elasticsearch

You can use the curl command to use Elasticsearch.

5. Examples of Using Elasticsearch

Here are some examples of using Elasticsearch:

To delete an index, you can use the following command, here the name of the index is “sample”:

curl -X DELETE 'http://localhost:9200/samples'

You can list all indexes with:

curl -X GET 'http://localhost:9200/_cat/indices?v'

Also, you can list all docs in the index with the command below:

curl -X GET 'http://localhost:9200/sample/_search'

Conclusion

At this point, you have learned to Install and Configure Elasticsearch on Rocky Linux 8. Elasticsearch on Rocky Linux 8 is used for real-time search, analytics, and data storage. It helps in efficiently storing, searching, and analyzing large volumes of data.

Hope you enjoy it.

You may also like these articles:

Install and Configure Laravel on Rocky Linux 8

How To Install and Use Iptables on Rocky Linux 8

How To Install MysQL on Rocky Linux 9

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!