Install Elasticsearch on Ubuntu 22.04

October 26, 2022 . 3 MIN READ

Introduction

Elasticsearch is a powerful platform designed for real-time distributed search and data analysis. It is widely used because of its flexibility, scalability, and advanced search capabilities. Many organizations rely on Elasticsearch to analyze logs, application data, and large datasets efficiently.

This guide explains how to install Elasticsearch, configure it for your environment, secure the installation, and start using it on an Ubuntu server.


Prerequisites

Before starting, ensure the following requirements are met:

  • A server running Ubuntu 22.04

  • At least 2 GB RAM and 2 CPU cores

  • A non-root user with sudo privileges

The hardware requirements for Elasticsearch depend on the amount of data or logs you plan to process. Larger workloads may require additional CPU, memory, and storage resources.


Step 1 — Install Elasticsearch

Elasticsearch packages are not included in the default Ubuntu repositories. Instead, they must be installed by adding the official Elastic package repository.

First, import the Elasticsearch GPG key to verify the authenticity of the packages:

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg –dearmor -o /usr/share/keyrings/elastic.gpg

Next, add the Elastic package repository:

echo “deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main” | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

Update the package list:

sudo apt update

Then install Elasticsearch:

sudo apt install elasticsearch

Once the installation is complete, Elasticsearch is ready for configuration.


Step 2 — Configure Elasticsearch

The main configuration file is located at:

/etc/elasticsearch/elasticsearch.yml

Open the file using a text editor:

sudo nano /etc/elasticsearch/elasticsearch.yml

This file uses YAML format, so it is important to keep proper indentation when editing.

For a basic single-server setup, modify the network host setting to restrict access to the local machine:

network.host: localhost

This ensures Elasticsearch only accepts connections from the local server, improving security.

After making changes, save the file and exit the editor.


Start and Enable Elasticsearch

Start the Elasticsearch service:

sudo systemctl start elasticsearch

Enable the service so it automatically starts during system boot:

sudo systemctl enable elasticsearch

Step 3 — Secure Elasticsearch

By default, Elasticsearch can be accessed through its HTTP API. If the service is exposed to external networks, unauthorized users could potentially read data or modify the cluster.

To limit access, configure the system firewall using UFW (Uncomplicated Firewall).

Allow a trusted host to connect to port 9200, which is Elasticsearch’s default API port:

sudo ufw allow from 198.51.100.0 to any port 9200

Enable the firewall:

sudo ufw enable

Check the firewall status:

sudo ufw status

If configured correctly, the firewall will allow access only from the specified IP address.


Step 4 — Test Elasticsearch

After installation, Elasticsearch should be running on port 9200.

You can verify the installation using a cURL request:

curl -X GET “http://localhost:9200”

If Elasticsearch is working correctly, the server will return a JSON response containing information about the cluster, node name, and version.

For a more detailed check, run:

curl -X GET “http://localhost:9200/_nodes?pretty”

This command displays detailed information about the cluster configuration, node settings, and modules.


Step 5 — Start Using Elasticsearch

Elasticsearch works through a RESTful API, supporting standard operations such as:

  • Create

  • Read

  • Update

  • Delete

These actions can be performed using HTTP requests.

Add Data

curl -X POST -H “Content-Type: application/json” \
“http://localhost:9200/tutorial/helloworld/1” \
-d ‘{ “message”: “Hello World!” }’

Retrieve Data

curl -X GET -H “Content-Type: application/json” \
“http://localhost:9200/tutorial/helloworld/1”

Update Data

curl -X PUT -H “Content-Type: application/json” \
“http://localhost:9200/tutorial/helloworld/1?pretty” \
-d ‘{
“message”: “Hello, People!”
}’

Adding the pretty parameter formats the output, making it easier to read.


Conclusion

You have successfully installed, configured, and tested Elasticsearch on an Ubuntu 22.04 server. You also learned how to secure the installation and perform basic data operations using the Elasticsearch API.

To explore advanced features such as indexing strategies, clustering, and search optimization, refer to the official Elasticsearch documentation.

Reference:

https://wiki.crowncloud.net/How_to_Install_Lets_Encrypt_SSL_Certificate_with_Nginx_on_Ubuntu_22_04 How_to_Install_Elasticsearch_on_Ubuntu_22_04#How+to+Install+Elasticsearch+on+Ubuntu+22.04

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-22-04

https://facsiaginsa.com/elastic/setup-elasticsearch-with-xpack-ssl

Leave a Reply

Your email address will not be published. Required fields are marked *