Install Elasticsearch in Centos and fedora
Elasticsearch is one of the most popular search engines powering applications that have complex search requirements such as big e-commerce stores and analytic applications.Elastic search is freely available under the Apache 2 license, which provides the most flexibility.
Prerequisites:
Java is the Basic requirement for installing Elasticsearch on any system.If your system don't have java installed then install lasest version by following our tutorial. You can check the installed version of Java by following command.
[root@lampblogs ~]# java -version
openjdk version "1.8.0_161"
Installing Elasticsearch
you can download the latest Elasticsearch from its official download url
[root@lampblogs ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-x86_64.rpm
In this article i have added following repo as elasticsearch.repo
[root@lampblogs ~]# vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
Once the repository is added, clear and update your YUM package index
[root@lampblogs ~]# yum clean all
Now you can install Elasticsearch using the command below
[root@lampblogs ~]# yum install elasticsearch
# if you downloaded rpm package from official download url then follow below #
[root@lampblogs ~]# yum localinstall elasticsearch-7.2.0-x86_64.rpm
configure Elasticsearch
Edit elasticsearch.yml file
[root@lampblogs ~]# vi /etc/elasticsearch/elasticsearch.yml
Replace lamp_Cluster1 with your Elasticsearch cluster name
cluster.name: lamp_Cluster1
nodename is like a hostname for the Elasticsearch server, dynamically generated during the service startup. You can set the Node name by updating the below line. Replace myfirstnode with your Elasticsearch node name.
node.name: myfirstnode
Elasticsearch binds to localhost (127.0.0.1) and listens on port number 9200 for HTTP traffic by default.Replace network host with your system ip or localhost.
# Listening on particular IPv4 #
network.host: 192.168.0.8
# Set a custom port for HTTP:
http.port: 9200
Once the installation process is complete, start and enable the service.
[root@lampblogs ~]# sudo systemctl daemon-reload
[root@lampblogs ~]# sudo systemctl start elasticsearch.service
[root@lampblogs ~]# sudo systemctl enable elasticsearch.service
Check if Elasticsearch is listening on port 9200
[root@lampblogs ~]# netstat -antp | grep 9200
tcp 0 0 192.168.0.8:48276 192.168.0.8:9200 TIME_WAIT -
tcp6 0 0 192.168.0.8:9200 :::* LISTEN 2054/java
Test Elasticsearch in browser using http://192.168.0.8/9200
or run curl -X GET 'http://192.168.0.8:9200' in server.
{
"name" : "myfirstnode",
"cluster_name" : "lamp_Cluster1",
"cluster_uuid" : "AU0sEbACSz2QjaNBel2irQ",
"version" : {
"number" : "6.8.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "1fad4e1",
"build_date" : "2019-06-18T13:16:52.517138Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
Now Elasticsearch is sucessfully installed and working fine.
Below are few examples to add,search data in Elasticsearch cluster.
Use the following curl command to add data on to our Elasticsearch.
curl -XPUT 'http://192.168.0.8:9200/lampblogs/howtos/1' -H 'Content-Type: application/json' -d '
{
"Title" : "Install Elasticsearch On CENTOS 7",
"Date" : "June 2019",
"Tag" : "CENTOS"
}'
you should get the following response with “result” as ”created”
{"_index":"lampblogs","_type":"howtos","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
Use the following command to query/read data on Elasticsearch.
curl -X GET 'http://192.168.0.8:9200/lampblogs/howtos/1?pretty=true'
{
"_index" : "lampblogs",
"_type" : "howtos",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"Title" : "Install Elasticsearch On CENTOS 7",
"Date" : "June 2019",
"Tag" : "CENTOS"
}
}
Use the following command to delete the document.
curl -X DELETE 'http://192.168.0.8:9200/lampblogs/howtos/1'
Response will look like below. If the document is found you will get “result” as' deleted'.
{"_index":"lampblogs","_type":"howtos","_id":"1","_version":2,"result":"deleted","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}