http://tecadmin.net/install-elasticsearch-on-linux/#

 

Elasticsearch

How to Install Elasticsearch (Single Node Cluster) on CentOS & Ubuntu_elk

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

1. Verify Java

Java is the primary requirement for installing Elasticsearch. So make sure you have Java installed on your system.



# java -version java version "1.8.0_31" Java(TM) SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)



If you don’t have Java installed on your system, use one of following link to install it first.

2. Download Elasticsearch Archive

Now download the latest Elasticsearch archive from its official download page. At the time of last update of this article Elasticsearch 2.3.1 version is latest version available to download.



$ /tmp $ wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.1.tar.gz



Now extract downloaded Elasticsearch archive on your system.



$ tar xzf elasticsearch-2.3.1.tar.gz



3. Configure Elasticsearch

Now we need to setup Elasticsearch cluster and node name. Elasticsearch uses “elasticsearch” as default cluster name, We recommend to change it as per your setup.



$ mv elasticsearch-2.3.1 /usr/share/elasticsearch $ cd /usr/share/elasticsearch



To change cluster named edit config/elasticsearch.yml



$ vim config/elasticsearch.yml



network.host: 192.168.10.100 cluster.name: TecAdmin_Cluster1 node.name: "California DataCenter"



4. Install Elasticsearch-Head Plugin

elasticsearch-head is a web front end for browsing and interacting with an Elastic Search cluster. Use the following command to install it.



$ bin/plugin install mobz/elasticsearch-head



5. Starting Elasticsearch Cluster

As the Elasticsearch setup is completed. Let the start Elasticsearch cluster using following command.



$ ./bin/elasticsearch &



6. Verify Setup

You have all done, just need to verify setup. Elasticsearch works on port default port 9200, open your browser to point your server on port 9200, You will find some thing like below output



http://localhost:9200/_plugin/head/





http://svt1.tecadmin.net:9200/



7. Basic Examples of Elasticsearch Uses

Following examples will help you to add, fetch and search data in Elasticsearch cluster.

Creating 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 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 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"
}
    } ]
  }
}




Congratulation’s! You have successfully configured elasticsearch single node cluster on your Linux system.

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: centosUbuntu