How to Install Elasticsearch 9 on AlmaLinux 9 or Rocky Linux 9
Install a single Elasticsearch 9 node on AlmaLinux 9 or Rocky Linux 9 from Elastic's RPM repository, verify it over HTTPS and tune the basics.
This guide installs a single Elasticsearch 9 node on AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9 from Elastic's own RPM repository. At the end the service starts at boot, answers over HTTPS with password authentication, and you have indexed and searched a test document. Only Elasticsearch is covered here; Kibana and Logstash are not needed to run it.
CentOS 7 reached end of life on 30 June 2024, and two things that older tutorials do are now wrong: you no longer install Java separately, because the package bundles its own JDK, and curl http://localhost:9200/ no longer works, because security with TLS is switched on automatically during installation.
Requirements
- A 64-bit AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9 server and a user with
sudorights. - Memory: Elasticsearch sizes its heap from the RAM it finds and uses the rest for the filesystem cache. Treat 4 GB as a comfortable minimum for anything beyond a test.
- Disk space on
/var/lib/elasticsearchfor your indices.
Step 1: Add the Elastic repository
Import the key Elastic signs its packages with:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Create the repository definition:
sudo tee /etc/yum.repos.d/elasticsearch.repo > /dev/null <<'EOF'
[elasticsearch]
name=Elasticsearch repository for 9.x packages
baseurl=https://artifacts.elastic.co/packages/9.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
type=rpm-md
EOF
The repository is disabled by default (enabled=0) on purpose: a routine dnf upgrade will not move a running search node to a new version behind your back. You enable it explicitly for the commands that should use it.
Step 2: Install Elasticsearch
sudo dnf install --enablerepo=elasticsearch elasticsearch
Read the end of the installation output before you clear the screen. The package configures security for a new single-node cluster and prints the generated password of the built-in elastic superuser. It is shown only once; store it in your password manager. The same step creates TLS certificates in /etc/elasticsearch/certs and writes the matching settings to /etc/elasticsearch/elasticsearch.yml.
The package also installs these locations:
| Purpose | Path |
|---|---|
| Configuration | /etc/elasticsearch/elasticsearch.yml |
| JVM options | /etc/elasticsearch/jvm.options.d/ |
| Environment variables for the service | /etc/sysconfig/elasticsearch |
| Data | /var/lib/elasticsearch |
| Logs | /var/log/elasticsearch |
| Program files, tools and bundled JDK | /usr/share/elasticsearch |
Step 3: Start the service
The package neither starts Elasticsearch nor enables it at boot. Do both:
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
The first start can take a minute. Check the result:
sudo systemctl status elasticsearch.service --no-pager
Step 4: Verify the node
Query the node over HTTPS, trusting the certificate authority that was generated for it. curl asks for the elastic password:
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
A JSON document with the node name, the cluster name elasticsearch and the version number confirms that the node is running. A request to http:// instead of https:// fails.
If you did not save the password, generate a new one:
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
Step 5: Index and search a test document
Store one document in a new index named notes:
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic \
-X POST "https://localhost:9200/notes/_doc?refresh=true&pretty" \
-H 'Content-Type: application/json' \
-d '{"title": "First note", "body": "Elasticsearch is running on this server"}'
Search for a word from it:
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic \
"https://localhost:9200/notes/_search?q=body:running&pretty"
The response lists one hit. Remove the test index when you are done:
sudo curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic \
-X DELETE "https://localhost:9200/notes?pretty"
Step 6: Adjust the configuration
Edit /etc/elasticsearch/elasticsearch.yml for cluster-level settings and restart the service afterwards.
Cluster and node name
The default cluster name is elasticsearch and the node name defaults to the host name. Give the cluster a name of its own so that a second installation on your network can never be confused with it:
cluster.name: search-prod
node.name: es-node-1
Heap size
By default Elasticsearch chooses the JVM heap size from the node's roles and total memory, and Elastic recommends keeping that default. If the server also runs other software and you must cap the heap, create a file ending in .options with identical minimum and maximum values, at most half of the RAM:
sudo tee /etc/elasticsearch/jvm.options.d/heap.options > /dev/null <<'EOF'
-Xms2g
-Xmx2g
EOF
sudo systemctl restart elasticsearch.service
Access from another server
Port 9200 is closed in firewalld by default, so only local clients can connect. If an application server needs the API, allow exactly that address rather than opening the port to everyone:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="198.51.100.20" port port="9200" protocol="tcp" accept'
sudo firewall-cmd --reload
Copy /etc/elasticsearch/certs/http_ca.crt to the client and configure it to trust that CA. Create a dedicated user or API key with only the privileges the application needs instead of giving it the elastic superuser.
The transport port 9300, used between cluster nodes, stays bound to the local host on a single-node installation. Leave it that way unless you are deliberately building a multi-node cluster.
Updates and logs
Upgrade within the 9.x series by enabling the repository for one command, then restart the service yourself. The package does not restart Elasticsearch after an upgrade unless you set RESTART_ON_UPGRADE in /etc/sysconfig/elasticsearch:
sudo dnf upgrade --enablerepo=elasticsearch elasticsearch
sudo systemctl restart elasticsearch.service
When the service does not start, the reason is in the cluster log, which is named after the cluster:
sudo tail -n 50 /var/log/elasticsearch/elasticsearch.log
sudo journalctl -u elasticsearch.service --no-pager -n 50
Typical causes are a YAML indentation error in elasticsearch.yml, a heap setting larger than the available memory, and data or log directories that are no longer owned by the elasticsearch user after a manual copy.
Frequently asked questions
Do I need to install Java first?
No. The RPM ships a bundled JDK under /usr/share/elasticsearch/jdk and uses it automatically. A system Java is only used if you point ES_JAVA_HOME at it in /etc/sysconfig/elasticsearch, which is rarely a good idea.
Can I turn off TLS and passwords for local development?
The security settings are in elasticsearch.yml and can be changed, but an unauthenticated node is one firewall mistake away from exposing all its data. Keeping security on costs one --cacert option and a password, and every official client supports both.
How do I connect Kibana later?
Install Kibana from the same repository and generate an enrollment token on the Elasticsearch node with sudo /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana. The token is valid for 30 minutes and is pasted into Kibana's setup screen.
Is one node enough for production?
One node works, but it has no redundancy: replica shards cannot be allocated, so indices with replicas show a yellow health status, and a disk failure loses everything since the last snapshot. Configure a snapshot repository and regular snapshots, or run at least three nodes when the data matters.