ElasticSearch head 插件安装

时间:2023-03-09 14:37:22
ElasticSearch head 插件安装

head 客户端可以很方便在上面创建索引,类型,文档,还有查询,使用它管理elasticsearch 提高效率.

在安装head 客户端之前必须安装node.js 环境,因为它是用node.js 编写的.

node.js 安装

在/usr/local/src 下载 : wget https://npm.taobao.org/mirrors/node/v10.8.0/node-v10.8.0-linux-x64.tar.xz

解压 tar -xvf node-v10.8.0-linux-x64.tar.xz

mv node-v6.10.0-linux-x64  /usr/local/nodejs

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

export NODE_HOME=/usr/local/nodejs/node-v10.8.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules

执行 source /etc/profile

然后验证安装是否成功:

[root@localhost ~]# node -v
v10.8.0

安装 grunt

Grunt-cli 只是一个命令行工具

npm install -g grunt-cli
grunt -version

下载 head源码包

wget https://github.com/mobz/elasticsearch-head/archive/master.zip

解压:unzip master.zip

然后进入elasticsearch-head-master 目录

修改elasticsearch-head-master文件下的Gruntfile.js文件中,在options节点下添加一行"hostname: '0.0.0.0',"

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

  

在 elasticsearch-head-master 目录下开始安装

npm install -g cnpm --registry=https://registry.npm.taobao.org

cnpm install

安装成功后,最后修改elasticsearch的elasticsearch.yml

增加参数,使head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*" 具体原因看看github官网的介绍:
连接到elasticsearch
默认情况下,elasticsearch在9200端口上公开一个http rest API, elasticsearch head会连接到该端口。
在elasticsearch启用歌珥
当不作为elasticsearch的插件运行时(版本5中甚至不可能),必须在elasticsearch中启用CORS,否则浏览器会拒绝看起来不安全的请求。
在elasticsearch配置;
添加http.cors。启用:真
您还必须设置http.cors。允许原点,因为默认情况下不允许原点。http.cors。allow-origin:“*”是有效值,但是它被认为是一种安全风险,因为您的集群可以从任何地方跨origin打开。

启动head

在 elasticsearch-head-master 路径下执行

grunt server

(node:3089) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100  

输出上面信息代表已经启动成功了,可以在浏览器上输入地址 http://localhost:9100 访问