How to install Elasticsearch on Ubuntu 20.04

s2 0

Elasticsearch is an open source, distributed full-text search and analysis engine. It supports RESTful operations and enables you to store, search, and analyze large amounts of data in real time. Elasticsearch is one of the most popular search engines powering applications with complex search needs such as large e-commerce stores and bing applications.

This guide explains how to install Elasticsearch on Ubuntu 20.04.

Install Elasticsearch

Installing Elasticsearch on Ubuntu is pretty straightforward. We activate the Elasticsearch repository, import the repository GPG key and install the Elasticsearch server.

The Elasticsearch package comes with a bundled version of OpenJDK so you don’t have to install Java.

First, update the package index and install the dependencies required to add a new HTTPS repository:

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

Import the repository’s GPG key:

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

The above command should print OKwhich means the key was successfully imported and packages from this repository are trusted.

Next, add the Elasticsearch repository to the system by running:

sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
If you want to install an earlier version of Elasticsearch, change 7.x in the command above with the required version.

Once the repository is enabled, install Elasticsearch by typing:

sudo apt updatesudo apt install elasticsearch

The Elasticsearch service does not start automatically after the installation process is complete. To start the service and enable the service to run:

sudo systemctl enable --now elasticsearch.service

To check if Elasticsearch is running, use curl
to send an HTTP request to port 9200 on localhost:

curl -X GET "localhost:9200/"

You should see something like this:

{
  "name" : "vagrant",
  "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"
}

It may take 5-10 seconds for the service to start. When you see curl: (7) Failed to connect to localhost port 9200: Connection refused, wait a few seconds and try again.

To view the messages logged by the Elasticsearch service, use the following command:

sudo journalctl -u elasticsearch

That’s it. Elasticsearch has been installed on your Ubuntu server.

Configure Elasticsearch

Elasticsearch data is stored in /var/lib/elasticsearch Directory. Configuration files are located in /etc/elasticsearch and Java startup options can be found in /etc/default/elasticsearch File.

By default, Elasticsearch is configured to only listen on localhost. If the client that connects to the database is also running on the same host and you are setting up a single node cluster, you do not need to change the default configuration file.

Remote access

By default, Elasticsearch does not implement authentication, so it can be accessed by anyone who can access the HTTP API.

To allow remote access to your Elasticsearch server, you need to configure your firewall and open TCP port 6379.

Typically, you want to allow access to the Redis server only from a specific IP address or range. For example, to connect only from the 192.168.121.0/24 subnet, you would run the following command:

sudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379

Once the firewall is configured, the next step is to edit the Elasticsearch configuration and allow Elasticsearch to wait for external connections.

To do this, open the elasticsearch.yml Configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Look for the line that contains network.host, uncomment it and change the value to 0.0.0.0:

/etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0

If your computer has multiple network interfaces, provide the IP address of the interface to force Elasticsearch to only listen on the specified interface.

Restart the Elasticsearch service for the changes to take effect:

sudo systemctl restart elasticsearch

That’s it. You can now connect to the Elasticsearch server from your remote location.

diploma

We showed you how to install Elasticsearch on Ubuntu 20.04.

To learn more about Elasticsearch, visit the official documentation
Page.

If you run into any problem or have any feedback, please leave a comment below.