Carlos Sura

How to Install and Configure Elasticsearch on CentOS, RHEL & Rocky Linux

Deploying Elasticsearch on RHEL-based distributions (CentOS, RHEL, Rocky Linux, or AlmaLinux) for local log indexing, application search, or a single-node development stack takes only a few minutes when using the official Elastic RPM repository.

Below is the complete walkthrough covering GPG key import, repository setup, network binding, JVM heap sizing, and systemd service verification.


Import the Elastic GPG Key and Add the RPM Repository

First, import the official Elastic signing key and create /etc/yum.repos.d/elasticsearch.repo:

sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo vim /etc/yum.repos.d/elasticsearch.repo

Add the repository definition (use 7.x or 8.x depending on your target major release):

[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

Install the elasticsearch package using dnf (or yum):

sudo dnf install -y elasticsearch

Configure elasticsearch.yml for Single-Node / Local Binding

Open /etc/elasticsearch/elasticsearch.yml:

sudo vim /etc/elasticsearch/elasticsearch.yml

To ensure Elasticsearch listens only on the loopback interface (preventing unauthenticated external access) and boots cleanly without searching for external master-eligible nodes, set:

network.host: localhost
http.port: 9200
discovery.type: single-node

Tune JVM Heap Memory (jvm.options.d)

Elasticsearch defaults to dynamically sizing its JVM heap up to 50% of available RAM. On smaller servers or shared VMs, pin the minimum (-Xms) and maximum (-Xmx) heap sizes to identical values inside /etc/elasticsearch/jvm.options.d/heap.options:

cat << 'EOF' | sudo tee /etc/elasticsearch/jvm.options.d/heap.options
-Xms2g
-Xmx2g
EOF

Enable the Service and Verify Cluster Health

Reload systemd, enable Elasticsearch at boot, and start the daemon:

sudo systemctl daemon-reload
sudo systemctl enable --now elasticsearch.service

Test the local HTTP endpoint using curl:

curl -X GET "http://localhost:9200/?pretty"
curl -X GET "http://localhost:9200/_cluster/health?pretty"

Note for Elasticsearch 8.x: By default, Elasticsearch 8+ enables TLS and basic authentication out of the box. Use curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200 (or reset the elastic superuser password with /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic).