Site icon DesignLinux

How to Install Elasticsearch on Ubuntu 20.04

How to Install Elasticsearch on Ubuntu 20.04

Elasticsearch is a powerful open-source analytics and full-text search engine. It provides a distributed, multitenant-capable architecture which enables you to store, search and analyze large volumes of data faster. Elastic search is freely available under the Apache 2 license, which provides the most flexibility. In this tutorial we will show you how to install Elasticsearch on Ubuntu 20.04.

Install Elasticsearch on Ubuntu

First, you should login to your Ubuntu system using sudo privileged user or root account. Follow the below steps:

1. Installing Elasticsearch

The Elasticsearch package ships with a bundled version of OpenJDK, so you do not have to install Java.

At first, we will update the package index list and install necessary dependencies to add a new HTTPS repository:

sudo apt update
sudo apt install apt-transport-https ca-certificates wget

Import the repository’s public key using the following wget command:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

It should print OK as an output, that means the key has been successfully imported, and packages from this repository will be considered trusted.

Run the following command to add the Elasticsearch repository to the system:

sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'

Next, update the packages index and install the Elasticsearch engine:

sudo apt update
sudo apt install elasticsearch

After completion of the process, start, and enable the service:

sudo systemctl enable elasticsearch.service --now

3. Configuring Elasticsearch

Configuration files for Elasticsearch are located in /etc/elasticsearch and Java start-up options can be configured in the /etc/default/elasticsearch file.

By default, Elasticsearch is configured to listen on localhost only. There is no authentication layer in Elasticsearch, so it can be accessed by anyone who can access the HTTP API. If you want to allow remote access to your Elasticsearch server, you will need to configure your firewall and allow access to the Elasticsearch port 9200 only from trusted clients.

For instance, if your system has UFW and you want to allow connections only from 192.168.123.45, run the following command:

sudo ufw allow from 192.168.123.45 to any port 9200

Next, you have to edit the Elasticsearch configuration and allow Elasticsearch to listen for external connections.

Open the elasticsearch.yml configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Find the line that contains network.host, uncomment and change the value to 0.0.0.0:

network.host: 0.0.0.0

Restart the Elasticsearch service for the changes to take effect:

sudo systemctl restart elasticsearch

It’s done. You can now connect to the Elasticsearch server from the remote location.

4. Test Elasticsearch Setup

The Elasticsearch service is ready to use. You can test it using curl command-line utility. To verify, use curl to send an HTTP request to port 9200 on localhost:

curl -X GET "http://localhost:9200/?pretty"
{
  "name" : "tecnstuff",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "IJqDxPfXSrmFQ27KbXbRIg",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Conclusion

This tutorial shown you how to install Elasticsearch on Ubuntu 20.04. To get more details about Elasticsearch visit the official documentation page.

If you face any problem or having a feedback, feel free to leave a comment below.

Exit mobile version