How to Install Elasticsearch on Debian 11

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 the following commands.

apt update

apt-get install openjdk-11-jre

After installation, check the version of JAVA.

java -version

Output:

[email protected]:~# java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, 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:

[email protected]:~# wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

Next, add the Elasticsearch repository to the system by the 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 the Elasticsearch package, Start and enable the elasticsearch service with the following command.

systemctl start elasticsearch.service

systemctl enable elasticsearch.service

Output:

[email protected]:~# 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

In case 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

If the firewall is enabled, then allow the port using the following command.

ufw allow 9200

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

http://<your_server_IP>:9200

Output:

{
  "name" : "server",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "yN1q0LdmSZyg_z_rGacNuw",
  "version" : {
    "number" : "7.14.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "dd5a0a2acaa2045ff9624f3729fc8a6f40835aa1",
    "build_date" : "2021-07-29T20:49:32.864135063Z",
    "build_snapshot" : false,
    "lucene_version" : "8.9.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Done.