大數據入門第二十五天——elasticsearch入門

1、概述

  推薦路神的ES權威指南翻譯:https://es.xiaoleilu.com/010_Intro/00_README.htmlhtml

  官網:https://www.elastic.co/cn/products/elasticsearchnode

  精品博文:https://blog.csdn.net/laoyang360/article/details/52244917linux

  1.es是什麼git

  官網的中文介紹:github

  Elasticsearch 是一個分佈式的 RESTful 風格的搜索和數據分析引擎,可以解決不斷涌現出的各類用例。做爲 Elastic Stack 的核心,它集中存儲您的數據,幫助您發現意料之中以及意料以外的狀況。數據庫

  權威指南的入門介紹:vim

Elasticsearch是一個實時分佈式搜索和分析引擎。它讓你之前所未有的速度處理大數據成爲可能。bash

它用於全文搜索、結構化搜索、分析以及將這三者混合使用ssh

  2.特徵curl

    查詢、分析、速度、可拓展性、彈性、靈活

    // 更多詳細特徵介紹,參考官網

2、安裝

  安裝es須要先安裝JDK,這裏咱們安裝es5.6,提請安裝一下JDK8

  1.下載

    https://www.elastic.co/cn/downloads/elasticsearch

    選擇一個合適的版本,下載便可

  2.解壓

    #es啓動時須要使用非root用戶!若是非要使用,另行配置,這裏暫不展開

[hadoop@mini1 ~]$ tar -zxvf elasticsearch-5.6.9.tar.gz -C /es

  // 相應的目錄須要有權限

  3.修改配置

[hadoop@mini1 config]$ vim elasticsearch.yml

  主要須要修改的項以下:

#集羣名稱,經過組播的方式通訊,經過名稱判斷屬於哪一個集羣 cluster.name: es #節點名稱,要惟一 node.name: es-1 #數據存放位置 path.data: /es/data #日誌存放位置 path.logs: /es/log #es綁定的ip地址 network.host: 192.168.137.128 #初始化時可進行選舉的節點 discovery.zen.ping.unicast.hosts: ["mini1", "mini2", "mini3"]

  4.拷貝到其餘節點

[hadoop@mini1 es]$ scp -r elasticsearch-5.6.9/ mini2:/es/
[hadoop@mini1 es]$ scp -r elasticsearch-5.6.9/ mini3:/es/

  5.修改其餘節點配置

  須要修改的有node.name和network.host

  6.啓動 

  bin/elasticsearch -h查看幫助文檔)
  bin/elasticsearch -d

  啓動時會報:Cannot allocate memory,緣由是內存不足,ES默認JVM內存爲2G

  解決方案參考自:https://blog.csdn.net/qq942477618/article/details/53414983

  其餘也會有一些啓動問題,根據日誌與博文排查便可:https://blog.csdn.net/feinifi/article/details/73633235?utm_source=itdadao&utm_medium=referral

  7.驗證

    根據以上兩篇博文排查完問題後就能夠啓動了,啓動後訪問默認的9200端口便可:mini1:9200

{ "name" : "es-1", "cluster_name" : "es", "cluster_uuid" : "qO0_NjifRiOnPUnWA-9W-Q", "version" : { "number" : "5.6.9", "build_hash" : "877a590", "build_date" : "2018-04-12T16:25:14.838Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" }

   8.中止

    能夠經過jps查看到其PID,也能夠直接使用kill一步到位:

kill `ps -ef | grep Elasticsearch | grep -v grep | awk '{print $2}'`

    固然,經過Jps也是能夠輕鬆找出es的pid的:

jps | grep Elasticsearch | awk '{print $1}'

    那中止命令也能夠長這樣:

kill -9 `jps | grep Elasticsearch | awk '{print $1}'`

   9.一鍵啓動腳本

    若是要編寫一個一鍵啓動腳本,那一個簡單的示例以下:

#!/bin/bash SERVERS="192.168.137.128 192.168.137.138 192.168.137.148" echo "start es..." for SERVER in $SERVERS do ssh $SERVER "source /etc/profile&&/es/elasticsearch-5.6.9/bin/elasticsearch -d" done

  chmod +x之後就能夠啓動了

  10.安裝head管理插件

    在線安裝:

bin/plugin install mobz/elasticsearch-head

   離線安裝須要先去github下載

./plugin install file:///home/bigdata/elasticsearch-head-master.zip

  這裏經過查看es-head的github,發現已經不支持5.x了:

  

   獨立server安裝方式,參考:https://blog.csdn.net/xgjianstart/article/details/78780176

3、基本概念

    和以前的lucene是比較相似的,主要概念以下:

      node/cluster:Node是集羣的節點,cluster表示集羣;

      Index:數據管理的頂層單位叫index(索引),概念上相似數據庫;

      Document:數據庫中的記錄就叫Document,一條條document組成了一個index;

      Type:Document的邏輯虛擬分組,概念上相似表,主要用來過濾Document;

    完整參考http://www.ruanyifeng.com/blog/2017/08/elasticsearch.html

4、基本操做

  es提供RESTful形式的操做,基本形式以下:

http://localhost:9200/<index>/<type>/[<id>]

  // 其中[]爲可選,<>爲必選

  1.新建與刪除index

  使用linux的curl來完成,新增index:

[hadoop@mini1 elasticsearch-5.6.9]$ curl -X PUT '192.168.137.128:9200/weather'

  刪除一樣簡單,換成DELETE請求便可

[hadoop@mini1 elasticsearch-5.6.9]$ curl -X DELETE '192.168.137.128:9200/weather'

  2.安裝IK中文分詞器

    https://github.com/medcl/elasticsearch-analysis-ik

    使用在線安裝便可(安裝博文參考:http://www.ruanyifeng.com/blog/2017/08/elasticsearch.html

 ###更多操做,待更新

相關文章
相關標籤/搜索