In this article, We are going to perform, How to Install Elasticsearch on CentOS 7 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
- CentOS 7 with Minimal Installation
- Java 8 or higher version
- 2 CPU and 4 GB RAM
- Open Ports 9200
Update the system packages
$ sudo yum update
Install JDK on CentOS
You can install OpenJDK 8 or 11 on CentOS
$ sudo yum -y install java-1.8.0-openjdk
Lets install OpenJDK 11 on ubuntu using below commands.
$ sudo yum 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) OpenJDK 64-Bit Server VM (build 11.0.7+10)
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/profile.d/java.sh
For OpenJDK 8 java is installed at /usr/lib/jvm/java-11-openjdk-amd64/bin/java location
For OpenJDK 11 Java is installed at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java location
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Load the environment variable using below command
$ source /etc/profile.d/java.sh
Lets verify JAVA_HOME variable
$ echo $JAVA_HOME
Output:
/usr/lib/jvm/java-11-openjdk-amd64
If you seeing output like above then we have successfully set up the Java Home on CentOS 7.
Step 1: How to Install ElasticSearch on CentOS 7
First import the Elasticsearch PGP key into CentOS using below command
$ sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Create elasticsearch.repo file in /etc/yum.repos.d/ directory
$ sudo nano /etc/yum.repos.d/elasticsearch.repo
Paste the below lines into it
[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=0 autorefresh=1 type=rpm-md
Install Elasticsearch using below command
$ sudo yum 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 CentOS 7
Step 3: Add Firewall Rule
If you are using firewall on Ubuntu, open port 9200 using below command.
$ sudo firewall-cmd --permanent --add-port=9200/tcp $ sudo firewall-cmd --reload
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 CentOS 7, 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