前言
网上相关插件教程我觉得非常混乱,但是机智过人的我还是很快就摸索出了正确答案。
环境:CentOS7
既然你已经安装了ES,那么肯定JDK你也有了,如果没有请点我其他文章进行下载安装。
下面我先简单介绍本次无痛安装需要的工作:
- nodejs(因为head插件是nodejs写的)
- grunt(网上说法是不用grunt说明你就out,但是我身边的前端好像都抛弃它了)
- 安装elasticsearch-head
友情提示:下载安装前,请创建好目录
下载安装NodeJS
下载
通过命令wget https://nodejs.org/dist/v11.1.0/node-v11.1.0-linux-x64.tar.xz
进行下载
如果失败请从官网复制地址进行下载,官网传送门
解压
针对tar.xz文件的解压方法
xz -d ***.tar.xz
tar -xvf ***.tar
完成后长这样
[root@localhost nodejs]# ls
node-v11.1.0-linux-x64 node-v11.1.0-linux-x64.tar
[root@localhost nodejs]# cd node-v11.1.0-linux-x64
[root@localhost node-v11.1.0-linux-x64]# ls
bin CHANGELOG.md include lib LICENSE README.md share
配置环境变量
root用户进入vi /etc/profile
,新增如下内容
export NODE_HOME=/usr/install/nodejs/node-v11.1.0-linux-x64
export PATH=$NODE_HOME/bin:$PATH
export NODE_PATH=$NODE_HOME/lib/node_modules
最后一句好像可以不要的样子,你们可以试试。
使配置生效
source /etc/profile
注意:root用户
检查是否成功
[root@localhost config]# node -v
v11.1.0
下载安装grunt-cli
- 移步到
/node-v11.1.0-linux-x64/bin
下 - 执行
npm init -f
[root@localhost bin]# npm init -f
npm WARN using --force I sure hope you know what you are doing.
Wrote to /usr/install/nodejs/node-v11.1.0-linux-x64/bin/package.json:
{
"name": "bin",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"grunt-cli": "^1.3.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
[root@localhost bin]# ls
node node_modules npm npx package.json package-lock.json
- root用户下执行
npm install grunt-cli -g
[root@localhost bin]# npm install grunt-cli -g
/usr/install/nodejs/node-v11.1.0-linux-x64/bin/grunt -> /usr/install/nodejs/node-v11.1.0-linux-x64/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 152 packages from 117 contributors in 17.057s
[root@localhost bin]# ls
grunt node node_modules npm npx package.json package-lock.json
- 验证
执行grunt
[root@localhost bin]# grunt
grunt-cli: The grunt command line interface (v1.3.2)
下载安装elasticsearch-head
- 执行
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
,如果失败,请到github上获取地址,点击绿色按钮Clone or download再右键DownloadZIP获取链接地址
[root@localhost es-head]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
--2018-11-15 17:28:21-- https://github.com/mobz/elasticsearch-head/archive/master.zip
正在解析主机 github.com (github.com)... 13.229.188.59, 13.250.177.223, 52.74.223.119
正在连接 github.com (github.com)|13.229.188.59|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://codeload.github.com/mobz/elasticsearch-head/zip/master [跟随至新的 URL]
--2018-11-15 17:28:22-- https://codeload.github.com/mobz/elasticsearch-head/zip/master
正在解析主机 codeload.github.com (codeload.github.com)... 13.229.189.0, 13.250.162.133, 54.251.140.56
正在连接 codeload.github.com (codeload.github.com)|13.229.189.0|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:921421 (900K) [application/zip]
正在保存至: “master.zip”
100%[===========================================================================================================================================>] 921,421 52.7KB/s 用时 16s
2018-11-15 17:28:39 (57.9 KB/s) - 已保存 “master.zip” [921421/921421])
[root@localhost es-head]# ls
master.zip
- 解压master.zip
执行unzip master.zip
如果返回找不到指令,说明还没有安装zip和unzip。跟随我执行以下步骤安装
yum -y install zip
、yum -y install unzip
成功后再一次unzip解压master.zip,获得如下所示
[root@localhost es-head]# ls
elasticsearch-head-master master.zip
[root@localhost es-head]# cd elasticsearch-head-master/
[root@localhost elasticsearch-head-master]# ls
Dockerfile elasticsearch-head.sublime-project grunt_fileSets.js LICENCE plugin-descriptor.properties README.textile src
Dockerfile-alpine Gruntfile.js index.html package.json proxy _site test
安装grunt
在elasticsearch-head-master
目录下执行npm install grunt
[root@localhost elasticsearch-head-master]# npm install grunt
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ grunt@1.0.1
removed 4 packages, updated 1 package and audited 1615 packages in 8.826s
found 22 vulnerabilities (16 low, 6 high)
run `npm audit fix` to fix them, or `npm audit` for details
修改配置文件
- 进入
/elasticsearch-head-master/Gruntfile.js
,翻到最后,在options里新增一条hostname: '*'
,如图
connect: {
server: {
options: {
port: 9100,
hostname: '*',
base: '.',
keepalive: true
}
}
}
- 修改
app.js
文件,vi /elasticsearch-head-master/_site/app.js
,找到
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
将其中的localhost替换成你es服务所在ip
由于文件内容很多无法肉眼搜索。在非Insert模式下(进入即非Insert模式,按i进入insert模式,ESC切换),输入/this.base_uri
回车,按小写n向下翻页查找(大写N向上翻页)
如果不修改为ip地址,你在其他主机访问时,连接es地址就会是http://localhost:9200/
。
- 修改 Elasticsearch配置文件
因为es和head属于两个单独的进程,他们之间的访问存在跨域问题所以需要一些跨域的配置。
进入/elasticsearch-6.5.0/config/elasticsearch.yml
新增一下字段
http.cors.enabled: true
http.cors.allow-origin: "*"
启动elasticsearch和head插件
- 到
bin
目录下执行nohup ./elasticsearch &
后台启动,通过tailf -n 100 nohup.out
可查看最后一百条启动信息,看到started
说明成功了。 - 执行
grunt server
或者npm run start
启动head插件或者后台启动nohup grunt server &
,nohup.out日志
会存在你执行命令目录下。
网友评论