Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal M
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


Tags


avrt

Install ElasticSearch 6.x on Ubuntu 18.04 LTS

Faisal MFaisal M

At Will & Skill we frequently use ElasticSearch in our project. This is a step-by-step guide on how You can install and use ElasticSearch 6.x in your project.

Look for OpenJDK in APT

$ sudo apt search openjdk

Install OpenJDK 8

$ sudo apt update
$ sudo apt install apt-transport-https openjdk-8-jre-headless

Add the proper GPG key for ElasticSearch

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

Save the repo definition

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

Update APT and install ElasticSearch from APT

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

Reload the daemon

$ sudo /bin/systemctl daemon-reload

Allow ElasticSearch to start on boot

$ sudo /bin/systemctl enable elasticsearch.service

Lets fire up ElasticSearch...

$ sudo systemctl start elasticsearch.service

Lets see if we have some logs

$ sudo ls -la /var/log/elasticsearch/

Have a look at the logs and make sure that ElasticSearch has properly initiated

sudo cat /var/log/elasticsearch/elasticsearch.log

If logs are looking good, You can CURL the ElasticSearch server

$ curl -XGET 'localhost:9200/?pretty'

The output should be something like this

{
  "name" : "c29HHBX",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "LweifnvTSKeP12nRNu0DAg",
  "version" : {
    "number" : "6.1.10",
    "build_hash" : "b727a60",
    "build_date" : "2018-06-06T15:48:34.860Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}

Do all of the above in one script

Create a file somewhere named install-elasticsearch.sh and then do

  1. chmod +x install-elasticsearch.sh
  2. ./install-elasticsearch.sh
#!/bin/bash

sudo apt update
sudo apt install -y apt-transport-https openjdk-8-jre-headless
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-6.x.list
sudo apt update && sudo apt install -y elasticsearch
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl status elasticsearch.service
echo "Waiting for ElasticSearch to boot up..."
sleep 20
curl -XGET 'localhost:9200/?pretty'

Happy coding!

Faisal M
Author

Faisal M

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

View Comments