1. 程式人生 > >ElasticSearch之——linux下安裝及head外掛

ElasticSearch之——linux下安裝及head外掛

轉載請註明出處:https://blog.csdn.net/l1028386804/article/details/79955325

系統環境: vm12 下的centos 7.2

當前安裝版本: elasticsearch-2.4.0.tar.gz

安裝和學習可參照官方文件:

安裝

# 下載, 獲取不成功可直接從官網下載
curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz
# 解壓
sudo tar -xvf elasticsearch-2.4.0.tar.gz
# 進入目錄
cd elasticsearch-2.4.4/bin

啟動

./bin/elasticsearch
啟動成功的介面為:

此時可以使用瀏覽器訪問: http://192.168.209.121:9200


注: 由於沒有更改yml檔案, 只能在本機訪問

修改elasticsearch.yml 使得其他機器可訪問

sudo vim ./config/elasticsearch.yml


安裝head

elasticsearch-head是一個介面化的叢集操作和管理工具,可以對叢集進行傻瓜式操作。你可以通過外掛把它整合到es(首選方式),也可以安裝成一個獨立webapp。
es-head主要有三個方面的操作:
顯示叢集的拓撲,並且能夠執行索引和節點級別操作
搜尋介面能夠查詢叢集中原始json或表格格式的檢索資料
能夠快速訪問並顯示叢集的狀態
有一個輸入視窗,允許任意呼叫RESTful API。這個介面包含幾個選項,可以組合在一起以產生有趣的結果;
請求方法(get、put、post、delete),查詢json資料,節點和路徑
支援JSON驗證器
支援重複請求計時器
支援使用javascript表示式變換結果
收集結果的能力隨著時間的推移(使用定時器),或比較的結果
能力圖表轉換後的結果在一個簡單的條形圖(包括時間序列)

 1), 直接安裝

./bin/plugin install mobz/elasticsearch-head

2) ,zip包安裝

1. https://github.com/mobz/elasticsearch-head下載zip 解壓
2. 建立elasticsearch-2.4.0\plugins\head檔案
3. 將解壓後的elasticsearch-head-master資料夾下的檔案copy到head
4. 執行es

 3, 安裝其他外掛

$ ${ES_HOME}/bin/plugin --install lukas-vlcek/bigdesk
# 安裝完成訪問:http://localhost:9200/_plugin/bigdesk/#nodes

$ ${ES_HOME}/bin/plugin -install royrusso/elasticsearch-HQ
# 安裝完成訪問:http://localhost:9200/_plugin/HQ/

$ ${ES_HOME}/bin/plugin -install lmenezes/elasticsearch-kopf
# 安裝完成訪問:http://localhost:9200/_plugin/kopf/#!/cluster
官方的文件:
https://github.com/mobz/elasticsearch-head

出現的錯誤: 

錯誤1:

Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:94)
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:160)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

解決: 不使用root賬戶登入

錯誤2:

java.io.FileNotFoundException: /usr/docker/elasticsearch/elasticsearch-2.4.0/logs/elasticsearch_index_search_slowlog.log (許可權不夠)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)

原因: 檔案所有者不是當前使用者

解決: 退回的解壓目錄, 更改整個資料夾的所有者為當前使用者

chown -R wenbronk:wenbronk elasticsearch-2.4.0

錯誤3:

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

原因: 最大檔案描述符太低, 需要增加到65536

su到root使用者, vim /etc/security/limits.conf

*        hard    nofile           65536
*        soft    nofile           65536

錯誤4:

ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

原因: 堆記憶體太低, 繼續調大

vi /etc/sysctl.conf 
vm.max_map_count=655360
執行:
sysctl -p

安裝前準備

啟動前需要修改配置檔案(需要許可權)

1.設定核心引數

vim /etc/sysctl.conf

新增如下內容:

fs.file-max=65536

vm.max_map_count=262144

之後可以使用sysctl –a檢視 –p重新整理

2. 設定資源引數

vim /etc/security/limits.conf

新增如下內容:

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096

3. 修改程序數

vim /etc/security/limits.d/20-nproc.conf

修改( * soft nproc )的值為2048