Elasticsearch is a highly scalable open-source analytics engine and full-text search. With Elasticsearch, you can store, search, and analyze big volumes of data faster and in near real time. Elasticsearch is generally used as the underlying engine/technology that powers applications that have complex search features and requirements. This guide will show you how to install Elasticsearch 7.x on Ubuntu 18.04 LTS (Bionic Beaver) Linux.
For Elasticsearch 6.x, check:
Here is the guide to install Elasticsearch 7.x on Ubuntu 18.04 LTS.
Step 1: Import Elasticsearch GPG Key
The first step is to import Elasticsearch GPG Key using the command:
sudo apt update
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
Step 2: Add Elasticsearch 7.x APT repository
Once the GPG key has been imported, add the apt repository so that you can install Elasticsearch package from:
sudo apt -y install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
Step 3: Install OpenJDK
Elasticsearch is dependent on Java, you need to install OpenJDK before you can continue.
sudo apt update
sudo apt -y install default-jdk default-jre
Confirm Java installation by checking the version:
$ java -version
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu118.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu118.04, mixed mode, sharing)
Step 4: Install Elasticsearch 7.x on Ubuntu 18.04
Now run apt-get update
then install elasticsearch package:
sudo apt update
sudo apt install vim elasticsearch-oss
After the installation, a default configuration file will be populated to /etc/elasticsearch/elasticsearch.yml
Most lines are commented out, edit the file to tweak and tune the configuration.
E.g, you can set correct cluster name for your applications:
$ sudo vim /etc/elasticsearch/elasticsearch.yml cluster.name: elkcluster
Note that the default minimum memory set for JVM is 2gb, if your server has small memory size, change this value:
sudo vim /etc/elasticsearch/jvm.options
Change:
-Xms2g
-Xmx2g
And set your values for minimum and maximum memory allocation. E.g to set values to 512mb of ram and 1GB, use:
-Xms512m
-Xmx1g
After you have modified the configuration, you can start Elasticsearch:
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl restart elasticsearch.service
Check status:
$ systemctl status elasticsearch.service ● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2022-10-18 17:29:04 UTC; 16s ago Docs: https://www.elastic.co Main PID: 5075 (java) Tasks: 45 (limit: 2300) CGroup: /system.slice/elasticsearch.service └─5075 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -D Oct 18 17:28:39 server systemd[1]: Starting Elasticsearch... Oct 18 17:29:04 server systemd[1]: Started Elasticsearch.
That’s all for the installation of Elasticsearch 7.x on Ubuntu 18.04 LTS (Bionic Beaver) Linux.
Learning materials:
For Cluster setup, check out Setup Elasticsearch Cluster on CentOS / Ubuntu With Ansible