Introduction
Elasticsearch is an open-sourced distributed search and analytics engine for all data types, including textual, numerical, and unstructured. Elasticsearch supports simple REST APIs to search and analyze data.
This article will explain how to install and configure elastic search on Centos 7.
Prerequisites
- A root or non-root user with
sudo
privileges on a CentOS-7 system.
Install Java
Before Installing Elasticsearch you need to install Java on your system.
-
Install the latest version of Java on the system.
# sudo yum -y install java-11-openjdk-devel
- Verify the installed Java version.
# java -version
Install Elasticsearch
- First, install wget package if not installed on your system.
# sudo yum -y install wget
- Download Elasticsearch rpm from the official repository.
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-x86_64.rpm
- Install Elasticsearch using the rpm command.
# sudo rpm -ivh elasticsearch-7.9.2-x86_64.rpm
- After successfully installation of Elasticsearch, enable it.
# sudo systemctl enable elasticsearch
Configuring Elasticsearch
Elasticsearch configuration files are located in/etc/elasticsearch
by default, it listens on localhost only.
-
Open the
elasticsearch.yml
configuration file.# vi /etc/elasticsearch/elasticsearch.yml
-
Uncomment the
cluster.name
andnode.name
in the file and set the values for both attributes.node.name: my-node
cluster.name: mycluster - Start the Elasticsearch services.
# sudo systemctl start elasticsearch
-
To test the service, make a
GET
request on your system.# curl -X GET 'http://localhost:9200'
Use of Elasticsearch
- Send a
POST
request to the Elasticsearch server to the first entry in Elasticsearch.# curl -H 'Content-Type: application/json' -X POST 'http://localhost:9200/data/firstentry/1' -d '{ "message": "Hello Test!"
}' -
Retrieve your added entry using HTTP get request.
# curl -X GET 'http://localhost:9200/data/firstentry/1'