介紹
elasticsearch-head是一個用於管理Elasticsearch的web前端插件,搞過ES的同學應該都了解。該插件在es5中可以以獨立服務的形式進行安裝使用。本文將介紹如何操作。
相關鏈接:
操作
Step1, 安裝nodejs和npm
yum -y install nodejs npm
Step2, 下載源碼並安裝
git clone https://github.com/mobz/elasticsearch-head.git cd elasticsearch-head/ npm install
Step3,es配置修改&elasticsearch-head插件源碼修改
① 修改elasticsearch.yml,增加跨域的配置(需要重啟es才能生效)
http.cors.enabled: true http.cors.allow-origin: "*"
② 編輯head/Gruntfile.js,修改服務器監聽地址,增加hostname屬性,將其值設置為*。
以下兩種配置都是OK的
# Type1
connect: { hostname: '*', server: { options: { port: 9100, base: '.', keepalive: true } } }
# Type 2
connect: { server: { options: { hostname: '*', port: 9100, base: '.', keepalive: true } } }
③ 編輯head/_site/app.js,修改head連接es的地址,將localhost修改為es的IP地址
# 原配置
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
# 將localhost修改為ES的IP地址
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://YOUR-ES-IP:9200";
Step4,啟動elasticsearch-head
cd elasticsearch-head/ && ./node_modules/grunt/bin/grunt server
注意:
① 此時elasticsearch-head為前台啟動,如果終端退出,那么elasticsearch-head服務也會隨之關閉。
② 在非elasticsearch-head目錄中啟動server會失敗!因為grunt需要讀取目錄下的Gruntfile.js。
So,你需要將之放到后台進行運行,nohup,&,screen等各種方法請各位隨意選擇~
ps:我會用screen來做類似的操作~
Others
另外,開機啟動、保持持久運行等可以考慮配置rc.local、supervisord等來實現(配置略)
效果