UbuntuUbuntu Based

How To Install Elasticsearch on Ubuntu 24.04 LTS

Install Elasticsearch on Ubuntu 24.04

Installing Elasticsearch on Ubuntu 24.04 LTS is a straightforward process that unlocks the potential of your data through powerful search and analytics capabilities. Elasticsearch, known for its scalability and speed, is an ideal choice for businesses seeking real-time data analysis and search functionality. This comprehensive guide provides step-by-step instructions to effectively install and configure Elasticsearch on your Ubuntu system, ensuring a successful deployment that adheres to best practices in setup and security.

Understanding Elasticsearch

Elasticsearch is a distributed, RESTful search and analytics engine built on Apache Lucene that enables the storage, searching, and analysis of large volumes of data quickly and in near real-time. Its high performance and scalability make it suitable for various use cases, including log and event data analysis, full-text search, and business analytics.

Core Functionalities

  1. Full-Text Search: Elasticsearch excels in high-performance full-text search, matching queries against documents in a distributed manner for quick results.
  2. Autocomplete and Suggestions: It provides suggestions as users type their queries, enhancing search interactivity.
  3. Real-Time Data Analytics: Elasticsearch enables real-time data analysis and visualization for prompt decision-making.
  4. Powerful APIs: With REST APIs, Elasticsearch integrates with various programming languages and frameworks, enhancing extensibility.

Prerequisites

Before installing Elasticsearch, ensure your Ubuntu 24.04 LTS system meets the following requirements:

  • RAM: A minimum of 4 GB of RAM is recommended for optimal performance.
  • Disk Space: At least 20 GB of available disk space.
  • CPU: A multi-core processor is recommended.
  • Sudo Privileges: Ensure you have sudo privileges to install packages and execute commands requiring administrative access.

Updating Your System

To begin, update your system packages to their latest versions:

sudo apt update && sudo apt upgrade -y

Installing Java

Elasticsearch requires Java, so install OpenJDK 17 using the following command:

sudo apt install openjdk-17-jdk -y

Verify the Java installation by checking the version:

java -version

If you encounter issues during installation, ensure your package lists are updated and consider re-running the installation command.

Adding Elasticsearch Repository

To install Elasticsearch, add the official Elasticsearch APT repository to your system:

  1. Install the prerequisite packages for adding the repository, including GnuPG:

sudo apt install wget gnupg2 -y

  1. Import the GPG key for the Elasticsearch APT repository to ensure package authenticity:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

  1. Add the Elasticsearch repository to your system:

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

  1. Update your package lists to include the newly added repository:

sudo apt update

This critical step allows you to install Elasticsearch from the official source, ensuring access to the latest features and security updates.

Installing Elasticsearch

With the repository added, install the Elasticsearch package:

sudo apt install elasticsearch -y

After installation, verify that Elasticsearch is running correctly by checking its status:

sudo systemctl status elasticsearch

If the service is not running, start it manually:

sudo systemctl start elasticsearch

Enable Elasticsearch to start automatically on system boot:

sudo systemctl enable elasticsearch

If you encounter errors during installation, check the logs at /var/log/elasticsearch/elasticsearch.log for detailed error messages.

Configuring Elasticsearch

Proper configuration ensures optimal performance and security. The primary configuration file for Elasticsearch is located at /etc/elasticsearch/elasticsearch.yml.

  1. Open the configuration file using a text editor:

sudo nano /etc/elasticsearch/elasticsearch.yml

  1. To allow remote access, bind Elasticsearch to the network interface by editing the following setting:

network.host: 0.0.0.0

Be cautious with this setting in production environments; consider binding it to a specific IP address.

Configure the Java Virtual Machine (JVM) heap size for optimal performance. This can be set in the same elasticsearch.yml file or in the JDK options file located at /etc/elasticsearch/jvm.options. Specify the heap size by adjusting:

-Xms2g
-Xmx2g

Setting both values to the same size ensures consistent performance.

After making changes, restart the Elasticsearch service to apply the configurations:

sudo systemctl restart elasticsearch

Securing Elasticsearch

Securing your Elasticsearch installation is vital, especially if it is accessible to the internet. Here are some essential security measures:

  1. Install and configure UFW (Uncomplicated Firewall) to allow traffic to Elasticsearch on port 9200:

sudo apt install ufw -y
sudo ufw allow 9200/tcp
sudo ufw enable

  1. Enable built-in security features in Elasticsearch by modifying the elasticsearch.yml configuration file:

xpack.security.enabled: true

Restart Elasticsearch to apply the changes:

sudo systemctl restart elasticsearch

  1. Set up users and assign roles using the following command:

sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

This will guide you through setting passwords for the built-in users.

Testing Elasticsearch

Test your Elasticsearch installation to ensure it is operational and ready for use:

  1. Perform a health check:

curl -X GET "localhost:9200/_cluster/health?pretty"

Look for "status" : "green", indicating a healthy cluster.

  1. Create a sample index:

curl -X PUT "localhost:9200/test_index"

  1. Insert a document into the index:

curl -X POST "localhost:9200/test_index/_doc/1" -H 'Content-Type: application/json' -d '{"name":"Sample Document","description":"This is a test document."}'

  1. Retrieve the document to confirm successful insertion:

curl -X GET "localhost:9200/test_index/_doc/1"

If you encounter issues while testing, check the Elasticsearch logs at /var/log/elasticsearch/elasticsearch.log for error messages and confirm your network settings allow communication with Elasticsearch on the specified ports.

Congratulations! You have successfully installed Elasticsearch. Thanks for using this tutorial for installing the Elasticsearch on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Elasticsearch website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button