AlmaLinuxLinuxTutorials

How To Install Elasticsearch on AlmaLinux 8

Install Elasticsearch on AlmaLinux 8

In this tutorial, we will show you how to install Elasticsearch on AlmaLinux 8. For those of you who didn’t know, 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. The search engine works very quickly, can be used to search large amounts of data (big data), and supports distributed architectures for high availability. Together with Kibana and Logstash, Elasticsearch forms the Elastic Stack.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Elasticsearch on an AlmaLinux 8. You can follow the same instructions for Rocky Linux.

Prerequisites

  • A server running one of the following operating systems: AlmaLinux 8 or Rocky Linux 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Elasticsearch on AlmaLinux 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf update
sudo dnf install epel-release
sudo dnf --enablerepo=epel group

Step 2. Installing Java.

Elasticsearch depends on Java and it has to be installed on the system by using the following command:

sudo dnf install java-11-openjdk-devel

Check the Java version once the installation is completed:

[root@idroot.us ~]# java -version
openjdk version "11.0.11" 2021-06-04 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)

Step 3. Installing Elasticsearch on AlmaLinux 8.

Now install the GPG key for the Elasticsearch rpm packages:

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

Then, create a yum repository file for the Elasticsearch:

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

Add the following line:

[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

Once is done, install the Elasticsearch package by using the following command below:

sudo dnf update
sudo dnf install elasticsearch

Step 4. Configure Elasticsearch.

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

nano /etc/elasticsearch/elasticsearch.yml

Add the following line:

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

Elasticsearch service will not start automatically after the installation process is complete. To start the service and enable the service to run:

sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

Step 5. Testing Elasticsearch.

Now everything is up and running on your system for ElasticSearch, it’s time to check whether it is working fine or not. So, to test it we use curl.

curl -X GET "localhost:9200/"

Output:

[root@vps ~]# curl -X GET "localhost:9200/"
{
  "name" : "node-1",
  "cluster_name" : "Idroot-Cluster",
  "cluster_uuid" : "5uoMXG0det2TETVNMeiUw",
  "version" : {
    "number" : "7.13.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "5ca8591c6fcdbgodet95b08a8e023559635c6f3",
    "build_date" : "2021-06-04T22:22:26.081971460Z",
    "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"
}

Step 6. How to Use ElasticSearch.

You can use the curl command to add data to the ElasticSearch:

curl -H 'Content-Type: application/json' -X POST 'http://localhost:9200/mytutorial/blog/1' -d '{ "message": "My first test!" }'

Output:

{"_index":"mytutorial","_type":"blog","_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/mytutorial/blog/1'

Output:

{"_index":"mytutorial","_type":"blog","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{ "message": "My first test!" }}

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

curl -X GET 'http://localhost:9200/mytutorial/blog/1?pretty'

Output:

{
  "_index" : "mytutorial",
  "_type" : "blog",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "message" : "My first test!"
  }
}

Congratulations! You have successfully installed Elasticsearch. Thanks for using this tutorial for installing the Elasticsearch on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official Elasticsearch website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button