1.下载
windows:https://github.com/mobz/elasticsearch-head
linux:
# wget https://github.com/mobz/elasticsearch-head/archive/v5.0.0.tar.gz
2.解压到指定目录
# tar -zxvf v5.0.0.tar.gz -C ../elk/head/
3.安装nodejs
# 安装node.js:参照:https://blog.csdn.net/qq_19783793/article/details/103501206
4.安装grunt工具
# cd /usr/local/soft/elk/head/elasticsearch-head-5.0.0
# npm install -g grunt --registry=https://registry.npm.taobao.org
# cnpm install -g grunt-cli
5.编译elasticsearch-head源码
# npm install
如果上面的安装太慢,尝试以下方式安装:使用cnpm代替npm编译es-head源码
# sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
# cnpm install
如果报错:✖ Install fail! RunScriptError: post install error, please remove node_modules before retry!
尝试以下操作:
# cd /usr/local/soft/elk/head/elasticsearch-head-5.0.0
# rm -rf node_modules/
# cnpm install gulp-sass --save-dev
# cnpm install
# gulp dev
6.启动head
# npm run start
[root@izbp1c527y2uc9f7yez4g4z elasticsearch-head-5.0.0]# npm run start
> elasticsearch-head@0.0.0 start /usr/local/soft/elk/head/elasticsearch-head-5.0.0
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
7.修改head配置
插件默认是本机的IP才能访问,无法跨域访问head 插件的管理界面,如果需要跨域访问则配置head插件安装目录根目录下的文件Gruntfile.js。
在Gruntfile.js文件中connect --> server --> options下添加hostname: '0.0.0.0',这样就可以跨域访问了
# 1.设置插件管理界面跨域访问
# vim Gruntfile.js
找到:
connect: {
server: {
options: {
port: 9100,
base: '.',
keepalive: true
}
}
}
在options下添加:hostname: '0.0.0.0',
# 保存退出:wq!
# 2.设置head连接的elasticsearch的地址
head插件默认是连接localhost上的elasticsearch,如果需要访问其他主机上的elasticsearch就需要修改head插件安装目录下的_site目录下的app.js文件。
把app.js文件中 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"; 这行配置中的localhost改成你elasticsearch服务的IP地址。
# vim _site/app.js
找到:
init: function(parent) {
this._super();
this.prefs = services.Preferences.instance();
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
// XHR request fails if the URL is not ending with a "/"
this.base_uri += "/";
}
if( this.config.auth_user ) {
var credentials = window.btoa( this.config.auth_user + ":" + this.config.auth_password );
$.ajaxSetup({
headers: {
"Authorization": "Basic " + credentials
}
});
}
将"http://localhost:9200"改成:"http://ip:9200"; # ip代表你的ES主机ip,如:192.168.199.122
#保存退出:wq!
8.修改ES配置
# $ cd /usr/local/soft/elk/elasticsearch/elasticsearch-6.7.2/config/
修改elasticsearch的配置文件,elasticsearch安装目录/config/elasticsearch.yml,打开文件后在末端另起一行分别顶格添加如下两行红色字体文本,保存后重启elasticsearch
# vim elasticsearch.yml
在该文件末尾添加:http.cors.enabled: true 与 http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
9.重启ES,然后启动head
# 重启ES
# ./elasticsearch -d
[root@izbp1c527y2uc9f7yez4g4z _site]# jps
29810 Elasticsearch
30659 Jps
# 重启head (npm run start 或者使用安装过的 grunt server)
# grunt server & -- 后台启动
# 访问ES:http://192.168.199.122:9200/
# 访问Head:http://192.168.199.122:9100/
10.停止head
# ps aux|grep head|grep -v grep
# kill -9 pid