ubuntu安装ElasticSearch-head插件

插件安装

1、下载插件(默认你已经安装git):

git clone https://github.com/mobz/elasticsearch-head.git

2、检查是否安装node

node -v

在这里插入图片描述

如果没有安装:先安装python:

#sudo apt-get install python-software-properties
# apt install nodejs-legacy

在这里插入图片描述

手动下载执行脚本文件:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

在这里插入图片描述

安装nodejs

sudo apt-get install nodejs

在这里插入图片描述

输入命令安装elasticsearch所需的依赖包:

npm install

依赖安装完后,需要修改一个文件才能连上head插件

vim config/elasticsearch.yml

在后面添加以下内容:

http.cors.enabled: true
http.cors.allow-origin: "*"

输入命令启动head插件

npm run start

在这里插入图片描述

扩展

安装npm

[root@node1 ~]#  npm install -g cnpm --registry=https://registry.npm.taobao.org

在这里插入图片描述
使用npm安装grunt

root@node1 ~]# npm install -g grunt

在这里插入图片描述
下载依赖
进入elasticsearch-head-master目录,执行下面命令

[es@node1 elasticsearch-head-master]$ npm install

注意 : 过程很漫长
在这里插入图片描述
如果上面命令安装较慢或失败,可以尝试国内镜像安装

#npm install -g cnpm --registry=https://registry.npm.taobao.org

$ cnpm install

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
停止ElasticSearch
如果ElasticSearch已经启动,需要先停止

[es@node1 ~]$ jps
3261 Elasticsearch
3375 Jps
[es@node1 ~]$ kill 3261

(1)配置 ElasticSearch,使得HTTP对外提供服务

[es@node1 elasticsearch-6.1.1]$ vi config/elasticsearch.yml

添加如下内容

# 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格
http.cors.enabled: true
http.cors.allow-origin: "*"

(2)修改Head插件配置文件

$ vi Gruntfile.js

找到connect:server,添加hostname一项,如下

connect: {
                        server: {
                                options: {
                                        hostname: '0.0.0.0',
                                        port: 9100,
                                        base: '.',
                                        keepalive: true
                                }
                        }
                }

启动
(1)启动elasticsearch
首先确认elasticsearch已经启动

[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
[es@node1 elasticsearch-6.1.1]$ jps
3451 Jps
3436 Elasticsearch
[es@node1 elasticsearch-6.1.1]$

(2)启动head
通过命令grunt server启动head

[es@node1 elasticsearch-head-master]$ grunt server
需要在head的目录下运行
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://node1:9100

或者通过命令npm run start也可以启动head

[es@node1 elasticsearch-head-master]$ npm run start
> elasticsearch-head@0.0.0 start /home/es/elasticsearch-head-master
> grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://node1:9100

(3)访问9100端口
http://10.105.45.32:9100/
在这里插入图片描述
如果出现“未连接”,请修改localhost为node1,然后单击“连接”按钮
在这里插入图片描述
** 简单应用**
(1)创建索引

[root@node1 ~]# curl -XPUT node1:9200/test
{"acknowledged":true,"shards_acknowledged":true,"index":"test"}[root@node1 ~]# 

**(2)查看head变化 **
在这里插入图片描述

常见问题

1、npm run start报错,端口被占用
卧槽,又他妈报错,心态有点崩啊。好吧,9100端口被占用,查找进程,杀死。再一看,卧槽?又复活了?杀不死?好吧,我换端口。

vim Gruntfile.js

找到port,修改为一个没有被占用的端口就ok啦。然后就可以访问head了,显示集群健康
在这里插入图片描述
2、npm run start安装报错
1、npm WARN Local package.json exists, but node_modules missing, did you mean to install?
翻译 :npm WARN本地package.json存在,但缺少node_modules,您是要安装吗?
2、This is probably not a problem with npm. There is likely additional logging output above.
翻译 : npm可能不是问题。 上面可能还有其他日志记录输出。

root@jnydjky:/optlim/elasticsearch-6.2.3/elasticsearch-head# npm run start

> elasticsearch-head@0.0.0 start /optlim/elasticsearch-6.2.3/elasticsearch-head
> grunt server

sh: 1: grunt: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! elasticsearch-head@0.0.0 start: `grunt server`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the elasticsearch-head@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-04-26T07_52_29_766Z-debug.log

在这里插入图片描述
翻译
在这里插入图片描述
报错原因安装错的head组件 ,正常地址:https://github.com/mobz/elasticsearch-head/archive/master.zip
解决办法 :
查看elasticsearch日志

root@jnydjky:/var/log# cd elasticsearch/
root@jnydjky:/var/log/elasticsearch# ls
/var/log/elasticsearch# cat elasticsearch.log

在这里插入图片描述
在这里插入图片描述
没有发现报错;

3、报错信息 :
1 package is looking for funding
run npm fund for details

found 44 vulnerabilities (20 low, 2 moderate, 22 high)
run npm audit fix to fix them, or npm audit for details
root@jnydjky:/optlim/elasticsearch-6.2.3/elasticsearch-head# npm install grunt
在这里插入图片描述

root@jnydjky:/optlim/elasticsearch-6.2.3/elasticsearch-head# npm fund
elasticsearch-head@0.0.0
├─┬ resolve@1.17.0
│ └── url: https://github.com/sponsors/ljharb
├─┬ is-finite@1.1.0
│ └── url: https://github.com/sponsors/sindresorhus
└─┬ glob@7.1.6
  └── url: https://github.com/sponsors/isaacs

在这里插入图片描述

# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy

[root@node1 ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
/usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt
/usr/lib
└─┬ grunt-cli@1.2.0 
  ├─┬ findup-sync@0.3.0 
  │ └─┬ glob@5.0.15 
  │   ├─┬ inflight@1.0.6 
  │   │ └── wrappy@1.0.2 
  │   ├── inherits@2.0.3 
  │   ├─┬ minimatch@3.0.4 
  │   │ └─┬ brace-expansion@1.1.8 
  │   │   ├── balanced-match@1.0.0 
  │   │   └── concat-map@0.0.1 
  │   ├── once@1.4.0 
  │   └── path-is-absolute@1.0.1 
  ├── grunt-known-options@1.1.0 
  ├─┬ nopt@3.0.6 
  │ └── abbrev@1.1.1 
  └── resolve@1.1.7 

在这里插入图片描述
版本确认

[es@node1 ~]$ node -v
v6.12.0
[es@node1 ~]$ npm -v
3.10.10
[es@node1 ~]$ grunt -version
grunt-cli v1.2.0

grunt为何有两个版本,因为之前装了,隔间了两个月,grunt版本有出新的版本了。apt自动安装最新的版本。
在这里插入图片描述
参考链接 :

安装ElasticSearch 6.1.1 head插件 : https://blog.csdn.net/zoubf/article/details/79007908

ubuntu安装elasticsearch和head插件(所有可能出现的问题解决)超详细 : https://blog.csdn.net/qq_40663357/article/details/88910133

安装ElasticSearch 6.1.1 head插件 : https://blog.csdn.net/zoubf/article/details/79007908

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寰宇001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值