在CentOS上安裝ELK 5時遇到的一些坑

來源:互聯網
上載者:User

安裝ELK的Linux環境是CentOS 7,使用的JDK版本是1.8.0_144
安裝使用的ELK版本是5.5.1
首先安裝elasticsearch 5.5.1,從官網下載elasticsearch-5.5.1.tar.gz後解壓,在bin目錄下以root使用者身份直接運行

./elasticsearch

會拋出異常資訊

java.lang.RuntimeException: can not run elasticsearch as root

警告不能使用root使用者啟動elasticsearch。
我建立了elk groups和elk使用者,按照網上提示的把elasticsearch解壓目錄的所有者賦予elk使用者,結果不起作用,當從root使用者切換回elk使用者後,無法切換到解壓目錄,提示許可權不許可。

還需要賦予elk使用者對解壓目錄的讀寫執行許可權後才能啟動elasticsearch應用。

sudo chmod -R 755 /opt/elk/elasticsearch-5.5.1

切換到elk使用者後,可以啟動elasticsearch,但是開機記錄中顯示啟動檢查失敗,啟動不成功。
檢查錯誤資訊有兩條

[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]

第一條錯誤檢查表示elk使用者啟動elasticsearch的最大檔案描述符預設值4096過小,需要調整為65536。
我們修改/etc/security/limits.conf檔案,在最後添加

elk soft nofile 65536elk hard nofile 65536

這裡的elk是啟動elasticsearch的使用者名稱,下同

第二條錯誤是虛擬記憶體參數過小,可以直接執行

sysctl -w vm.max_map_count=655360

指令直接設定vm.max_map_count參數值為655360
也可以直接修改/etc/sysctl.conf 檔案
在檔案最後加上

vm.max_map_count=655360

再執行sysctl -p命令即可。

啟動elasticsearch後,從遠程無法訪問9200連接埠,需要修改elasticsearch.yml檔案,設定network.host為0.0.0.0

# Set the bind address to a specific IP (IPv4 or IPv6):# network.host: 0.0.0.0## Set a custom port for HTTP:##http.port: 9200

同時在CentOS的防火牆上開啟9200連接埠。
重啟elasticsearch後,從遠程機器上執行curl命令

curl http://xxx.xxx.xxx.xxx:9200{  "name" : "QM1a6g-",  "cluster_name" : "elasticsearch",  "cluster_uuid" : "lBAC52_EQzGL6AIUrcdZMg",  "version" : {    "number" : "5.5.1",    "build_hash" : "19c13d0",    "build_date" : "2017-07-18T20:44:24.823Z",    "build_snapshot" : false,    "lucene_version" : "6.6.0"  },  "tagline" : "You Know, for Search"}

即可以從遠端伺服器擷取elasticsearch伺服器的資訊。
如果在elasticsearch.yml檔案中設定bootstrap.memory_lock為true,保證ES啟動時有足夠記憶體,啟動時會檢查失敗

[1]: memory locking requested for elasticsearch process but memory is not locked

需要修改/etc/security/limits.conf檔案,添加下列設定

elk soft memlock unlimitedelk hard memlock unlimited

設定進程可以鎖定在記憶體中的最大資料大小
再修改/etc/sysctl.conf 檔案,添加

vm.swappiness=0

表示最大限度的使用系統記憶體
設定完後重啟系統,再重啟elasticsearch發現問題仍然存在,需要執行ulimit -l unlimited指令後才能啟動成功,但是這條指令在CentOS重啟後失效,最後我修改了
/etc/security/limits.conf檔案為以下形式

* soft nofile 65536* hard nofile 65536* soft memlock unlimited* hard memlock unlimited

對所有域都執行nofile和memlock的設定,重啟系統後再重啟elastichsearch不再出現memlock檢查的問題。

從elasticsearch 5.0開始,elasticsearch不再支援site plugin,因此對es進行查詢的head外掛程式不能再通過elasticsearch-plugin命令安裝,可以通過安裝chrome瀏覽器的elasticsearch-head外掛程式或者單獨運行elasticsearch-head伺服器,指向elasticsearch伺服器的http連接埠。
我安裝head外掛程式的時候參照了下面這篇文章
http://www.cnblogs.com/xing901022/p/6030296.html
使用的nodejs版本為6.11.2,head項目需要的nodejs外掛程式可以通過npm或yarn命令安裝,由於牆的緣故,建議將npm和yarn的registry鏡像改為淘寶鏡像

npm --registry https://registry.npm.taobao.org info underscore yarn config set registry https://registry.npm.taobao.org

使用npm安裝包時,建議使用npm install -g全域安裝,其他上面文章提到的一樣。

在最後在head目錄下執行npm install或者yarn install命令時,會出現下面的錯誤

npm ERR! phantomjs-prebuilt@2.1.14 install: `node install.js`

這時需要單獨安裝phantomjs-prebuilt,執行命令為

npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

參考了
http://blog.csdn.net/txl910514/article/details/55135734這篇文章

使用grunt server啟動head伺服器後,從遠程瀏覽器可以直接對es進行查詢。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.