elasticsearch-head插件安裝

什麼是elasticsearch-head

ElasticSearch Head是集羣管理、數據可視化、增刪查改、查詢語句可視化工具,提供了一個直觀訪問ES庫的方式。

elasticsearch-head有哪些主要功能

1、方便的查看集羣狀態,包括有多少個replication,多少個shared 2、查看索引的狀態 3、可以直接瀏覽數據 4、提供便捷的查詢方式,通過選擇的方式查詢 5、提供rest api方式的查詢

elasticsearch-head網上流傳的安裝方式

1、一種是通過elasticsearch本身的插件集成進行安裝 2、 利用npm和nodejs進行安裝啓動,github中給出的安裝方法也是這種,本文就是以這種方式進行解說

安裝

1、下載head插件

wget  https://github.com/mobz/elasticsearch-head/archive/master.zip
[root@oa3 other]# wget  https://github.com/mobz/elasticsearch-head/archive/master.zip
--2018-10-26 08:51:55--  https://github.com/mobz/elasticsearch-head/archive/master.zip
正在解析主機 github.com (github.com)... 192.30.253.112, 192.30.253.113
正在連接 github.com (github.com)|192.30.253.112|:443... 已連接。
已發出 HTTP 請求,正在等待迴應... 302 Found
位置:https://codeload.github.com/mobz/elasticsearch-head/zip/master [跟隨至新的 URL]
--2018-10-26 08:51:57--  https://codeload.github.com/mobz/elasticsearch-head/zip/master
正在解析主機 codeload.github.com (codeload.github.com)... 192.30.253.120, 192.30.253.121
正在連接 codeload.github.com (codeload.github.com)|192.30.253.120|:443... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:921421 (900K) [application/zip]
正在保存至: “master.zip”

100%[======================================================================================================================================================================================>] 921,421      171KB/s 用時 5.3s   

2018-10-26 08:52:03 (171 KB/s) - 已保存 “master.zip” [921421/921421])

2、解壓下載好的head

unzip master.zip

解壓成功後,安裝目錄下會多出如下文件夾

drwxr-xr-x.  6 root          root            4096 9月  15 2017 elasticsearch-head-master

3、安裝nodejs

wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
[root@oa3 other]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
--2018-10-26 09:01:42--  https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
正在解析主機 npm.taobao.org (npm.taobao.org)... 114.55.80.225
正在連接 npm.taobao.org (npm.taobao.org)|114.55.80.225|:443... 已連接。
已發出 HTTP 請求,正在等待迴應... 302 Found
位置:http://cdn.npm.taobao.org/dist/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz [跟隨至新的 URL]
--2018-10-26 09:01:42--  http://cdn.npm.taobao.org/dist/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
正在解析主機 cdn.npm.taobao.org (cdn.npm.taobao.org)... 182.106.155.235, 182.106.155.232, 182.106.155.233, ...
正在連接 cdn.npm.taobao.org (cdn.npm.taobao.org)|182.106.155.235|:80... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:12189839 (12M) [application/octet-stream]
正在保存至: “node-v4.4.7-linux-x64.tar.gz”

100%[======================================================================================================================================================================================>] 12,189,839  4.04MB/s 用時 2.9s   

2018-10-26 09:01:45 (4.04 MB/s) - 已保存 “node-v4.4.7-linux-x64.tar.gz” [12189839/12189839])

4、解壓nodejs安裝包

tar -zxvf node-v4.4.7-linux-x64.tar.gz

5、配置nodejs環境變量

vim /etc/profile

加入如下內容

export NODE_HOME=/oa/other/node-v4.4.7-linux-x64
export PATH=$PATH:$NODE_HOME/bin

執行

source /etc/profile

查看nodejs環境變量,是否配置成功

echo $NODE_HOME

控制檯輸出

/oa/other/node-v4.4.7-linux-x64

6、安裝grunt

grunt是基於Node.js的項目構建工具,可以進行打包壓縮、測試、執行等等的工作,head插件就是通過grunt啓動

cd /oa/other/elasticsearch-head-master/
npm install -g grunt-cli

查看是否安裝成功

grunt -version

控制檯輸出

grunt-cli v1.3.1

7、安裝依賴

切換進入elasticsearch-head-master目錄。如果你的網速較快,可以使用這個命令

npm install

不然推薦使用國內鏡像

npm install -g cnpm --registry=https://registry.npm.taobao.org

注:如果使用npm install命令出現

npm ERR! [email protected] install: `node install.js`

則再次運行

npm install [email protected] --ignore-scripts

即可

注:如果使用國內鏡像安裝,當運行grunt server,出現

grunt-cli: The grunt command line interface (v1.3.1)

Fatal error: Unable to find local grunt.

If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:

https://gruntjs.com/getting-started

則運行

npm install -g grunt

即可

相關配置文件修改

1、修改Elasticsearch配置文件

在elasticsearch.yml文件,添加支持跨域訪問

http.cors.enabled: true
http.cors.allow-origin: "*"

2、修改Gruntfile.js

修改 elasticsearch-head-master/Gruntfile.js,在connect屬性中,增加hostname: ‘0.0.0.0’

vim Gruntfile.js

修改爲

connect: {
        server: {
            options: {
                hostname: '0.0.0.0',
                port: 9107,
                base: '.',
                keepalive: true
            }
        }
    }

:端口可以任意

3、修改連接地址(可選)

修改 elasticsearch-head-master/_site/app.js

注:esIP:esPort 爲elasticsearch爲es的連接地址,諸如:192.168.1.1:9200

啓動elasticsearch-head

cd elasticsearch-head-master
grunt server

控制檯輸出

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9107

elasticsearch-head設置後臺啓動與關閉

啓動

直接用

grunt server

這種方式啓動,當ssh終端關閉或者執行ctrl+c命令時,head就關閉了。

所以可以執行如下命令,讓head在後臺運行

cd elasticsearch-head-master
nohup grunt server  > /dev/null 2>&1 &

關閉

網傳的後臺關閉是用

ps -ef |grep head
然後執行
kill -9 進程號

但我試過了不管用。其實head的啓動用是基於grunt啓動,只要找出grunt進程,然後關閉進程號就行

[root@oa3 elasticsearch-head-master]# ps -ef | grep grunt
root     11622     1  1 14:17 ?        00:00:05 grunt
root     12097 11964  0 14:26 pts/1    00:00:00 grep --color=auto grunt
[root@oa3 elasticsearch-head-master]# kill -9 11622

當然上面的啓動關閉可以做成shell腳本,方便執行。具體腳本就不提供了,很簡單的,比如關閉後臺的head,其shell腳本爲:

ps -ef |grep grunt|awk '{print $2}'|xargs kill -9

最後展示一下head頁面

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章