How to install and configure Elasticsearch on Amazon Linux 2023
This guide walks you through installing Elasticsearch 8.12.x on Amazon Linux 2023 using the official Yum repository. You will configure the service for production use, set up a basic security policy, and verify the cluster is running.
This tutorial shows you how to install Elasticsearch 8.12.x on Amazon Linux 2023 using the official Yum repository. You will configure the service for production use, set up a basic security policy, and verify the cluster is running. These steps apply to a fresh server with root access and the standard Amazon Linux 2023 base packages.
Prerequisites
- Amazon Linux 2023 instance with root access.
- At least 4 GB of RAM available for the Java heap.
- Network access to yum.diy.com or the Amazon Linux package mirrors.
- Java Development Kit (JDK) 17 installed via Amazon Linux Extras or the official repository.
- Root privileges to install packages and manage services.
Step 1: Install Java 17 and system dependencies
Elasticsearch requires Java 17 to run. You must install the JDK before starting the main package installation. Use the Amazon Linux Extras repository to get the correct version compatible with the 8.x series.
yum install -y java-17-amazon-corretto-devel
Verify the Java installation by checking the version. You should see Java version 17.x.x.
java -version
Expected output:
openjdk version "17.0.10" 2024-04-16
OpenJDK Runtime Environment (build 17.0.10+7)
OpenJDK 64-Bit Server VM (build 17.0.10+7, mixed mode, sharing)
Step 2: Add the Elasticsearch GPG key and repository
You need to add the official Elasticsearch GPG key to verify package signatures. Then, add the Elasticsearch repository to your system so you can install the specific version.
yum install -y https://artifacts.elastic.co/GPG-KEY-elasticsearch
Add the repository file to the system. This points the package manager to the correct index.
yum install -y https://artifacts.elastic.co/packages/8.x/yum/elastic-8.x.repo
Update the package metadata to see the new packages available.
yum makecache
Step 3: Install Elasticsearch
Install the main Elasticsearch package using Yum. This will download the binary and the necessary configuration files.
yum install -y elasticsearch
Once the installation finishes, check the installed version to ensure you have the latest 8.x release.
yum list installed | grep elasticsearch
Expected output:
elasticsearch.x86_64 8.12.0 @elasticsearch
Step 4: Configure Elasticsearch for production
Edit the main configuration file to set the cluster name and disable the default single-node security check if you are not using a security-enabled cluster yet. You must define the node name and cluster settings.
vi /etc/elasticsearch/elasticsearch.yml
Add the following lines to the file to configure the cluster name, node name, and disable X-Pack security checks for this initial setup.
cluster.name: my-app-cluster
node.name: node-1
network.host: 0.0.0.0
discovery.type: single-node
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
Save and exit the editor. Restart the service to apply the changes.
systemctl restart elasticsearch
Step 5: Configure Java Heap Memory
Elasticsearch requires a specific amount of memory for the Java heap. You must set this in the JVM options file to prevent out-of-memory errors. Set the heap size to 512MB for a small instance or 1GB for larger workloads.
vi /etc/elasticsearch/jvm.options
Add the following lines to define the minimum and maximum heap size.
-Xms512m
-Xmx512m
Save and exit the editor. Restart the service again to apply the memory settings.
systemctl restart elasticsearch
Step 6: Verify the installation
Check if the Elasticsearch service is running and listening on the default port 9200. Use curl to query the root endpoint and verify the cluster health.
curl -s http://localhost:9200
Expected output:
{
"cluster_name" : "my-app-cluster",
"cluster_uuid" : "abc123...",
"version" : {
"number" : "8.12.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "abc123...",
"build_date" : "2024-01-01T00:00:00.000Z",
"build_snapshot" : false,
"lucene_version" : "9.10.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
Check the cluster health status to ensure all nodes are green.
curl -s http://localhost:9200/_cluster/health?pretty
Expected output:
{
"cluster_name" : "my-app-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
Troubleshooting
If the service fails to start, check the system logs for specific errors. Look for Java heap space errors or permission issues in the systemd journal.
journalctl -u elasticsearch -n 50
If you see a Java heap space error, ensure the JVM options file is correctly configured. Restart the service after making changes.
systemctl restart elasticsearch
If the service is stuck in a failed state, try clearing the cache and restarting. This forces Elasticsearch to re-read the configuration files.
systemctl daemon-reload
systemctl restart elasticsearch
Ensure the elasticsearch user exists and owns the data directory. If the user is missing, create it.
groupadd elasticsearch
useradd -g elasticsearch -m elasticsearch
Finally, verify that the port 9200 is open and accessible. If you are running behind a firewall, ensure the port is not blocked.