一,介绍

elasticsearch head 是一款开源的可视化的elasticsearch可视化工具,使用相当方便和广泛。

这个插件安装比较简单,网上已经有写得比较好的文章了

安装方式有4种,我也选择的是源码安装。

源码安装,通过npm run start启动
通过docker安装
通过chrome插件安装
通过ES的plugin方式安装

其实docker安装应该更好用,有兴趣的可以参考

https://jingyan.baidu.com/article/c1465413d7bd7a0bfdfc4c50.html


环境说明:

本文记录博主自己的安装步骤,以备今后查验。

操作系统版本:Red Hat Enterprise Linux release 8.2 (Ootpa)

二,安装步骤:

2.1,nodejs及npm安装

head是一个Node.js项目,所以需要先安装Node.js才可以运行head。安装了Node.js后,安装需要用到的npm命令就自带安装上了。

注意从这里开始要使用root用户。下载Nodejs:

Download | Node.jsNode.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.https://nodejs.org/en/download/

当前最新的版本是16.17.0

es安装ik smart es head安装_elasticsearch

如果操作系统版本低的话可以选择低一些的版本,例如14.20.0

下滑到下载页面的底部:

 

es安装ik smart es head安装_elasticsearch_02

所有版本的下载列表:Index of /dist/


https://nodejs.org/dist/

上传下载的安装包,然后解压:

#xz -dk node-v16.17.0-linux-x64.tar.xz

#tar -xvf node-v16.17.0-linux-x64.tar

es安装ik smart es head安装_html_03

执行node命令 查看版本:

[root@goya1 bin]# ./node -v
v16.17.0

解压文件的 bin 目录底下包含了 node、npm 等命令,我们可以使用 ln 命令来设置软连接:
ln -s /app/nodejs/bin/npm /usr/local/bin/
ln -s /app/nodejs/bin/node /usr/local/bin/
设置npm镜像为国内的
npm config set registry http://registry.npm.taobao.org

可以通过输入npm命令来验证是否生效。

es安装ik smart es head安装_es安装ik smart_04

 2.2,elasticsearch-head安装

GitHub - mobz/elasticsearch-head: A web front end for an elastic search clusterA web front end for an elastic search cluster. Contribute to mobz/elasticsearch-head development by creating an account on GitHub.https://github.com/mobz/elasticsearch-head

通过上面的连接下载安装包,然后将安装包上传到服务器。解压到目录/app/head-master

es安装ik smart es head安装_es安装ik smart_05

进入/app/head-master目录,执行npm install命令。

es安装ik smart es head安装_es安装ik smart_06

有错误产生,Nodejs版本过高。重新下载降级版本node-v14.20.0-linux-x64.tar来安装,成功通过。

es安装ik smart es head安装_html_07

也有另外一种解决办法就是安装phantomjs-prebuilt的2.1.14版本。读者可以自行测试。

es安装ik smart es head安装_elasticsearch_08

运行elasticsearch-head:

 

es安装ik smart es head安装_es安装ik smart_09

使用elasticsearch-head:(说明:这里我连接是由3台ES节点组成的ES集群,且ES启用了x-pack,也就是需要用户名和密码访问)

es安装ik smart es head安装_html_10

这里其实无法连接到elasticsearch, 还需要解决跨域问题: 

2.3,配置跨域访问:
由于前后端分离开发,所以会存在跨域问题,需要在服务端做CORS的配置,如下:
vim elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true
http.cors.allow-headers: Content-Type,Accept,Authorization,x-requested-with
#http.cors.allow-headers: "*"
配置完,后重启服务端程序。
cd bin 
./elasticsearch 或 ./elasticsearch -d #后台启动

错误处理1:Access to XMLHttpRequest at xxx has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

es安装ik smart es head安装_解决方法_11

es安装ik smart es head安装_解决方法_12

同源策略禁止读取位于 http://localhost:9200/_cluster/health 的远程资源。解决方法:在elasticsearch.yml中增配置内容如下: 
http.cors.allow-headers: Content-Type,Accept,Authorization, x-requested-with 

或者http.cors.allow-headers: "*"

错误2:vendor.js: GET https://:9200/ 401 (Unauthorized)。ES启用了X-pack,但是在elasticsearch-head 连接时提示401无权限访问。

es安装ik smart es head安装_html_13


解决方法1(不推荐):修改ES配置文件,关闭x-pack功能,在elasticsearch.yml文件,添加如下一行内容:xpack.security.enabled: false

解决方法2:从head-master端解决。

2.4,配置head master 到 elasticsearch的加密访问。

如何从head-master这边解决是作者花了两天时间都没有办法解决的问题,感谢万能的网络,最后找到了解决办法。思路就是带密码访问加密的ES。在输入elasticsearch-head访问地址时输入auth_user和auth_password两个变量值,如下图所示:

http://192.168.88.5:9100/?base_uri=https://192.168.88.5:9200&auth_user=elastic&auth_password=123456

es安装ik smart es head安装_es安装ik smart_14

三,其他技巧

3.1,设置master head需要用户名和密码登录。保障elasticsearch-head的访问安全。