0.环境需要
系统搭载的是centos6.8,已经部署好elasticsearch
(es安装参考本人帖子https://blog.csdn.net/qq_39626154/article/details/81939440)
node.js
官网下载地址https://nodejs.org/en/download/
下载源码包放在/opt/下
一、安装配置node
解压源码包node-v8.11.4-linux-x64.tar.xz并移到安装目录/usr/local/node
[root@localhost opt]# xz -d node-v8.11.4-linux-x64.tar.xz
[root@localhost opt]# tar xf node-v8.11.4-linux-x64.tar
[root@localhost opt]# mv node-v8.11.4-linux-x64 /usr/local/node
修改系统环境变量参数
[root@localhost opt]# vim /etc/profile
文件内容末尾增加:
#set for nodejs
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
声明系统环境变量
[root@localhost opt]# source /etc/profile
查看node版本
[root@localhost opt]# node -v
v8.11.4
二、下载安装elastichsearch-head插件
1.地址:https://github.com/mobz/elasticsearch-head
2.安装git :yum -y install git
3.clone elasticsearch-head: git clone https://github.com/mobz/elasticsearch-head.git
到elasticsearch-head目录下, 执行npm install 命令, 执行该命名可能会出现以下错误:
[root@localhost elasticsearch-head]# npm install
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! /root/.npm/_logs/2018-08-27T08_46_50_939Z-debug.log
此时忽略phantomjs-prebuilt@2.1.16,执行命令如下
[root@localhost elasticsearch-head]# npm install phantomjs-prebuilt@2.1.16 --ignore-scripts
三、启动elastichsearch-head
[root@localhost elasticsearch-head]# npm run start
> elasticsearch-head@0.0.0 start /usr/local/elasticsearch-head
> grunt server
>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
(node:3685) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
验证elasticsearch-head,在浏览器中输入主机地址和端口
四、连接没响应问题解决
当重启服务器之后发现依旧如上图, 还是无法正常连接到elasticsearch服务,这是因为elasticsearch服务与elasticsearch-head之间可能存在跨越,修改elasticsearch配置即可,在elastichsearch.yml中添加如下命名即可:
#allow origin
http.cors.enabled: true
http.cors.allow-origin: "*"
修改后重启elasticsearch
重新连接可看到连接上了