Hamsa K
Editor
7 min read | 4 years ago

How to Install Elasticsearch on Ubuntu 20 04

Install and configure Elasticsearch in ubuntu 20.04

Elasticsearch is an Open Source full-text search and analytics engine tool used to store, search, and analyze big volumes of data in near real-time.Elastic search is freely available under Apache 2 license, which provides the most flexibility.

This article will guide you to install Elasticsearch on Ubuntu 20.04 LTS system.

prerequisites:

1) you need to be logged into your Ubuntu system with root user or any other user with sudo privileges

2) An Ubuntu 20.04 server with 4GB RAM and good cpu

3) Java 8 or higher version

Step 1: update packages

we will update the system and alsoinstall necessary dependency package to access repository over HTTPS. 

root@ubuntu20:~# apt update
root@ubuntu20:~# apt install apt-transport-https

Step 2: Install Java

If java is not installed in your system, you can install it with the following command.

sudo apt install openjdk-11-jdk

once java is installed check the version.

root@ubuntu20:~# java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

and make sure the JAVA_HOME environment variable is configured as below

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 

Step 3: Install elasticsearch

First we will import gpg key using wget command as shown below.

root@ubuntu20:~# wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

output should be ok, now key has been imported successfully.Next, add the Elasticsearch repository to the system with the following command.

For elasticsearch 7.x

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

For elasticsearch 6.x

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

At the time of writing this post, 7.x is latest version. if you want previous version you can install it with above command.Next update the repository and install elastcsearch.

root@ubuntu20:~# apt update
root@ubuntu20:~# apt install elasticsearch

Elasticsearch service will not start automatically after the installation.you can start it and enable the service for autostart on system boot.

root@ubuntu20:~# systemctl start elasticsearch
root@ubuntu20:~# systemctl enable elasticsearch

.if service was unable to start, then check below log file for any errors.

root@ubuntu20:~# tail -f /var/log/elasticsearch/elasticsearch.log
root@ubuntu20:~# systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/elasticsearch.service.d
             └─startup-timeout.conf
     Active: active (running) since Mon 2020-09-14 13:10:43 UTC; 11s ago
       Docs: https://www.elastic.co
   Main PID: 2491 (java)
      Tasks: 39 (limit: 3452)
     Memory: 1.2G
     CGroup: /system.slice/elasticsearch.service
             ├─2491 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch ->
             └─2655 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
Sep 14 13:08:31 ubuntu20 systemd[1]: Starting Elasticsearch...
Sep 14 13:10:43 ubuntu20 systemd[1]: Started Elasticsearch.

Step 5: Verify elasticsearch

You can verify the installation by running the following curl command.

curl -X GET "localhost:9200"

sample output:

root@ubuntu20:~# curl -X GET 'http://localhost:9200'
{
  "name" : "ubuntu20",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "7.9.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "083627f112ba94dffc1232e8b42b73492789ef91",
    "build_date" : "2020-09-01T21:22:21.964974Z",
    "build_snapshot" : false,
    "lucene_version" : "8.6.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Step 6: Configure Remote Access

By default, elasticsearch listens on localhost.If you need to allow remote access to the HTTP API, then configure the firewall to allow access to the default Elasticsearch HTTP API port 9200 for the trusted remote host. Then enable and check the firewall with following commands.

ufw allow from 198.168.0.30 to any port 9200
ufw enable
ufw status

Replace your remote server ip in above command.

Once the firewall is configured, then you need to edit Elasticsearch configuration file and allow Elasticsearch to listen for external connections.

nano /etc/elasticsearch/elasticsearch.yml

uncomment it and change network.host value as below and also your server is running with single node cluster, need to set value for discovery.seed_hosts as shown below.

network.host: 0.0.0.0
discovery.seed_hosts: ["127.0.0.1"]

save and exit file and restart elasticsearch service once.

root@ubuntu20:~# systemctl restart elasticsearch.service

That's it. you have successfully configured single node Elasticsearch cluster on Ubuntu system.



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy