How to install ElasticSearch 7 and 8 on Debian

Post Reply
User avatar
isscbta
Team Member
Posts: 130
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 15 times
Been thanked: 3 times

Elasticsearch is a free and open-source distributed search and analytics engine that can handle all types of data, including text, numerical, geospatial, structured, and unstructured. It was developed based on Apache Lucene and was first introduced in 2010 by Elasticsearch N.V., now known as Elastic. With its user-friendly REST APIs, distributed architecture, speed, and scalability, Elasticsearch is the backbone of the Elastic Stack, a collection of open-source tools for data ingestion, enrichment, storage, analysis, and visualization. The Elastic Stack is commonly referred to as the ELK Stack (Elasticsearch, Logstash, and Kibana) and now includes a suite of lightweight data shippers called Beats for sending data to Elasticsearch.

In the following steps, we will guide you through the installation process of ElasticSearch 7 on a Debian server.

In your SSH, as root, run:

Code: Select all

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
apt-get update
apt-get install elasticsearch

# Now let's optionally limit ElasticSearch RAM usage to 2 GB :
echo "" >> /etc/elasticsearch/jvm.options
echo "-Xms2g" >> /etc/elasticsearch/jvm.options
echo "-Xmx2g" >> /etc/elasticsearch/jvm.options

systemctl enable elasticsearch.service
systemctl start elasticsearch.service
systemctl status elasticsearch.service

# Test it:
curl -X GET "http://localhost:9200/?pretty"
If you want to bind public IPv4:

Code: Select all

echo "-Djava.net.preferIPv4Stack=true" >> /etc/elasticsearch/jvm.options
echo "" >> /etc/elasticsearch/elasticsearch.yml
echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml
echo "cluster.initial_master_nodes: node-1" >> /etc/elasticsearch/elasticsearch.yml
systemctl restart elasticsearch.service
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

In the following steps, we will guide you through the installation process of ElasticSearch 8 on a Debian server.

In your SSH, as root, run:

Code: Select all

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
apt-get install apt-transport-https
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
apt-get update
apt-get install elasticsearch
Output will be something like:
--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : YOUR-ES-TOKEN-IS-HERE
...
Now let's optionally limit ElasticSearch RAM usage to 2 GB :

Code: Select all

echo "" >> /etc/elasticsearch/jvm.options
echo "-Xms2g" >> /etc/elasticsearch/jvm.options
echo "-Xmx2g" >> /etc/elasticsearch/jvm.options
Enable and start ElasticSearch:

Code: Select all

systemctl enable elasticsearch.service
systemctl start elasticsearch.service
systemctl status elasticsearch.service

# Test it:
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:YOUR-ES-TOKEN https://localhost:9200

In order to disable SSL and authentication, do the following:

Code: Select all

cp /etc/elasticsearch/elasticsearch.yml /root/elasticsearch.yml.backup

v-sed "xpack.security.enabled" "# xpack.security.enabled" /etc/elasticsearch/elasticsearch.yml
v-php-func "replace_in_file_once_between_including_borders" "/etc/elasticsearch/elasticsearch.yml" "xpack.security.transport.ssl:" "truststore.path: certs/transport.p12" ""
v-php-func "replace_in_file_once_between_including_borders" "/etc/elasticsearch/elasticsearch.yml" "xpack.security.http.ssl:" "keystore.path: certs/http.p12" ""

echo "" >> /etc/elasticsearch/elasticsearch.yml
echo "xpack.security.enabled: false" >> /etc/elasticsearch/elasticsearch.yml
echo "xpack.security.transport.ssl.enabled: false" >> /etc/elasticsearch/elasticsearch.yml
echo "xpack.security.http.ssl.enabled: false" >> /etc/elasticsearch/elasticsearch.yml
systemctl restart elasticsearch.service

# Test it:
curl http://localhost:9200
Post Reply