In this article, We are going to perform, How to Install Elasticsearch on Ubuntu 20.04/18.04/16.04 LTS or any Cloud Instance like Amazon EC2, Azure VM, Google Compute Engine,etc. with preinstalled
Table of Contents
Introduction
Elasticsearch is a free and open source search and analytics engine. It is used to store, search and analyze big volumes of data quickly and real time.
Prerequisites
- Ubuntu Server with 20.04/18.04/16.04 LTS
- Java 8 or higher version
- 2 CPU and 4 GB RAM
- Open Ports 9200
Update the system packages
$ sudo apt update
Install the apt-transport-https package to access repository over HTTPS
$ sudo apt install apt-transport-https
Install Java on Ubuntu
Lets install OpenJDK 11 on ubuntu using below commands.
$ sudo apt install openjdk-11-jdk
Lets verify java version
$ java -version
Output:
openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
Set Default Java Version using update alternatives
If you have installed multiple Java versions on your system and you want to set Default Java version on Ubuntu. Lets set Default Java Version using update alternatives command,
$ sudo update-alternatives --config java
It prompts for selecting by 0,1,2..so choose accordingly:
Setting the JAVA_HOME Environment Variables
$ sudo nano /etc/environment
For OpenJDK 8 java is installed at /usr/lib/jvm/java-11-openjdk-amd64/bin/java location
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Load the environment variable using below command
$ source /etc/environment
Lets verify JAVA_HOME variable
$ echo $JAVA_HOME
Output:
/usr/lib/jvm/java-11-openjdk-amd64
Step 1: Install ElasticSearch on Ubuntu
Here, We are adding ElasticSearch official apt package and this is signed with GPG keys
$ sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
Next add the repository in /etc/apt/sources.list.d/elastic-7.x.list using below command.
$ sudo echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
To install elasticsearch enter below command
$ sudo apt-get update
$ sudo apt-get install elasticsearch
Start elacticsearch services
$ sudo systemctl start elasticsearch
Enable elacticsearch at system startup
$ sudo systemctl enable elasticsearch
To check the status of elasticsearch
$ sudo systemctl status elasticsearch
Output:
elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-05-28 05:31:52 UTC; 1 day 3h ago
Docs: http://www.elastic.co
Main PID: 156620 (java)
Tasks: 68 (limit: 19185)
Memory: 1.3G
CGroup: /system.slice/elasticsearch.service
├─156620 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xs>
└─156730 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
Step 2: Configure Elasticsearch
Let’s make changes in below configuration file
$ sudo nano /etc/elasticsearch/elasticsearch.yml
Go to Network section and uncommnet network.host and replace your system IP or localhost
network.host: 0.0.0.0
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
Restart elacticsearch services to take effect
$ sudo systemctl restart elasticsearch
Here We have covered How to Install Elasticsearch on Ubuntu
Step 3: Add Firewall Rule
To allow traffic on port 9200 enter the below command:
$ sudo ufw allow 9200/tcp
Step 4: Testing Elasticsearch
Lets test Elasticsearch using curl command by sending HTTP request
$ curl -X GET "localhost:9200"
Output:
{ "name" : "ip-192-168-100-10", "cluster_name" : "elasticsearch", "cluster_uuid" : "ciPfyPlvT1K7lVmOv_Jbtw", "version" : { "number" : "7.6.2", "build_flavor" : "default", "build_type" : "deb", "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f", "build_date" : "2020-03-26T06:34:37.794943Z", "build_snapshot" : false, "lucene_version" : "8.4.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
OR
You can access using browser
http://systemIP:9200
Error: ElasticSearch 7 start up error – the default discovery settings are unsuitable for production use;
ERROR: Elasticsearch did not exit normally – check the logs at /var/log/elasticsearch/elasticsearch.log
If you have installed Elasticsearch on Single system and you are unable start Elasticsearch service due to above error.
Open Elasticsearch configuration , navigate to Discovery section and change below as shown below
# --------------------------------- 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: [ ]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
Conclusion:
In this article, We have performed ,How to Install Elasticsearch on Ubuntu, Configure Elasticsearch, Testing and Adding firewall rule.
How to Install ELK Stack on Ubuntu 18.04/16.04 LTS
How to Install Elastic Stack on CentOS 7