ElasticSearch / Install and configure on Linux Debian/Ubuntu

We are willing to install and configure the elastic search on Linux , and we will run from both localhost and global ip address.

Alanya memories. (2021-January)

We can install ElasticSearch with Debian package. It can be used to install Elasticsearch on any Debian-based system such as Debian and Ubuntu.This package is free to use under the Elastic license. It contains open source and free commercial features and access to paid commercial features.

The latest stable version of Elasticsearch can be found on the Download Elasticsearch page.

Ok, Let’s start ;

Download and install the public signing key:

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

You may need to install the package on Debian/Ubuntu before proceeding:

sudo apt-get install apt-transport-https

Save the repository definition to :

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

You can install the Elasticsearch Debian/Ubuntu package with:

sudo apt-get update && sudo apt-get install elasticsearch

Well done !

Elasticsearch can be started and stopped as follows:

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

To configure Elasticsearch to start automatically when the system boots up, run the following commands:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

Ok , let’s try it , after start the elasticsearch service,

run the command

curl -X GET "localhost:9200/?pretty"

we should see an output like below ,

{
"name" : "Xe2edb7",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "CC15_F_ATp-4NgIJGDFasf",
"version" : {
"number" : "7.10.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "f27399d",
"build_date" : "2016-03-30T09:51:41.449Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "1.2.3",
"minimum_index_compatibility_version" : "1.2.3"
},
"tagline" : "You Know, for Search"
}

Now , we will configure for an IP Adress or our domain , the directory contains the default runtime configuration for Elasticsearch.

before edit elasticsearch.yml file , check permissions and give required permissions as below , IF NEEDED

after change user to root ( sudo su root )

chmod o+x /etc/ /etc/elasticsearch/
chgrp [youruser] /etc/elasticsearch/

edit elasticsearch.yml file ,

nano /etc/elasticsearch/elasticsearch.yml

a) find the network section , remove #remarks at network hosts and port lines, and then write your ip address and port

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 81.93.216.111
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#

b) find the Discovery section, remove #remarks at lines of discovery.seed_hosts and cluster.initial_master_nodes , put yours,

# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["81.93.216.111:9200"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["elastic-test-node-1"]
#
# For more information, consult the discovery and cluster formation module docu>
#

attention here , cluster.initial_master_nodes indicates your node name,

you can find and change your node name at Node section ,

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-elasticsearch-test
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: elastic-test-node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1

Alright, stop and start the elasticsearch service again, and then check the elasticsearch service over global ip ,

have a look at browser, please type configured server ip and port, it should look like this ,

Congrats !

At the next article, we will see how to configure security settings for elasticsearch service.

Software Engineer & Consultant