上一篇谈到在Ubuntu16.04中安装elasticsearch,这一篇我们来谈谈如何在本地机器中安装elasticsearch-head插件,进行ES可视化管理

环境配置

  • Node JS版本:10.16.0
  • 虚拟机中已经安装好elasticsearch,版本:5.6.8

安装elasticsearch-head

安装NodeJS

elasticsearch-head 是在nodejs环境下运行的,因此必须提前安装好NodeJS,安装教程可参考此篇博客,够详细了:NodeJS 安装及环境配置

安装好后,在cmd命令行中键入

1
node -v

得到如下版本信息,便安装成功

1
2
C:\Users\Administrator>node -v
v10.16.0

安装grunt

运行elasticsearch-head需要借助grunt命令,因此需要安装grunt。打开命令行窗口进入nodejs 安装目录,运行以下命令

1
npm install -g grunt  -cli

如果没有报错就安装成功

1
2
3
4
PS D:\nodejs> npm install -g grunt-cli
D:\nodejs\node_global\grunt -> D:\nodejs\node_global\node_modules\grunt-cli\bin\grunt
+ grunt-cli@1.3.2
added 150 packages from 121 contributors in 23.241s

下载elasticsearch-head

进入网址: https://github.com/mobz/elasticsearch-head 下载整个项目到本地目录下并进行解压,我将解压后的目录放在了D盘

下载ES-head
下载ES-head
解压后的head文件
解压后的head文件

Gruntfile.js 是个配置文件,里面可以配elasticsearch-head在本地的端口

npm安装elasticsearch-head

使用命令行进入elasticsearch-head 目录,执行下述命令

1
npm install

进行npm安装,如果没有报错则安装成功

npm安装
npm安装

如果提示

1
2
3
4
5
6
7
8
9
10
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! D:\nodejs\node_cache\_logs\2020-04-09T15_58_31_720Z-debug.log

这种错误,则先执行以下命令

1
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

安装成功后再执行 npm install,就会发现没有报错了

修改虚拟机中的elasticsearch配置

先将运行中的ES停掉,如果有的话,然后进入编辑虚拟机中的/usr/local/elasticsearch-5.6.8/conf/elasticsearch.yml 文件,添加下述两行代码

1
2
http.cors.enabled: true
http.cors.allow-origin: "*"
  • http.cors.enabled:表示是否支持跨域,默认为false
  • http.cors.allow-origin:当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\/\/localhost(:[0-9]+)?/

编辑完后保存并退出,重新运行虚拟机中的ES

运行elasticsearch-head

上述安装和配置都完成后,在本地主机命令行中键入 grunt server 运行elasticsearch-head,得到如下提示则运行成功

1
2
3
4
PS D:\elasticsearch-head-master> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

此时就可以在浏览器中输入 http://localhost:9100 打开elasticsearch-head
然后在连接栏中输入 虚拟机IP:9200 进行连接,便能连接上虚拟机中的ES

打开ES-head
打开ES-head
连接虚拟机中的ES
连接虚拟机中的ES

完结撒花。