寫在前面
通過查看官方文檔可知,Elasticsearch 5 以上版本已經不支持 site plugins 的方式了,所以 head 需要作為一個單獨的服務進行安裝。
- for Elasticsearch 5.x: site plugins are not supported. Run as a standalone server
- for Elasticsearch 2.x: sudo elasticsearch/bin/plugin install mobz/elasticsearch-head
- for Elasticsearch 1.x: sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head/1.x
- for Elasticsearch 0.x: sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head/0.9
準備工作
我們需要準備以下安裝包
-
elasticsearch-head
-
node
由于head插件本質上還是一個nodejs的工程,因此需要安裝node,使用npm來安裝依賴的包。
安裝
安裝 node
-
安裝 node 需要的基礎環境
yum -y install gcc make gcc-c++ openssl-devel wget
-
解壓 node
cd /opt/es/node tar -zxvf node-v8.1.4-linux-x64.tar.gz
-
配置環境變量
配置NODE_HOME,進入profile編輯環境變量
vim /etc/profile
設置nodejs環境變量,在 export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 一行的上面添加如下內容:
#set for nodejs export NODE_HOME=/opt/es/node/node-v8.1.4-linux-x64 export PATH=$NODE_HOME/bin:$PATH
:wq 保存并退出,編譯/etc/profile 使配置生效
source /etc/profile
驗證是否安裝配置成功
node -v 輸出: v8.1.4 npm -v 輸出:5.0.3
安裝 head
-
解壓 elasticsearch-head-master.zip ,并進入
unzip elasticsearch-head-master.zip cd elasticsearch-head-master
-
執行 npm install
npm install
-
安裝 grunt
grunt 是一個很方便的構建工具,可以進行打包壓縮、測試、執行等工作,5.0里的head插件就是通過grunt啟動的,因此需要安裝 grunt 。
linux:npm install grunt-cli windows:npm install grunt-cli -g
安裝完成后檢查一下
grunt --version 輸出:grunt-cli v1.2.0
修改配置文件
-
修改 Gruntfile.js
路徑:elasticsearch-head-master/Gruntfile.js
增加hostname屬性,設置為*
connect: { server: { options: { port: 9100, hostname: '*', base: '.', keepalive: true } } }
-
修改連接 Elasticsearch 的地址
路徑:elasticsearch-head-master/_site/app.js
修改 localhost:9200 為實際 Elasticsearch 的地址
修改前: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 修改后: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.X.X:9200";
-
修改 Elasticsearch 配置文件
路徑:elasticsearch-5.5.0/config/elasticsearch.yml
增加下面兩個配置
http.cors.enabled: true http.cors.allow-origin: "*"
啟動 head
啟動 head 插件之前,需要先啟動 Elasticsearch 服務
-
直接啟動
grunt server
-
后臺啟動
nohup grunt server
寫在最后
不積跬步,無以至千里,不積小流,無以成江海。
希望自己可以一直堅持下去