简介

  • elasticsearch-head是一个界面化的集群操作和管理工具,可以对集群进行傻瓜式操作。elasticsearch-head是Elasticsearch的图形化界面,方便用户对数据进行增删改查,基于REST的四种方式进行数据交互。

功能

  • es-head主要有三个方面的操作:
  • 显示集群的拓扑,并且能够执行索引和节点级别操作
  • 搜索接口能够查询集群中原始json或表格格式的检索数据
  • 能够快速访问并显示集群的状态
  • 有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
  • 请求方法(get、put、post、delete),查询json数据,节点和路径
  • 支持JSON验证器
  • 支持重复请求计时器
  • 支持使用javascript表达式变换结果
  • 收集结果的能力随着时间的推移(使用定时器),或比较的结果
  • 能力图表转换后的结果在一个简单的条形图(包括时间序列)

Elasticsearch安装head插件

cd /usr/local/elk

mkdir es-head

上传elasticsearch-head-master.zip

unzip elasticsearch-head-master.zip

# 因为是独立启动head的
chmod 755 /usr/local/elk/es-head
  • 安装node
  • 由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)
  • 官网下载对应版本的node: https://nodejs.org/en/download/.( node-v8.11.1-linux-x64.tar.xz)
  • 下载下来的jar包是xz格式的,一般的linux可能不识别,还需要安装xz.
  • 然后解压nodejs的安装包
  • 解压完node的安装文件后,需要配置下环境变量,编辑/etc/profile
  • source 使配置文件生效。
cd /usr/local/elk

mkdir node

上传node-v8.11.1-linux-x64.tar.xz

# 安装xz
yum -y install xz

# 解压nodejs的安装包:
xz -d node-v8.11.1-linux-x64.tar.xz
tar -xvf node-v8.11.1-linux-x64.tar


# 配置下环境变量,编辑/etc/profile,添加:

vi /etc/profile
# set node environment
export NODE_HOME=/usr/local/elk/node/node-v8.11.1-linux-x64
export PATH=$PATH:$NODE_HOME/bin

# 配置文件生效
source /etc/profile

# 测试node是否安装成功:
[root@node1 elasticsearch-head-master]# node -v
v8.11.1
[root@node1 elasticsearch-head-master]# npm -v
5.6.0
  • 安装grunt
  • grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.0里的head插件就是通过grunt启动的。因此需要安装一下grunt
cd /usr/local/elk/es-head/elasticsearch-head-master/node_modules

# -g 代表全局
npm install -g grunt-cli

返回:
/usr/local/elk/nodejs/node-v8.11.1-linux-x64/bin/grunt -> /usr/local/elk/nodejs/node-v8.11.1-linux-x64/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.2.0
added 16 packages in 6.843s
[root@node1 node_modules]# grunt
grunt-cli: The grunt command line interface (v1.2.0)

Fatal error: Unable to find local grunt.

If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:

http://gruntjs.com/getting-started

返回以上信息,证明安装成功


# 测试
[root@node1 node_modules]# grunt -version
grunt-cli v1.2.0
grunt v1.0.1
  • 修改elasticsearch-head-master源码
cd /usr/local/elk/es-head/elasticsearch-head-master

vi Gruntfile.js

修改服务器监听地址(Gruntfile.js)

connect: {
    server: {
        options: {
            port: 9100,
            hostname: '*',
            base: '.',
            keepalive: true
        }
    }
}

增加这一行:增加hostname属性,设置为*


修改连接地址(app.js)

cd /usr/local/elk/es-head/elasticsearch-head-master/_site

vi 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://172.30.1.45:9200";
  • 修改elasticsearch配置文件,添加:
vi /usr/local/elk/elasticsearch-5.0.0/config/elasticsearch.yml

#elasticsearch配置允许跨域访问,这样head插件可以访问es。
http.cors.enabled: true
http.cors.allow-origin: "*"
  • 运行elasticsearch-head-master
  • 先启动elasticsearch
  • 进入elasticsearch-head-master,执行npm install (可能phantomjs耗时较长)
  • 最后启动nodejs: grunt server