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

> Step-by-step guide to installing Elasticsearch on CentOS, RHEL, and Rocky Linux via RPM, configuring network binding, JVM heap size, and systemd.

- Canonical URL: <https://carlossura.com/blog/install-elasticsearch-centos/>
- Author: Carlos Sura
- Published: 2020-05-02
- Updated: 2026-10-20
- Tags: linux, centos, elasticsearch, rhel, devops

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`:

```bash
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):

```ini
[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`):

```bash
sudo dnf install -y elasticsearch
```

---

## Configure `elasticsearch.yml` for Single-Node / Local Binding

Open `/etc/elasticsearch/elasticsearch.yml`:

```bash
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:

```yaml
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`:

```bash
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:

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

Test the local HTTP endpoint using `curl`:

```bash
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`).
