一.介绍 head插件
head插件是用node.js开发的所以需要此环境
简单的说 Node.js 就是运行在服务端的 JavaScript。Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型,使其轻量又高效。Node.js 的包管理器 npm,是全球最大的开源库生态系统。
二.下载软件包node.js和head插件:
https://nodejs.org/en/download/
https://github.com/mobz/elasticsearch-head
2.1 上传到服务器指定的目录下如图:
三.解压到指定文件夹以及配置环境变量:
3.1 解压到指定文件夹中:
[root@localhost es-plugs-head]# cp -r /opt/softpackagebyjurf/node-v10.15.3-linux-x64 .
[root@localhost es-plugs-head]# ls
node-v10.15.3-linux-x64[root@localhost es-plugs-head]# cp -r /opt/softpackagebyjurf/elasticsearch-head-master .
[root@localhost es-plugs-head]# ls
elasticsearch-head-master node-v10.15.3-linux-x64
3.2 配置node.js的环境变量
[root@localhost es-plugs-head]# vim /etc/profile #此操作使用root用户操作
export NODE_HOME=/opt/softpackagebyjurf/es-plugs-head/node-v10.15.3-linux-x64
export PATH=$PATH:$NODE_HOME/bin
export NODE_PATH=$NODE_HOME/lib/node_modules
配置后执行:source /etc/profile
[root@localhost es-plugs-head]# source /etc/profile
四.head的插件安装:
进入 elasticsearch-head-master目录 :
#4.1 grunt插件的安装
[root@localhost es-plugs-head]# cd elasticsearch-head-master/
[root@localhost elasticsearch-head-master]# npm install -g grunt-cli
/opt/softpackagebyjurf/es-plugs-head/node-v10.15.3-linux-x64/bin/grunt -> /opt/softpackagebyjurf/es-plugs-head/node-v10.15.3-linux-x64/lib/node_modules/grunt-cli/bin/grunt
added 152 packages from 122 contributors in 17.052s
#4.2 phantomjs 的安装
[root@localhost elasticsearch-head-master]# npm install
npm WARN deprecated [email protected]: Use the built-in module in node 9.0.0 or newer, instead
npm WARN deprecated [email protected]: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
> [email protected] install /opt/softpackagebyjurf/es-plugs-head/elasticsearch-head-master/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /opt/softpackagebyjurf/es-plugs-head/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1555481880343/phantomjs-2.1.1-linux-x86_64 -> /opt/softpackagebyjurf/es-plugs-head/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /opt/softpackagebyjurf/es-plugs-head/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 511 packages from 618 contributors and audited 1751 packages in 24.463s
found 34 vulnerabilities (19 low, 8 moderate, 7 high)
run `npm audit fix` to fix them, or `npm audit` for details
#4.3 给es的执行用户赋予head插件的权限
因为root用户拥有head插件目录的执行权限,现在赋予给es的操作用户elauser也具有head插件目录的操作权限,命令如下:
[root@localhost elasticsearch-head-master]# chown -R elauser:elagroup /opt/softpackagebyjurf/es-plugs-head/
#4.4 置修改Gruntfile.js
[root@localhost elasticsearch-head-master]# vim Gruntfile.js
connect: {
server: {
options: {
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
#4.5 置修改ip地址
修改连接地址:elasticsearch-head-master /_site/app.js
将localhost改为192.168.233.120
#4.6 修改elasticsearch.yml配置文件:(注意键值对后面的“:”加一空格)
http.cors.enabled: true
http.cors.allow-origin: "*"
五.head的启动:
进入elasticsearch-head-master目录下: cd elasticsearch-head-master
5.1 启动grunt server
#执行 grunt server
[root@localhost elasticsearch-head-master]# grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
#后台运行方式 grunt server & 后台启动head插件 (加&设置为后台启动,不加ctrl+c退出时则关闭)
[root@localhost elasticsearch-head-master]# grunt server &
[1] 58893
[root@localhost elasticsearch-head-master]# Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
5.2 启动es
启动es (必须用elauser用户)
[elauser@localhost bin]$ ./elasticsearch -d
[elauser@localhost bin]$ jps
58707 Elasticsearch
58731 Jps
[elauser@localhost bin]$
5.3 页面访问es
本机访问: http://localhost:9100
其他机器访问:http://192.168.233.120:9100
参考:
https://blog.csdn.net/fenglailea/article/details/52934263 node.js npm grunt安装,elasticsearch-head 5.X安装
https://blog.csdn.net/qq_36697880/article/details/83011578 Linux安装elasticsearch6.X的head插件
六.自定义启动和关闭脚本程序:
6.1 自定义后台启动和关闭的脚本程序
ps -ef |grep grunt|awk '{print $2}'|sed -n '1p' |xargs kill -9
'{print $2}':表示每行的第二列
sed -n '1p' :多条数据,只取第一行,即第一条数据。
6.2 自定义启动脚本es-head-start.sh的内容:
#!/bin/bash
echo "START elasticsearch-head "
nohup grunt server &
exit
6.3 自定义启动脚本es-head-stop.sh的内容:
#!/bin/bash
echo "STOP elasticsearch-head "
ps -ef |grep grunt|awk '{print $2}'|sed -n '1p' |xargs kill -9
6.4 脚本执行:[root@localhost elasticsearch-head-master]# sh es-head-start.sh