how to install elasticsearch on almalinux

How to Install and Configure Elasticsearch on AlmaLinux

Elasticsearch is an open-source search engine built on the Apache Lucene library. Elasticsearch was initially released in 2010 and has become the most popular search engine application ever since. People use Elasticsearch for log analytics, full-text search, operational use cases, etc.

Magento, as a well-known e-commerce application also uses Elasticsearch as its search engine. In this tutorial, we will show you how to install and configure Elasticsearch on AlmaLinux.

Prerequisites

  • An AlmaLinux VPS with at least 8GB of RAM
  • root SSH access or a regular user with sudo privileges

Step 1: Log in to your server via SSH

First, you will need to log in to your AlmaLinux 8 VPS via SSH as the root user:

ssh root@IP_Address -p Port_number

You will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.

You can check whether you have the proper AlmaLinux version installed on your server with the following command:

# cat /etc/almalinux-release

It will return an output like this.

AlmaLinux release 9.1 (Lime Lynx)

In this article, we are using ‘root’ to execute the shell commands. If you want to use your regular user with sudo privileges to run the commands, make sure to append ‘sudo’ in front of the commands.

Step 2: Update the system

Before starting, you have to make sure that all AlmaLinux OS packages installed on the server are up to date. You can do this by running the following commands:

# yum update
# yum upgrade

Step 3. Install Java

Elasticsearch is based on Java, so we need to install it first. We can simply run this command below to install it from the default repository.

# yum install java-11-openjdk java-11-openjdk-devel

Let’s check java version

# java --version

It will show you an output similar to this:

openjdk 11.0.18 2023-01-17 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.18.0.10-2.el9_1) (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.18.0.10-2.el9_1) (build 11.0.18+10-LTS, mixed mode, sharing)

Step 4. Add repository

In this step, we are going to add the Elasticsearch repository and then install it from the repository. But, there is an issue with importing the Elastic key on AlmaLinux 9, and it is expected for a workaround, you can invoke this command:

# update-crypto-policies --set LEGACY

then reboot the server

Next, create a file called elasticsearch.repo in the /etc/yum.repos.d/ directory

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

Paste the following content into that 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=1
autorefresh=1
type=rpm-md

Save the file, then exit from the editor. Next, let’s update the packages to the latest available version.

# yum update
# yum makecache

Step 5. Install Elasticsearch

Elasticsearch is a memory-intensive application. It requires at least 8GB of RAM to run properly. And in this step, we are going to install it using the repository we added earlier in the previous step. Let’s proceed with the installation.

# yum install elasticsearch

Once installed, the elasticsearch service is not automatically running; let’s execute this command below to run Elasticsearch and enable the service.

# systemctl enable --now elasticsearch

That’s it; Elasticsearch should be up and running now we can verify it by running this command.

# systemctl status elasticsearch

The command will show you an output like this:

[root@almalinux ~]# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2023-03-10 17:30:37 WIB; 54s ago
Docs: https://www.elastic.co
Main PID: 1813 (java)
Tasks: 90 (limit: 10907)
Memory: 1.2G
CPU: 57.850s
CGroup: /system.slice/elasticsearch.service
├─1813 /usr/share/elasticsearch/jdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=/usr/share/elasticsearch/bin/elasticsearch -Dcli.libs=lib/too>
├─1872 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manager=allow -XX:+AlwaysPreTouch>
└─1893 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Mar 10 17:30:08 almalinux.rosehosting.com systemd[1]: Starting Elasticsearch...
Mar 10 17:30:37 almalinux.rosehosting.com systemd[1]: Started Elasticsearch.

Step 6. Configure Elasticsearch

Elasticsearch has three main configuration files, and you can find them in /etc/elasticsearch directory.

  • elasticsearch.yml for configuring Elasticsearch itself
  • jvm.options for configuring Elasticsearch JVM settings
  • log4j2.properties for configuring Elasticsearch logging

In this step, we are going to modify the elasticsearch.yml file, and the configuration file uses YAML format.

For example, we can edit the listening IP address. By default, Elasticsearch is only accessible on localhost. We can set a different address to expose our Elasticsearch node on the network:

# nano /etc/elasticsearch/elasticsearch.yml

Find this line

#network.host: 192.168.0.1

Uncomment it and modify the IP address. Let’s change it to 0.0.0.0.

network.host: 0.0.0.0

We can also modify the port, it is port 9200 by default, and we can change it to any port we like.

#http.port: 9200

Uncomment and modify the port like this:

http.port: 9222

Save the file, then exit from the editor. Next, restart elasticsearch service.

# systemctl restart elasticsearch

Please note that Elasticsearch uses two ports to listen to external TCP traffic. Port 9200 is used for all API calls over HTTP. This includes search and aggregations and anything else that uses an HTTP request. Port 9300 is a custom binary protocol used for communications between nodes in a cluster.

Congratulations! You have successfully installed Elasticsearch on AlmaLinux 9.

If you are one of our web hosting customers and use our managed Linux Hosting, you don’t have to follow this tutorial and install Elasticsearch on AlmaLinux 9 yourself, our Linux admins will set up and configure an Elasticsearch VPS for you. They are available 24×7 and will take care of your request immediately, and all you need to do is to submit a ticket. We can also help you configure the more complex setup, like configuring Elasticsearch on your Magento website.

PS. If you liked this post, please share it with your friends on social networks or simply leave a reply below. Thanks.

2 thoughts on “How to Install and Configure Elasticsearch on AlmaLinux

Leave a Reply

Your email address will not be published. Required fields are marked *