前面講完了ELK的應用,我們可以通過curl命令或者java或python的request命令,或者kibana的開發面板對ES的數據直接操作,本篇介紹一個輕量又好用的插件:es-head。
ELK系列(一)、安裝ElasticSearch+Logstash+Kibana+Filebeat-v7.7.0
ELK系列(二)、在Kibana中使用RESTful操作ES庫
ELK系列(四)、Logstash讀取nginx日誌寫入ES中
ELK系列(五)、Logstash修改@timestamp時間爲日誌的產生時間
ELK系列(六)、修改Nginx日誌爲Json格式並使用Logstash導入至ES
ELK系列(七)、Filebeat+Logstash採集多個日誌文件並寫入不同的ES索引中
ELK系列(八)、使用Filebeat+Redis+Logstash收集日誌數據
ELK系列(十)、ES中文分詞器IK插件安裝和配置遠程詞庫熱加載
-------------------------------------ElasticSearch插件es-head安裝及使用-------------------------------------
環境準備
CentOS7
ElasticSearchv7.7.0
Nodejs
es-head需要nodejs環境編譯,先看看機器中是否已經有nodejs環境,如果沒有的話我們先要安裝nodejs環境:
nodjs官網:https://nodejs.org/en/download/
我下載的最新版v12.17:https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.xz
解壓安裝nodejs:
#解壓
tar xvJf node-v12.17.0-linux-x64.tar.xz
#配置環境變量
mv node-v12.17.0-linux-x64 /opt/app/
vim /etc/profile
#新增下面的內容
export NODE_HOME=/opt/app/node-v12.17.0-linux-x64
export PATH=$JAVA_HOME/bin:$NODE_HOME/bin:$PATH
#刷新環境變量
source /etc/profile
測試node命令:
node -v
自此,需要的環境已準備完畢,下面開始安裝es-head插件。
下載
地址:https://github.com/mobz/elasticsearch-head
可使用git命令在線下載,或者下載zip包之後,離線安裝都可以。
使用git命令下載:
git clone https://github.com/mobz/elasticsearch-head.git
下載zip包並解壓:
https://github.com/mobz/elasticsearch-head/archive/master.zip
unzip elasticsearch-head-master.zip
編譯安裝
安裝
進入目錄執行npm命令安裝:
cd elasticsearch-head-master/
npm install
修改npm源
如果npm install一直卡在fetchMetadata: sill 不動的話,是因爲訪問的npm registry網絡不行,我們可以修改爲淘寶的倉庫:
#查看npm倉庫
npm config get registry
#或
npm info express
#修改爲淘寶的源
npm config set registry https://registry.npm.taobao.org
這時候再執行npm install 速度就快很多了,這時候出現這個錯誤:
> [email protected] install /home/wyk/elasticsearch-head-master/node_modules/phantomjs-prebuilt
> node install.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module '/home/wyk/elasticsearch-head-master/node_modules/phantomjs-prebuilt/install.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
...
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-27T03_40_09_380Z-debug.log
忽略[email protected]
修改安裝命令再安裝就行了,出現下面的結果就是安裝成功了:
npm install [email protected] --ignore-scripts
啓動驗證
配置ES:
vim $ES_HOME/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
修改完ES配置重啓ES後,在es-head目錄下使用下面的命令啓動es-head:
npm run start
根據提示,我們訪問http://wykd:9100 看看效果,已成功啓動並訪問我們的ES集羣:
es-head使用密碼訪問ES
前面我們介紹過,推薦大家的ES開啓安全認證,那麼es-head怎麼訪問開啓了XPACK安全認證的ES集羣呢? 把集羣修改其中一項配置然後重啓ES集羣:
vim $ES_HOME/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
#http.cors.allow-headers: Authorization #這個配置改爲下面的
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
使用下面的路徑訪問帶有XPACK安全認證的ES集羣,密碼改爲自己的即可:
http://wykd:9100/?auth_user=elastic&auth_password=123456
希望本文對你有幫助,請點個贊鼓勵一下作者吧~ 謝謝!