elasticsearch的安裝、部署

https://blog.csdn.net/lubin2016/article/details/81606753node

 

1. elasticsearch的安裝

1.1 集羣規劃

上傳elasticsearch的tar.gz包至規劃的集羣各節點的目錄下(規劃兩個節點rc-fhcb-10-es001,rc-fhcb-10-es002),如:本項目安裝在/opt/fhcb/目錄下

注意:建議elasticsearch的安裝包在集羣中各節點目錄一致linux

1.2 修改配置文件

修改安裝包下config目錄下的配置文件elasticsearch.yml(集羣每一個節點)git

 1 # 集羣的名稱  2 cluster.name: elasticsearch  3 # 節點名稱  4 node.name: es-node-01  5 # 配置文件的位置  6 path.conf: /opt/fhcb/elasticsearch-1.6.0/config  7 # 該節點存儲的索引數據  8 path.data: /opt/fhcb/elasticsearch-1.6.0/data  9 # 臨時工做目錄 10 path.work: /opt/fhcb/elasticsearch-1.6.0/work 11 # 日誌文件位置 12 path.logs: /opt/fhcb/elasticsearch-1.6.0/logs 13 # 插件安裝目錄 14 path.plugins: /opt/fhcb/elasticsearch-1.6.0/plugins 15 # 設置該節點綁定的ip地址 16 network.bind_host: rc-fhcb-10-es001 17 # 設置其它節點與該節點交互的ip地址 18 network.publish_host: rc-fhcb-10-es001 network.host: rc-fhcb-10-es001 # 設置tcp協議端口號 19 transport.tcp.port: 9300 20 # 設置http協議端口號 21 http.port: 9200 22 # 經過配置這個參數來防止集羣腦裂現象 (集羣總節點數量/2)+1 discovery.zen.minimum_master_nodes: 2 23 # 默認設置爲3s,此參數值爲集羣發現其它節點ping鏈接的超時時間,爲避免網絡延時,致使報錯,故設置稍大些 24 discovery.zen.ping.timeout: 40s 25 # 設置是否打開多播發現節點,默認爲true discovery.zen.ping.multicast.enabled: false 26 # 在es1.x中默認使用的是組播(multicast)協議,默認會自動發現同一網段的es節點組建集羣, 27 # 在es2.x中默認使用的是單播(unicast)協議,想要組建集羣的話就須要在這指定要發現的節點信息了。 28 discovery.zen.ping.unicast.hosts: ["rc-fhcb-10-es001", "rc-fhcb-10-es002"]

其它,節點下配置修改與上面大體相同,只是如下幾個參數值不一樣:github

1 node.name: es-node-02 2 network.bind_host: rc-fhcb-10-es002 3 network.publish_host: rc-fhcb-10-es002 4 network.host: rc-fhcb-10-es002

1.3 啓動elasticsearch集羣

在bin目錄下,後臺啓動elasticsearch(集羣每一個節點)web

方式一sql

./elasticsearch -d -Xms8g -Xmx8g

注意:參數-Xms8g -Xmx8g爲ES使用的堆內存,具體大小應根據機器的配置肯定,建議不要超過物理內存的一半,也不要超過32G;npm

方式二json

1 在修改/etc/profile文件,添加以下內容 2 export ES_HEAP_SIZE=8g 3 
4 而後在ES安裝目錄的bin目錄下啓動 5 ./elasticsearch -d

1.4 插件安裝(在線安裝)

插件的安裝沒必要每一個節點都進行安裝,進入到安裝節點的elasticsearch安裝目錄的bin目錄下網絡

BigDesk Plugin : 對集羣中es狀態進行監控app

./plugin -install lukas-vlcek/bigdesk

Elasticsearch Head Plugin插件

./plugin -install mobz/elasticsearch-head

Elasticsearch Sql 插件

./plugin install NLPchina/elasticsearch-sql -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.6/elasticsearch-sql-1.4.6.zip

注意:sql插件重啓後生效

Elasticsearch kopf插件

./plugin -install lmenezes/elasticsearch-kopf

注意:以上安裝方式都是在線安裝,安裝節點必須能鏈接互聯網

查看head頁面索引http://10.13.11.21:9200/_plugin/head/

查看sql頁面:http://10.13.11.21:9200/_plugin/sql/

關閉elasticsearch

前臺運行,經過」CTRL+C「組合鍵來終止elasticsearch的運行

後臺運行,經過「kill -9 進程號」中止運行

經過REST API接口關閉整個集羣:

curl -XPOST http://主機ip:9200/_cluster/nodes/_shutdown

經過以下命令來關閉單個節點:

curl -XPOST http://主機ip:9200/_cluster/nodes/節點標誌符(如:es-node-01)/_shutdown

1.5 插件安裝(離線安裝)

head插件

下載地址:https://github.com/mobz/elasticsearch-head

./plugin --install head --url file:///opt/softwares/elasticsearch-head-master.zip

sql插件

下載地址:https://github.com/NLPchina/elasticsearch-sql

./plugin --install sql --url file:///opt/softwares/elasticsearch-sql-1.4.6.zip

注意:sql插件重啓後生效

bigdesk插件

下載地址:https://github.com/lukas-vlcek/bigdesk

./plugin --install bigdesk --url file:///opt/softwares/bigdesk-master.zip

kopf插件

下載地址:https://github.com/lmenezes/elasticsearch-kopf

./plugin --install kopf --url file:///opt/softwares/elasticsearch-kopf-master.zip

2. 數據導入導出工具elasticdump工具的安裝

2.1 安裝nodejs插件

方式一:在線安裝

1 yum -y install epel-release 2 yum -y install nodejs 3 yum -y install npm

方式二:離線安裝

下載地址:https://nodejs.org/dist/latest-v8.x

下載nodejs的安裝包(xxx.tar.gz),解壓到指定目錄;

配置nodejs的環境變量

1 export NODE_HOME=/opt/fhcb/node-v8.11.3-linux-x64 2 export PATH=$NODE_HOME/bin:$PATH

驗證

1 npm -v 2 node -v

2.2 安裝elasticdump

方式一:(在線)

1 npm install elasticdump # 局部安裝,elasticdump安裝在當前目錄 2 #或 3 npm install elasticdump -g  # -g表示全局安裝

注意: 此方式安裝elasticdump須要聯網
方式二:(離線)

1 # 前提條件:已經安裝好node,npm 2 直接將已經安裝好的node_modules安裝包拷貝到須要安裝的機器上便可

2.3 導出數據

進入elasticdump的安裝目錄node_modules,而後進入elasticdump/bin目錄下操做;

./elasticdump --input http://10.13.11.21:9200/10news_f_hot_news_toplist --output /root/datas/10news_f_hot_news_toplist.json --type=data

注意:導出目錄/root/datas必須存在,不然報錯;

–type參數:analyzer,拷貝analyzer分詞

–type參數:mapping,拷貝映射

–type參數:data,拷貝數據

導出特定內容的數據

 1 ./elasticdump --input http://192.168.102.108:9200/web_page_news_info_09 --output /root/datas/web_page_news_info_09.json --type=data  2 --searchBody  3 '  4 {  5  "from": 0,  6  "size": 200,  7  "query": {  8  "filtered": {  9  "filter": { 10  "bool": { 11  "must": { 12  "query": { 13  "match": { 14  "orgcode": { 15  "query": "FHCB00001", 16  "type": "phrase" 17  } 18  } 19  } 20  } 21  } 22  } 23  } 24  } 25 } 26 ' 27 # 導出web_page_news_info_09.json表中,orgcode字段爲FHCB00001的記錄

2.4 導入數據

./elasticdump --input /opt/data/web_page_book_summary_09.json --output http://10.13.11.21:9200 --type=data

注意:可使用elasticdump –help查看插件的一些經常使用命令

3. IK中文分詞器

3.1 安裝ik分詞器(ES集羣每一個節點)

3.1.1 到github下載分詞器源代碼,地址爲:https://github.com/medcl/elasticsearch-analysis-ik

注意:下載與elasticsearch匹配的分詞器源碼版本,1.6.x對應的源碼版本爲1.4.0

3.1.2 解壓elasticsearch-analysis-ik-1.4.0.zip,而後編譯源碼
3.1.3 將解壓目錄文件中config/ik文件夾複製到ES安裝目錄config文件夾下
3.1.4 把\target\releases\elasticsearch-analysis-ik-1.4.1.zip 解壓到 ES安裝目錄/plugins/analysis-ik/
3.1.5 將elasticsearch-analysis-ik-1.4.0.jar複製到ES安裝目錄/lib下
3.1.6 修改ES的配置文件config/elasticsearch.yml,增長ik的配置

 1 index:  2  analysis:  3  analyzer:  4  ik:  5  alias:[ik_analyzer]  6  type:org.elasticsearch.index.analysis.IkAnalyzerProvider  7  ik_max_word:  8  type:ik  9  use_smart:false 10  ik_smart: 11  type:ik 12  use_smart:true 13 index.analysis.analyzer.default.type:ik

注意:全局範圍內全部的索引都將受到影響,也能夠只對某個索引設置分詞器

3.1.7 重啓elasticsearch

3.1.8 驗證分詞效果

 1 #使用分詞器  2 http://10.11.2.105:9200/web_page_book_summary_09/_analyze?analyzer=ik_smart&pretty=true&text=中國特社會主義  3 { "tokens" : [ { "token" : "中國特點社會主義", "start_offset" : 0, "end_offset" : 8, "type" : "CN_WORD", "position" : 1 } ] }  4 
 5 #沒有使用分詞器  6 http://10.13.11.21:9200/web_page_book_summary_09/_analyze?analyzer=standard&pretty=true&text=中國特社會主義  7 {  8  "tokens": [{  9  "token": "中", 10  "start_offset": 0, 11  "end_offset": 1, 12         "type": "<IDEOGRAPHIC>", 13  "position": 1 14  }, { 15  "token": "國", 16  "start_offset": 1, 17  "end_offset": 2, 18         "type": "<IDEOGRAPHIC>", 19  "position": 2 20  }, { 21  "token": "特", 22  "start_offset": 2, 23  "end_offset": 3, 24         "type": "<IDEOGRAPHIC>", 25  "position": 3 26  }, { 27  "token": "色", 28  "start_offset": 3, 29  "end_offset": 4, 30         "type": "<IDEOGRAPHIC>", 31  "position": 4 32  }, { 33  "token": "社", 34  "start_offset": 4, 35  "end_offset": 5, 36         "type": "<IDEOGRAPHIC>", 37  "position": 5 38  }, { 39  "token": "會", 40  "start_offset": 5, 41  "end_offset": 6, 42         "type": "<IDEOGRAPHIC>", 43  "position": 6 44  }, { 45  "token": "主", 46  "start_offset": 6, 47  "end_offset": 7, 48         "type": "<IDEOGRAPHIC>", 49  "position": 7 50  }, { 51  "token": "義", 52  "start_offset": 7, 53  "end_offset": 8, 54         "type": "<IDEOGRAPHIC>", 55  "position": 8 56  }] 57 }

3.2 IK分詞器

ik_max_word: 會將文本作最細粒度的拆分,好比會將「中華人民共和國國歌」拆分爲「中華人民共和國,中華人民,中華,華人,人民共和國,人民,人,民,共和國,共和,和,國國,國歌」,會窮盡各類可能的組合;
ik_smart: 會作最粗粒度的拆分,好比會將「中華人民共和國國歌」拆分爲「中華人民共和國,國歌」。

4. 問題集錦

問題1:由SSL引起的問題

nodejs的npm安裝模塊時候報錯:npm ERR! Error: CERT_UNTRUSTED

解決方案:

npm config set strict-ssl false

問題2:npm安裝elasticdump時報錯

SyntaxError: Unexpected identifier

解決方案:升級一下nodejs版本

npm install -g n n stable
相關文章
相關標籤/搜索