elasticsearch-head安装
Node.js环境安装
head插件要求Node.js环境,并且Node.js的版本 大于等于 6.0。
下载 Node.js 12.13.0 版本。下载地址:https://nodejs.org/en/download/
配置nodejs环境变量
vim /etc/profile
export NODE_HOME=/home/tom/data/node-v10.15.3-linux-x64
export PATH=$NODE_HOME/bin:$PATH
执行命令 source /etc/profile 使上面的配置生效。然后执行 npm -v,看到输出 6.11.3
head插件安装
在GitHub上找到head插件,地址:https://github.com/mobz/elasticsearch-head
cd /opt/server
unzip elasticsearch-head-master.zip
mv elasticsearch-head-master elasticsearch-head
安装插件;由于需要下载一些依赖包,所以会比较慢。
cd 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.
手动安装phantomjs-prebuilt
npm install phantomjs-prebuilt@2.1.16 --ignore-scripts
重新执行“npm install”
启动head插件
nohup npm run start &
浏览器打开“http://172.16.11.146:9100”,
浏览器报错
Access to XMLHttpRequest at 'http://172.16.11.146:9200/_nodes/stats' from origin 'http://172.16.11.146:9100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这个问题是因为ES和head插件存在一个跨域问题。要解决这个问题,我们需要首先关闭Elasticsearch,然后添加两行配置:
http.cors.enabled: true
http.cors.allow-origin: "*"
然后,重新启动ES,刷新 head 插件页面,即可看到现在head插件已经正确查找到了我们的启动那个ES节点