http://blog.csdn.net/tanga842428/article/details/76161461 (Elasticsearch 集羣管理工具head安裝)
http://blog.csdn.net/q15150676766/article/details/76039270 ( ElasticSearch學習Head的安裝)
1、環境準備
下載nodejs
nodejs官網下載地址https://nodejs.org/dist/
[root@localhost data]# wget https://nodejs.org/dist/v6.11.2/node-v6.11.2-linux-x64.tar.xz
2、配置node環境變量
[root@node1 data]# xz -d node-v6.11.2-linux-x64.tar.xz
[root@node1 data]# tar -xvf node-v6.11.2-linux-x64.tar -C /usr/local/
[root@node1 data]# cd ~
[root@node1 ~]# ln -s /usr/local/node-v6.11.2-linux-x64/bin/node /usr/bin/node
[root@node1 ~]# ln -s /usr/local/node-v6.11.2-linux-x64/bin/npm /usr/bin/npm
[root@node1 ~]# node -v
v6.11.2
[root@node1 ~]# npm -v
3.10.10
[root@node1 ~]#
或者:
root@node1 data]# vim /etc/profile 添加如下2行
export NODE_HOME=/usr/local/node-v6.11.2-linux-x64
export PATH=$PATH:$NODE_HOME/bin
root@node1 data]# source /etc/profile
[root@node1 data]# node -v
v6.11.2
[root@node1 data]# npm -v
3.10.10
4、安裝grunt
如果生產環境無法聯網在線安裝grunt,可以找一臺能聯網的主機配置好node,安裝好grunt後將elasticsearch-head目錄下的node_models打包上傳
[root@node1 ~]# npm install -g grunt-cli #執行命令後顯示如下:
/usr/local/node-v6.11.2-linux-x64/bin/grunt -> /usr/local/node-v6.11.2-linux-x64/lib/node_modules/grunt-cli/bin/grunt
/usr/local/node-v6.11.2-linux-x64/lib
│ └─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
│ └── [email protected]
再關聯下grunt
[root@node1 ~]# ln -s /usr/local/node-v6.9.5-linux-x64/lib/node_modules/grunt-cli/bin/grunt /usr/bin/grunt
grunt是一個方便的構建工具,可以進行打包壓縮、測試、執行等等的工作,5.x裏的head插件就是通過grunt啓動的;
#”-g”參數代表全局安裝,一般安裝到nodejs的”lib/node_modules”目錄下;不帶參數”-g”,則是本地安裝,一般安裝到運行npm命令時所在的目錄,這裏就需要安裝到head插件目錄;
#爲grunt命令建軟鏈接,方便全局執行,或加入環境變量;;
#如果鏡像速度不理想,可提前切到國內的鏡像,在安裝grunt-cli前執行:npm config set registry https://registry.npm.taobao.org。
5、 下載elasticsearch-head
[root@node1 ~]# cd /usr/local
[root@node1 local]# git clone git://github.com/mobz/elasticsearch-head.git
[root@node1 local]# cd elasticsearch-head/
[root@node1 elasticsearch-head]# npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] license should be a valid SPDX license expression
發現有3個警告信息,忽略即可,其中“npm WARN [email protected] license should be a valid SPDX license expression”警告信息可做如下處理:http://www.itdadao.com/articles/c15a1031952p0.html
即修改”./ elasticsearch-head”目錄下“package.json”文件第19行的”"Apache2" “爲"Apache-2.0",涉及到開源軟件與其他合作類軟件的使用聲明。
#如果沒有全局安裝grunt二進制程序,可在”elasticsearch-head”目錄下執行”npm install grunt --save“ 或 ”npm install grunt-cli“。
6、配置head文件
[root@node1 elasticsearch-head]# cd _site/
[root@node1 _site]# cp app.js app.js.bak
[root@node1 _site]# vim app.js
#在4330行將原"http://localhost:9200"修改爲"http://10.129.11.86:9200",否則head插件不能獲取節點狀態信息。
[root@node1 elasticsearch-head]# cp Gruntfile.js Gruntfile.js.bak
[root@node1 elasticsearch-head]# vim Gruntfile.js
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
# 在93行新增”hostname: '0.0.0.0', “,確保能被訪問。
7、重啓elasticsearch,並啓動node 且驗證,
[root@node1 elasticsearch-head]# nohup node_modules/grunt/bin/grunt server &exit
#啓動head插件,需要到elasticsearch-head目錄下
如果想關閉head插件,使用Linux查找進程命令:
ps aux|grep head
結束進程:
kill 進程號