Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»BIG-DATA»How to Install Elasticsearch on CentOS 7/6

    How to Install Elasticsearch on CentOS 7/6

    By RahulOctober 18, 20193 Mins Read

    Elasticsearch is flexible and powerful open-source, distributed real-time search and analytics engine. Using a simple set of APIs provides the ability for full-text search. Elastic search is freely available under the Apache 2 license, which provides the most flexibility.

    Advertisement

    This tutorial will help you to setup Elasticsearch single node cluster on CentOS, Red Hat, and Fedora systems.

    Step 1 – Prerequsities

    Java is the primary requirement for installing Elasticsearch on any system. You can check the installed version of Java by executing the following command. If it returns an error, install Java on your system using this tutorial.

    java -version
    

    Step 2 – Setup Yum Repository

    First of all, install GPG key for the elasticsearch rpm packages.

    sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
    

    Then create yum repository file for the elasticsearch. Edit /etc/yum.repos.d/elasticsearch.repo file:

    sudo vi /etc/yum.repos.d/elasticsearch.repo
    

    Add below content:

    [Elasticsearch-7]
    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=1
    autorefresh=1
    type=rpm-md
    

    Step 3 – Install Elasticsearch

    After adding yum repository, just install Elasticsearch on CentOS and RHEL system using the following command:

    sudo yum install elasticsearch
    

    After successful installation edit Elasticsearch configuration file “/etc/elasticsearch/elasticsearch.yml” and set the network.host to localhost. You can also change it to the system LAP IP address to make it accessible over the network.

    vim /etc/elasticsearch/elasticsearch.yml
    
      network.host: localhost
    

    Then enable the elasticsearch service and start it.

    sudo systemctl enable elasticsearch
    sudo systemctl start elasticsearch
    

    The ElasticSearch has been successfully installed and running on your CentOS or RHEL system.

    Run the following command to verify service:

    curl -X GET "localhost:9200/?pretty"
    

    You will see the results like below:

    {
      "name" : "tecadmin",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "HY8HoLHnRCeb3QzXnTcmrQ",
      "version" : {
        "number" : "7.4.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
        "build_date" : "2019-09-27T08:36:48.569419Z",
        "build_snapshot" : false,
        "lucene_version" : "8.2.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    

    Step 4 – Elasticsearch Examples (Optional)

    The following examples will help you to add, fetch and search data in the Elasticsearch cluster.

    Create New Bucket

    curl -XPUT http://localhost:9200/mybucket
    

    Output:

    {"acknowledged":true}
    

    Adding Data to Elasticsearch

    Use following commands to add some data in Elasticsearch.
    Command 1:

    curl -XPUT 'http://localhost:9200/mybucket/user/johny' -d '{ "name" : "Rahul Kumar" }'
    

    Output:

    {"_index":"mybucket","_type":"user","_id":"johny","_version":1,"created":true}
    

    Command 2:

    curl -XPUT 'http://localhost:9200/mybucket/post/1' -d '
    {
        "user": "Rahul",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 1 in Elasticsearch" ,
        "title": "Demo Post 1"
    }'
    

    Output:

    {"_index":"mybucket","_type":"post","_id":"1","_version":1,"created":true}
    

    Command 3:

    curl -XPUT 'http://localhost:9200/mybucket/post/2' -d '
    {
        "user": "TecAdmin",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 2 in Elasticsearch" ,
        "title": "Demo Post 2"
    }'
    

    Output:

    {"_index":"mybucket","_type":"post","_id":"2","_version":1,"created":true}
    

    Fetching Data from Elasticsearch

    Use the following command to GET data from ElasticSearch and read the output.

    curl -XGET 'http://localhost:9200/mybucket/user/johny?pretty=true'
    curl -XGET 'http://localhost:9200/mybucket/post/1?pretty=true'
    curl -XGET 'http://localhost:9200/mybucket/post/2?pretty=true'
    

    Searching in Elasticsearch

    Use the following command to search data from elastic search. Below command will search all data associated with user johny.

    curl 'http://localhost:9200/mybucket/post/_search?q=user:TecAdmin&pretty=true'
    

    Output:

    {
      "took" : 145,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
      },
      "hits" : {
        "total" : 1,
        "max_score" : 0.30685282,
        "hits" : [ {
          "_index" : "mybucket",
          "_type" : "post",
          "_id" : "2",
          "_score" : 0.30685282,
          "_source":
    {
        "user": "TecAdmin",
        "postDate": "01-15-2015",
        "body": "This is Demo Post 2 in Elasticsearch" ,
        "title": "Demo Post 2"
    }
        } ]
      }
    }
    
    

    Congratulations! You have successfully configured elasticsearch single node cluster on your Linux system.

    cluster data database elasticsearch Elasticsearch Cluster
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install and Secure MongoDB on Ubuntu 22.04

    What is High Availability Cluster: A Basic Introduction

    Using HDFS Filesystem (CLI)

    Creating Directory In HDFS And Copy Files (Hadoop)

    View 7 Comments

    7 Comments

    1. sarma on November 9, 2019 2:50 pm

      At step 3, after
      sudo yum install elasticsearch
      I got message, “No Package elasticsearch available.
      Error: Nothing to do

      My Java Version was 1.7.0_67

      How to proceed now?

      Reply
      • Rahul on November 12, 2019 7:29 am

        Hi,

        I have checked and elasticsearch package are available to install in repository. Please check repository once again.

        Reply
    2. AgBOX on March 21, 2016 6:49 am

      For new version elasticsearch version 2x, install plugin should : bin/plugin install

      Reply
    3. Breno on August 13, 2015 8:11 pm

      Great article. Congratulation!

      Reply
    4. Sam on July 28, 2015 6:54 am

      Perfect article… written nicely

      Thanks man…

      Reply
    5. JULIAN on July 7, 2015 4:12 am

      Thanks!
      really, you saved me so much time.

      Reply
    6. patrick on June 6, 2015 3:08 am

      Hi this needs updating to java 1.7
      please follow
      http://www.cyberciti.biz/faq/centos-linux-6-install-java-sdk/
      before installing elastic search
      great article i thought this was going to be really hard.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.