Elasticsearch is an open source full-text search and analysis engine. It supports RESTful operations, and allows you to store, search, and analyze large amounts of data in real time. Elasticsearch is one of the most popular search engines that can power applications with complex search requirements, such as large e-commerce stores and analytics applications.
This guide explains how to install Elasticsearch on Ubuntu 20.04.
Installing Elasticsearch on Ubuntu is very straightforward. We will enable the Docker software source, import the GPG key, and install Elasticsearch.
The Elasticsearch package is packaged with OpenJDK, so you don't need to install Java.
First, update the package index and install the necessary dependent packages to add a new Https software source:
sudo apt update
sudo apt install apt-transport-https ca-certificates wget
Import the GPG key of the software source:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
The above command should output OK
, which means that the key has been successfully imported and the package of this software source is also considered to be trusted.
Next, add Elasticsearch software source to the system, enter:
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 the previous version of Elasticsearch, change the`7.x`Replace with the version you need.
Once the software source is enabled, enter the following command to install Elasticsearch:
sudo apt update
sudo apt install elasticsearch
The Elasticsearch service will not start automatically after the installation is complete. Want to start the service and enable startup:
sudo systemctl enable --now elasticsearch.service
To verify that Elasticsearch is running, use curl
to send an HTTP request to port 9200
:
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 will take 5-10 seconds to start the service. If you see curl: (7) Failed to connect to localhost port 9200: Connection refused
, please wait a few seconds and try again.
To view the messages recorded by the Elasticsearch service, use the following command:
sudo journalctl -u elasticsearch
that's it. Elasticsearch has been installed on your Ubuntu machine.
Elasticsearch data is stored in the /var/lib/elasticsearch
directory. The configuration file is located in /etc/elasticsearch
and the Java startup options can be configured via the /etc/default/elasticsearch
file.
By default, Elasticsearch is configured to only listen on localhost. If the client connecting to the database is also on this machine, you can set up a simple node cluster without modifying the default configuration file.
Elasticsearch, available out of the box, does not implement authorization, so it can be accessed by anyone through HTTP API.
To allow remote access to your Elasticsearch server, you will need to configure your firewall and open TCP port 6379.
Normally, you will only allow access to the server from a specified IP or specified IP range. For example, to only allow access from the 192.168.121.0/24
subnet, you would allow the following command:
sudo ufw allow proto tcp from192.168.121.0/24 to any port 6379
Once the firewall is configured, the next step is to edit the Elasticsearch configuration file and allow Elasticsearch to listen for other connections.
To do this, open the elasticsearch.yml
configuration file:
sudo nano /etc/elasticsearch/elasticsearch.yml
Search for the line that includes network.host
, uncomment it, and modify the value to 0.0.0.0
:
network.host:0.0.0.0
If there are many network interfaces on your machine, specify the interface IP address to force Elasticsearch to only listen on the specified interface.
Restart the Elasticsearch service to make the application take effect:
sudo systemctl restart elasticsearch
that's it! , Now you can connect to the Elasticsearch server from your remote location.
We have shown you how to install Elasticsearch on Ubuntu 20.04.
To learn more about Elasticsearch, please Browse the official documentation page.
Recommended Posts