How To Install Elasticsearch on Rocky Linux 8

In this guide, we want to teach you How To Install and Configure 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.

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.

Install Java on Rocky Linux 8

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

sudo dnf update

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)

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
Output
Name        : elasticsearch
Epoch       : 0
Version     : 8.5.0
Release     : 1
Architecture: x86_64
Install Date: Tue 08 Nov 2022 04:59:30 AM EST
Group       : Application/Internet
Size        : 1193406199
License     : Elastic License
Signature   : RSA/SHA512, Mon 24 Oct 2022 03:33:40 PM EDT, Key ID d27d666cd88e42b4
Source RPM  : elasticsearch-8.5.0-1-src.rpm
Build Date  : Mon 24 Oct 2022 01:02:41 PM EDT
Build Host  : packer-virtualbox-iso-1646848364
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

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))

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

Test Elasticsearch

At this point, you can verify your installation that 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:

Output
{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "OHcyCxt0TAmMxQX8JrLESg",
  "version" : {
    "number" : "8.5.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "c94b4700cda13820dad5aa74fae6db185ca5c304",
    "build_date" : "2022-10-24T16:54:16.433628434Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.1",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

You can use the curl command to use 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.

Hope you enjoy it.

You may be 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

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!
Latest Articles

POPULAR TAGS

Most Popular