How to Install Elasticsearch on Rocky Linux 8

Elasticsearch is an Open source full-text search and analytics engine tool used to store, search, and analyze big volumes of data in near real time.

Installing Java

As Elasticsearch depends on Java and it has to be installed on system by using following command.

dnf install java-11-openjdk-devel

Verify the Java installation by following command.

java -version

Output:

[[email protected] ~]# java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode, sharing)
[[email protected] ~]#

Installing Elasticsearch

Run the following command to install GPG key for the Elasticsearch rpm packages.

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

Next, create a yum repository file for the Elasticsearch.

nano /etc/yum.repos.d/elasticsearch.repo

Add the following content.

[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

Save and exit,

After the repository is enabled, install the Elasticsearch package by using.

dnf install elasticsearch

Output:

[[email protected] ~]# dnf install elasticsearch
Elasticsearch repository for 7.x packages                                                                    24 MB/s |  25 MB     00:01
Last metadata expiration check: 0:00:13 ago on Thu 27 May 2021 05:23:44 PM EDT.
Dependencies resolved.
============================================================================================================================================
 Package                            Architecture                Version                        Repository                              Size
============================================================================================================================================
Installing:
 elasticsearch                      x86_64                      7.13.0-1                       elasticsearch-7.x                      312 M

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

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

Configure Elasticsearch

After installation is completed, edit Elasticsearch configuration file “/etc/elasticsearch/elasticsearch.yml” and set the network.host to localhost.

vim /etc/elasticsearch/elasticsearch.yml

Add the following content,

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

Save and exit,

Now enable and start the Elasticsearch service.

systemctl enable elasticsearch

systemctl start elasticsearch

Check the status of the service by using following command.

systemctl status elasticsearch

Output:

[[email protected] ~]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
     Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2021-05-27 17:26:14 EDT; 12min ago
         Docs: https://www.elastic.co
 Main PID: 82908 (java)
        Tasks: 55 (limit: 11394)
     Memory: 1.1G
     CGroup: /system.slice/elasticsearch.service
                     ├─82908 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.t>
                     └─83105 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

May 27 17:25:24 server systemd[1]: Starting Elasticsearch...
May 27 17:26:14 server systemd[1]: Started Elasticsearch.

Testing Elasticsearch

Run the following command to view the Elasticsearch server configuration and version details.

curl -X GET "localhost:9200/"

Output:

[[email protected] ~]# curl -X GET "localhost:9200/"
{
    "name" : "node-1",
    "cluster_name" : "Crowncloud-cluster",
    "cluster_uuid" : "G0GdHCQnRqe2ABCp9EMD3Q",
    "version" : {
        "number" : "7.13.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "5ca8591c6fcdb1260ce95b08a8e023559635c6f3",
        "build_date" : "2021-05-19T22:22:26.081971330Z",
        "build_snapshot" : false,
        "lucene_version" : "8.8.2",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
    },
    "tagline" : "You Know, for Search"
}