Site icon DesignLinux

How to Install Elasticsearch on Ubuntu 20.04

Elasticsearch is an open-source distributed full-text search and analytics engine. It supports RESTful operations and allows you to store, search, and analyze big volumes of data in real-time. Elasticsearch is one of the most popular search engines powering applications that have complex search requirements such as big e-commerce stores and analytic applications.

This guide explains how to install Elasticsearch on Ubuntu 20.04.

Installing Elasticsearch

Installing Elasticsearch on Ubuntu is fairly straightforward. We’ll enable the Docker repository, import the repository GPG key, and install Elasticsearch.

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

First, update the packages index and install the dependencies necessary 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 command above should output OK, which means that the key has been successfully imported, and packages from this repository will be considered trusted.

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

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 a previous version of Elasticsearch, change 7.x in the command above with the version you need.

Once the repository is enabled, install Elasticsearch by typing:

sudo apt updatesudo apt install elasticsearch

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

sudo systemctl enable --now elasticsearch.service

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

curl -X GET "localhost:9200/"

You should see something similar to 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. If you see curl: (7) Failed to connect to localhost port 9200: Connection refused, wait for 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.

Configuring Elasticsearch

Elasticsearch data is stored in the /var/lib/elasticsearch directory. Configuration files 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. If the client connecting to the database is also running on the same host and you are setting up a single node cluster, you don’t need to change the default configuration file.

Remote Access

Out of box 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 will need to configure your firewall and open TCP port 6379.

Typically, you would want to allow access to the Redis server only from a specific IP address or IP range. For example, to allow connections 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 listen for external connections.

To do so, open the elasticsearch.yml configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Search 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 you have multiple network interfaces on your machine, specify the interface IP address to force Elasticsearch to listen only to the given 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.

Conclusion

We’ve shown you how to install Elasticsearch on Ubuntu 20.04.

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

If you hit a problem or have feedback, leave a comment below.

java elasticsearch database ubuntu
Exit mobile version