How to Install Elasticsearch on Debian 10

Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you to store, search, and analyze big volumes of data quickly and in near real time. Elasticsearch is an open source developed in Java and used by many big organizations around the world.

Install OpenJDK-11

First, update the packages index and install the OpenJDK-11 with following commands.

apt update

apt-get install openjdk-11-jre

After installation check the version of the JAVA.

java -version

Output:

root@vps:~# java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1deb10u1, mixed mode, sharing)

Install Elasticsearch

Install GnuPG2 Package by running the following command.

apt-get install gnupg2

Import GPG key for Elasticsearch packages.

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

Output:

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

Next, add the Elasticsearch repository to the system by following command.

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

After adding the repository to your system. Update cache and then install Elasticsearch packages on your system.

apt update 

apt install elasticsearch

After installing Elasticsearch package, Statr and enable the elasticsearch service with following command.

systemctl start elasticsearch.service

systemctl enable elasticsearch.service

Output:

root@vps:~# systemctl enable elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /lib/systemd/system/elasticsearch.service.

Configure Elasticsearch

Once the elasticsearch has been installed on your system, open the elasticsearch.yml configuration file.

vi /etc/elasticsearch/elasticsearch.yml 

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

Set the network host to 0.0.0.0 to listen on all interfaces and make it available publicly,

network.host: 0.0.0.0

Incase you want to configure this to be private/local to your machine. You will have to set the network.host to 127.0.0.1, so the content is not public.

Add discovery.type: single-node under the discovery section,

discovery.type: single-node

Save and exit the file once modified and restart the Elasticsearch service for the changes to take effect.

systemctl restart elasticsearch

Enter it into your browser's to the server hostname or IP addressed followed by port #9200

http://<your_server_IP>:9200

Output:

{
  "name" : "vps.server.com",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "JwprDKDKT5-1FhYgOqMswg",
  "version" : {
    "number" : "7.13.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "9a7758028e4ea59bcab41c12004603c5a7dd84a9",
    "build_date" : "2021-05-28T17:40:59.346932922Z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Done!