使用ES的基本都会使用过head,可是版本升级到5.0后,head插件就很差使了。下面就看看如何在5.0中启动Head插件吧!html
Running with built in servernode
enable cors by adding http.cors.enabled: true in elasticsearch configuration. Don’t forget to also set http.cors.allow-origin because no origin allowed by default. http.cors.allow-origin: "*" is valid value, however it’s considered as a security risk as your cluster is open to cross origin from anywhere.linux
Check Elasticsearch documentation on this parameter:git
git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install grunt server
open http://localhost:9100/
This will start a local webserver running on port 9100 serving elasticsearch-headgithub
Best option if you are likely to connect to several different clustersweb
5.0版本的ES跟以前的版本最大的不一样之处就是多了不少环境的校验,好比jdk,max-files等等。npm
vi /etc/sysctl.conf # 增长下面的内容 fs.file-max=65536 vm.max_map_count=262144
#sysctl -p使其生效json
vi /etc/security/limits.conf # 修改 * soft nofile 32768 * hard nofile 65536 user nofile 65536 user as unlimited user hard nproc 2048 #从新登录便可生效
ulimit -u 2048
修改一下es使用的参数:服务器
# 换个集群的名字,省得跟别人的集群混在一块儿 cluster.name: es-5.0-test # 换个节点名字 node.name: node-101 # 修改一下ES的监听地址,这样别的机器也能够访问 network.host: 0.0.0.0 # 默认的就好 http.port: 9200 # 增长新的参数,这样head插件能够访问es http.cors.enabled: true http.cors.allow-origin: "*"
须要从github上面下载代码,所以先要安装gitapp
yum -y install git
安装完成后,就能够直接下载代码了:
git clone git://github.com/mobz/elasticsearch-head.git
下载后,修改下777权限(简单粗暴),由于是独立启动head的,因此随便放一个位置就好了,参考:
/usr/elk/head/*****
因为head插件本质上仍是一个nodejs的工程,所以须要安装node,使用npm来安装依赖的包。(npm能够理解为maven)
去官网下载nodejs,https://nodejs.org/en/download/
下载下来的jar包是xz格式的,通常的linux可能不识别,还须要安装xz.
yum -y install xz
而后解压nodejs的安装包:
xz -d node*.tar.xz tar -xvf node*.tar
解压完node的安装文件后,须要配置下环境变量,编辑/etc/profile,添加
# set node environment export NODE_HOME=/usr/elk/node-v6.9.1-linux-x64 export PATH=$PATH:$NODE_HOME/bin
别忘记当即执行如下
source /etc/profile
这个时候能够测试一下node是否生效:
[root@localnode1 node-v6.9.1-linux-x64]# echo $NODE_HOME /usr/elk/node-v6.9.1-linux-x64 [root@localnode1 node-v6.9.1-linux-x64]# node -v v6.9.1 [root@localnode1 node-v6.9.1-linux-x64]# npm -v 3.10.8
grunt是一个很方便的构建工具,能够进行打包压缩、测试、执行等等的工做,5.0里的head插件就是经过grunt启动的。所以须要安装一下grunt:
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node /usr/bin/node
#创建软链接,不然root找不到npm
npm init
#生成package.json不然报错 sudo npm install -g grunt-cli
安装完成后检查一下:
[root@localnode1 elasticsearch-head]# grunt -version grunt-cli v1.2.0 grunt v0.4.5
因为head的代码仍是2.6版本的,直接执行有不少限制,好比没法跨机器访问。所以须要用户修改两个地方:
目录:head/Gruntfile.js
connect: { server: { options: { port: 9100, hostname: '*', base: '.', keepalive: true } } }
增长hostname属性,设置为*
目录:head/_site/app.js
修改head的链接地址:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
把localhost修改为你es的服务器地址,如:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.10.10.10:9200";
首先开启5.0 ES。
而后在head目录中,执行npm install 下载以来的包:
npm install
最后,启动nodejs
grunt server
这个时候,访问http://xxx:9100
就能够访问head插件了.