ES系列二之CentOS7安装ES head插件

CentOS7安装ES head插件

附:Centos7中安装Node出现Cannot find module ‘…/lib/utils/unsupported.js‘问题

删除原本的的npm连接,重新建一个即可。

1、先cd到该node版本中的bin文件夹下,这里装的是12.16.2版本:

cd /usr/local/soft/node-v16/bin
或 
/usr/local/soft/node/node-v20/bin

2、删除该路径下的npm文件, 出现提示输入yes即可
在这里插入图片描述

mv npm npm.bk

3、重新建立文件连接

ln -s ../usr/local/soft/node-v16/lib/node_modules/npm/bin/npm-cli.js ./npm

再次使用 npm -v 命令查看发现已近ok了
整个操作用一张图表示如下:

一、Head插件简介

ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作。

  • 显示集群的拓扑,并且能够执行索引和节点级别操作
  • 搜索接口能够查询集群中原始json或表格格式的检索数据
  • 能够快速访问并显示集群的状态
  • 有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
  • 5.0版本之前可以通过plugin名安装,5.0之后可以独立运行。

-----------------------只需要在第一台es部署head 即可-----------------------

二、Head插件安装

前置:安装phantomjs(由于入坑多写一步,此步骤可省掉)

1.下载phantomjs

安装npm的时候会依赖phantomjs 所以我们先安装phantomjs

phantomjs 下载地址:http://phantomjs.org/download.html

可以复制下载地址通过命令来下载,如下

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

2.解压安装包

# 下载bzip2
 ① yum -y install bzip2

#创建存放目录
[root@elk-1 ~]# mkdir /tmp/phantomjs

# ------------------------------------------------------------
# 将文件移动过去即可,不需要解压
[root@elk-1 ~]# mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /tmp/phantomjs/
 
更改权限
[root@elk-1 ~]# chmod 777 /tmp/phantomjs -R
# ------------------------------------------------------------
 # ========================================================
#如果不行 再解压 安装
 ② bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2

 ③ tar -xvf phantomjs-2.1.1-linux-x86_64.tar
 # ========================================================

3.安装(由于我的解压目录在 /home/tools/phantomjs-2.1.1-linux-x86_64,所以后面就直接写绝对路径了)

① 将可执行文件放入系统路径

   ln -s /home/tools/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs

② 安装依赖——fontconfig和freetype

  yum install fontconfig freetype2

③ 配置环境变量

  vim /etc/profile

  export  PHANTOMJS=/home/tools/phantomjs-2.1.1-linux-x86_64

  export  PATH=$PATH:$PHANTOMJS/bin

保存后执行:source /etc/profile

④ 测试 执行如下命令会显示phantomjs的版本

phantomjs -v

  1. 安装NodeJS

    [root@localhost soft]#  yum install -y nodejs
    或 上传tar.gz包 直接解压缩
    
  2. 安装npm

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

    附:报错 npm ERR! code CERT_HAS_EXPIRED
    在这里插入图片描述

  3. 使用npm安装grunt

[root@node1 ~]# npm install -g grunt
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN gentlyRm not removing /usr/bin/grunt as it wasn't installed by /usr/lib/node_modules/grunt
/usr/bin/grunt -> /usr/lib/node_modules/grunt/bin/grunt
/usr/lib
└── grunt@1.0.1 
    
[root@node1 ~]# 

[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 

[root@node1 ~]#
  1. 版本确认
    [es@node1 ~]$ node -v
    v6.12.0
    [es@node1 ~]$ npm -v
    3.10.10
    [es@node1 ~]$ grunt -version
    grunt-cli v1.5.0
    [es@node1 ~]$
    

三、安装head

  1. 下载head插件源码
[root@localhost ~]# cd /usr/local/soft/es7.14/
[root@localhost es7.14]# get https://github.com/mobz/elasticsearch-head/archive/master.zip

--2017-12-18 09:58:08--  https://github.com/mobz/elasticsearch-head/archive/master.zip
.......
......
HTTP request sent, awaiting response... 200 OK
Length: 921421 (900K) [application/zip]
Saving to: ‘master.zip’

100%[===============================================================>] 921,421     9.64KB/s   in 67s    

2017-12-18 09:59:18 (13.4 KB/s) - ‘master.zip’ saved [921421/921421]

[root@localhost es7.14]# ls
master.zip
$ unzip master.zip 

# 改名
[root@localhost es7.14]# mv elasticsearth-head-master head-master 
  1. 下载依赖

    进入elasticsearch-head-master目录,执行下面命令:

[root@localhost head-master]# npm install -g

[root@localhost head-master]#

如果上面命令安装较慢或失败,可以尝试国内镜像安装

[es@node1 elasticsearch-head-master]$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

[es@node1 elasticsearch-head-master]$

四、配置

  1. 停止ElasticSearch

如果ElasticSearch已经启动,需要先停止

[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: "*"
  1. 修改Head插件配置文件
[es@node1 elasticsearch-head-master]$ vi Gruntfile.js

在这里插入图片描述

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

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

(3-2) 修改 _site/app.js

[root@elk-1 ~]# vim /usr/local/elasticsearch-head-master/_site/app.js +4373  
原来是http://localhost:9200 ,如果head和ES不在同一个节点,注意修改成ES的IP地址,写成node-1或node-3的IP地址

在这里插入图片描述

五、启动

  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
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
  1. 访问9100端口

     http://node1:9100/
    

如果出现“未连接”,请修改localhost为node1,然后单击“连接”按钮

六、简单应用

  1. 创建索引
[root@node1 ~]# curl -XPUT node1:9200/test
{"acknowledged":true,"shards_acknowledged":true,"index":"test"}
[root@node1 ~]#
  1. 查看head变化

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值