Elasticsearch-head有兩種運(yùn)行方式
1 作為ElasticSearch插件運(yùn)行
執(zhí)行命令
$ elasticsearch/bin/plugin install mobz/elasticsearch-head
然后瀏覽器訪問http://localhost:9200/進(jìn)行查看
2 作為獨(dú)立的webapp運(yùn)行(推薦)
2.1 安裝node.js
兩種方式安裝
- 先安裝摊沉,nvm恰响,即是Node Version Manager(Node版本管理器)
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
#激活nvm
$ source ~/.nvm/nvm.sh
激活完成后稚照,安裝node
$ nvm install node
$ nvm use node
- Node官網(wǎng)下載安裝
http://nodejs.cn/download/
2.2 安裝grunt
grunt是基于Node.js的項(xiàng)目構(gòu)建工具潜支,可以進(jìn)行打包壓縮淘钟、測(cè)試惧所、執(zhí)行等等的工作,head插件就是通過grunt啟動(dòng)
$ cd ./elasticsearch/elasticsearch-head
$ npm install -g grunt-cli
執(zhí)行后會(huì)生成node_modules文件夾锻拘,grunt -version
檢查是否安裝成功油吭。
2.3 安裝Head插件
$ git clone git://github.com/mobz/elasticsearch-head.git
$ cd elasticsearch-head/
$ npm install
修改服務(wù)器監(jiān)聽地址
elasticsearch-head/Gruntfile.js
增加hostname
屬性,設(shè)置為*
connect: {
server: {
options: {
port: 9100,
hostname: '*', # 增加屬性
base: '.',
keepalive: true
}
}
}
修改連接地址
elasticsearch-head/_site/app.js
署拟,把localhost
修改成你es的服務(wù)器地址
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
啟動(dòng)Head插件
$ grunt server
#或
$ npm run start
訪問 http://localhost:9100/婉宰,出現(xiàn)畫面啟動(dòng)成功
3 異常情況
- 連接集群,發(fā)現(xiàn)無論如何點(diǎn)擊都沒有反應(yīng)推穷,還需要在es上進(jìn)行以下設(shè)置心包,開啟跨域訪問支持
./elasticsearch/config/elasticsearch.yml
在最后添加以下三條屬性:
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
重啟Elasticsearch服務(wù)
- elasticsearch安裝x-pack插件之后,head插件就無法使用了馒铃,因?yàn)閤-pack中加入了安全模塊(security機(jī)制)蟹腾,這個(gè)時(shí)候需要在elasticseach.yml中再增加下面一行配置即可解決。
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
在每次使用head插件的時(shí)候区宇,按照如下的格式輸入娃殖,其中auth_user是es的用戶名,auth_password是es的密碼:
http://172.20.1.187:9100/?auth_user=elastic&auth_password=123456