Theme editor

Guide Linux How to Install and Configure Elasticsearch 9.x on Ubuntu & Debian

  • Thread starter Thread starter CL4Y
  • Start date Start date
  • Views 186

CL4Y

Keyboard Ninja
Administrator
Thread owner

How to Install and Configure Elasticsearch 9.x on Ubuntu & Debian

Elasticsearch is a powerful, open-source search and analytics engine. While incredibly robust, the initial installation on a Debian-based system like Ubuntu requires a few specific configuration steps to get a single node up and running.
This guide will walk you through the entire process, from adding the repository to configuring your node for a development environment.



1. 🔑 Add the Elastic GPG Key​

First, you must add the Elastic GPG key to your system. This allows apt to verify the authenticity of the packages you're about to download, ensuring they haven't been tampered with.
Bash:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

jetto-elasticsearch-install-1.gif




2. 📦 Add the Elasticsearch APT Repository​

With the key in place, you now need to tell your system where to find the Elasticsearch packages. We will add the official Elastic repository for version 9.x.

This command creates a new source list file for apt:
Bash:
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-9.x.list

jetto-elasticsearch-install-2.gif




3. 💻 Install Elasticsearch​

Now you are ready to install. Update your package lists to include the new repository, and then install the elasticsearch package itself.

Bash:
sudo apt-get -y update && sudo apt-get -y install elasticsearch
After the installation finishes, the Elasticsearch service will be installed, but it will likely fail to start. This is normal, as we still need to configure it.

jetto-elasticsearch-install-3.gif




4. 📝 Configure the Elasticsearch Node​

This is the most critical step. We need to edit the main configuration file to tell Elasticsearch to run as a single node and to disable security features (for development/testing only).

Open the configuration file:
Bash:
sudo nano /etc/elasticsearch/elasticsearch.yml

Now, find and modify the following lines. You will need to uncomment (remove the #) some of them.
YAML:
# 1. Bind to localhost
# This is crucial for a single-node setup on a machine not exposed to the public.
network.host: localhost

# 2. Disable security (FOR DEVELOPMENT ONLY)
# WARNING: This disables all authentication and encryption.
# Do NOT use this configuration in a production environment.
xpack.security.enabled: false
xpack.security.http.ssl: false
xpack.security.transport.ssl: false

# 3. Set the initial master node
# For a single-node cluster, you must comment out this line
# to bypass the cluster bootstrap checks.
# cluster.initial_master_nodes: ["node-1", "node-2"]
Save the file and exit the editor.

jetto-elasticsearch-install-4.gif




5. 🚀 Adjust the JVM Heap Size (Optional but Recommended)​

By default, Elasticsearch's Java Virtual Machine (JVM) heap size can be small. For any real use, you'll want to increase it. The recommended practice is to create a custom override file.
  1. Navigate to the jvm.options.d directory. This is the correct place for custom settings:
    Bash:
    cd /etc/elasticsearch/jvm.options.d/
  2. Create a new file to set your custom heap size. We'll call it jvm.options:
    Bash:
    sudo nano jvm.options
  3. Add your minimum (-Xms) and maximum (-Xmx) heap settings. Using 4g (minimum) and 6g (maximum) as an example:
    Bash:
    -Xms4g
    -Xmx6g
    Pro-Tip: For production servers, it's best practice to set the minimum and maximum heap size to the same value (e.g., -Xms4g and -Xmx4g) to prevent performance issues from heap resizing.
Save and exit the file.

jetto-elasticsearch-install-5.gif




6. ✅ Start and Enable the Elasticsearch Service​

Now that all configurations are in place, you can start the service.
  1. Reload the systemd manager to pick up any changes:
    Bash:
    sudo systemctl daemon-reload
  2. Enable the service to start automatically on boot:
    Bash:
    sudo systemctl enable elasticsearch.service
  3. Start the service:
    Bash:
    sudo systemctl start elasticsearch.service
jetto-elasticsearch-install-6.gif




7. 🔎 Verify the Installation​

Wait about 30 seconds for the service to initialize, and then check its status:
Bash:
sudo systemctl status elasticsearch.service

If everything is correct, you should see an active (running) status.
You can also test the node by sending a request to it:

Bash:
curl -X GET "localhost:9200"
If successful, Elasticsearch will return a JSON response with your cluster and node information.

jetto-elasticsearch-install-7.gif
 
Last edited:
Back
Top