Skip to content

Installing Elasticsearch on Debian

Installing Elasticsearch (6.x) on Debian

Download and install the public signing key:

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

Installing the ‘apt-transport-https’ package before proceeding:

apt-get install apt-transport-https

Adding the repository definition to ‘/etc/apt/sources.list’

echo -e "\n# Elasticsearch\ndeb https://artifacts.elastic.co/packages/6.x/apt stable main" >> /etc/apt/sources.list

Before installing elasticsearch, we need openjdk:

apt-get install openjdk-8-jdk

Installing elasticsearch:

apt-get update && apt-get install elasticsearch

Output example:

Preparing to unpack .../elasticsearch_6.7.1_all.deb ...
/usr/bin/java
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (6.7.1) ...
Setting up elasticsearch (6.7.1) ...

Before starting: If you wish, you can adjust the settings. Elasticsearch has three configuration files:

– ‘/etc/elasticsearch/elasticsearch.yml’ for configuring Elasticsearch
– ‘/etc/elasticsearch/jvm.options’ for configuring Elasticsearch JVM settings
– ‘/etc/elasticsearch/log4j2.properties’ for configuring Elasticsearch logging

Sample configuration file for Elasticsearch

cluster.name: UNIX
node.name: web
network.host: 127.0.0.1
http.port: 9200
http.compression: true
bootstrap.memory_lock: true
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch

Starting elasticsearch:

systemctl start elasticsearch

Let’s play and test a little bit:

root@ns:~# curl http://localhost:9200/
{
  "name" : "KG5BdkS",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "bfK5xI2ZQPyH4fyL3S1X7A",
  "version" : {
    "number" : "6.7.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "2f32220",
    "build_date" : "2019-04-02T15:59:27.961366Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

I will create a index:

root@ns:~# curl -X PUT http://localhost:9200/tex
{"acknowledged":true,"shards_acknowledged":true,"index":"tex"}

And I will test to add some data to my index

root@ns:~# curl http://localhost:9200/tex/unixteacher/1 -d '{"message":"Welcome to my webpage"}' -H "Content-Type: application/json"
{"_index":"tex","_type":"unixteacher","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

Everything looks ok. I have got the data from the index

root@ns:~# curl http://localhost:9200/tex/unixteacher/1?pretty
{
  "_index" : "tex",
  "_type" : "unixteacher",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "message" : "Welcome to my webpage"
  }
}

I can get the data from the _search endpoint:

root@ns:~# curl http://localhost:9200/tex/_search?pretty
{
  "took" : 41,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "tex",
        "_type" : "unixteacher",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "message" : "Welcome to my webpage"
        }
      }
    ]
  }
}
Published inLinux
© 2019 - Marian Amza. All rights reserved.
Powered by Wordpress & Debian