Elasticsearch插件安装之elasticsearch-head

释放双眼,带上耳机,听听看~!

elasticsearch-head简介

elasticsearch-head被称为是弹性搜索集群的web前端,head插件主要是用来和elastic Cluster交互的Web前端
elasticsearch-head站点:https://github.com/mobz/elasticsearch-head

lasticsearch-head的主要作用

    可以显示elastic cluster的各种状态,展示每个elastic节点的信息以及每个节点的动作
    可以显示每个节点的主分片和副本分片的数量
    可以索引、多种数据查询功能,它提供一组针对集群查询API,并将结果以JSON的表格形式返回

elasticsearch-head插件在0.x-2.x版本的时候是集成在elasticsearch内的,由elasticsearch的bin/elasticsearch-plugin来管理插件,可是从2.x版本跳到了5.x版本后,head就作用了一个独立的服务来运行了,脱离了elasticsearch的约束,所以相对来说,部署起来也比较繁琐了

部署elasticsearch-head插件

官网给出的elasticsearch-head是git包,所以我们还得被强制安装git来下载此插件

安装git

正好有时间,在此就使用源码包安装了
两个途径下载git源码,分别是linux内核官网和github
内核下载地址:https://mirrors.edge.kernel.org/pub/software/scm/git/
github下载地址:https://github.com/git/git/releases
如果从源码进行git安装,那么将依赖这些库文件:curl、zlib、openssl、expat,还有libiconv
如果想要git能够支持更多种的文件格式,例如(doc、html、info)那么还需要安装这些库 别忘了安装gcc编译器哦
安装依赖包

[root@CentOS7_node2 /]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel \
asciidoc xmlto docbook2X \
gcc-c++ \
autoconf -y

安装git

编译安装挺麻烦的,编译时间有点长,10分钟打底吧,有时间了就编译装下,没时间了就yum装
[root@CentOS7_node2 src]# wget https://github.com/git/git/archive/v2.21.0.tar.gz
[root@CentOS7_node2 src]# tar xf v2.21.0.tar.gz 
[root@CentOS7_node2 src]# cd git-2.21.0/
[root@CentOS7_node2 git-2.21.0]# make configure     #编译检查
GIT_VERSION = 2.21.0
    GEN configure

[root@CentOS7_node2 git-2.21.0]# ./configure --prefix=/usr/local/git-2.21
[root@CentOS7_node2 git-2.21.0]# make all doc info
/bin/sh: line 1: docbook2x-texi: command not found    #编译出错,找不到docbook2x-texi命令
make[1]: *** [user-manual.texi] Error 127
make[1]: Leaving directory `/usr/local/src/git-2.21.0/Documentation'
make: *** [info] Error 2

#安装docbook2x-texi库文件
[root@CentOS7_node2 git-2.21.0]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/d/docbook2X-0.8.8-17.el7.x86_64.rpm         #
Retrieving http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/d/docbook2X-0.8.8-17.el7.x86_64.rpm
Preparing...                          ################################# [100%]
        package docbook2X-0.8.8-17.el7.x86_64 is already installed


[root@CentOS7_node2 git-2.21.0]# ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi 
#软连docbook2x库文件
[root@CentOS7_node2 git-2.21.0]# make all doc info
#重新编译
[root@CentOS7_node2 git-2.21.0]# make install install-doc install-html install-info
#安装,顺便安装能够支持doc、html、info的文件格式给安装上

[root@CentOS7_node2 git-2.21.0]# ln -s /usr/local/git-2.21/bin/git /usr/local/bin/git
[root@CentOS7_node2 git-2.21.0]# git --version      #输入变量
git version 2.21.0

克隆elasticsearch-head插件到本地

[root@CentOS7_node2 src]# git clone https://github.com/mobz/elasticsearch-head.git
Cloning into 'elasticsearch-head'...
remote: Enumerating objects: 4260, done.
remote: Total 4260 (delta 0), reused 0 (delta 0), pack-reused 4260
Receiving objects: 100% (4260/4260), 2.02 MiB | 779.00 KiB/s, done.
Resolving deltas: 100% (2373/2373), done.

下载完后,而这个插件还是基于nodejs所研发,还必须依赖nodejs环境

安装nodejs

[root@CentOS7_node2 src]# wget https://nodejs.org/dist/latest-v8.x/node-v8.16.0.tar.gz
[root@CentOS7_node2 src]# tar xf node-v8.16.0.tar.gz 
[root@CentOS7_node2 src]# cd node-v8.16.0
[root@CentOS7_node2 node-v8.16.0]# ./configure --prefix=/usr/local/node-v8.16
[root@CentOS7_node2 node-v8.16.0]# make -j 8 && make install

添加环境变量

[root@CentOS7_node2 node-v8.16.0]# vim /etc/profile
################nodejs###############
export NODE_HOME=/usr/local/node-v8.16
export PATH=$PATH:$NODE_HOME/bin
[root@CentOS7_node2 node-v8.16.0]# source /etc/profile
[root@CentOS7_node2 node-v8.16.0]# node -v
v8.16.0
[root@CentOS7_node2 node-v8.16.0]# npm -v
6.4.1

安装grunt客户端程序来控制head插件

[root@CentOS7_node2 src]# mv elasticsearch-head /usr/local/
#把下载好的head插件移动到/usr/local目录下
[root@CentOS7_node2 src]# cd /usr/local/elasticsearch-head/
[root@CentOS7_node2 elasticsearch-head]# npm install -g grunt --registry=https://registry.npm.taobao.org
#使用淘宝的镜像源来安装grunt程序,grunt是基于nodejs的项目构建工具,可以进行打包压缩、测试、执行等工作,head插件就是通过grunt启动。
/usr/local/node-v8.16/bin/grunt -> /usr/local/node-v8.16/lib/node_modules/grunt/bin/grunt
+ grunt@1.0.4
added 97 packages from 63 contributors in 3.612s

[root@CentOS7_node2 elasticsearch-head]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org 
#安装grunt工具的客户端
/usr/local/node-v8.16/bin/grunt -> /usr/local/node-v8.16/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 152 packages from 122 contributors in 4.377s

head配置修改

安装完成后需要修改head配置文件来连接es cluster
1.修改elasticsearch-head/Gruntfile.js

进入vi后,直接搜索9100,然后在9100下添加hostname字段
[root@CentOS7_node2 ~]# vim /usr/local/elasticsearch-head/Gruntfile.js
                connect: {
                        server: {
                                options: {
                                        port: 9100,
                                        hostname: "*",
                                        base: '.',
                                        keepalive: true
                                }
                        }
                }

2.修改elasticsearch-head/_site/app.js

进入vi后,直接搜索9200,然后把9200改为9100,此端口是head对外提供的http端口,把localhost改为本机对外访问的地址
vim /usr/local/elasticsearch-head/_site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.211.55.9:9100";

3.修改lasticsearch-5.6.16/config/elasticsearch.yml
修改完head插件后,还需要修改elasticsearch配置文件来支持跨域访问

[root@CentOS7_node2 ~]# echo 'http.cors.enabled: true' >> /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
[root@CentOS7_node2 ~]# echo 'http.cors.allow-origin: "*"' >> /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
[root@CentOS7_node2 ~]# tail -2 /usr/local/elasticsearch-5.6.16/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"

重启es及head

[root@CentOS7_node2 elasticsearch-head]# su elasticsearch /usr/local/elasticsearch-5.6.16/bin/elasticsearch
[root@CentOS7_node2 elasticsearch-head]# nohup grunt server &
[root@CentOS7_node2 elasticsearch-head]# ss -anplt | grep grunt
LISTEN     0      128         :::9100                    :::*                   users:(("grunt",pid=31540,fd=10))

测试访问

浏览器访问IP:9100

创建文档

我们创建手动创建文档,让文档自动生成索引,我们这里是使用curl命令结合put上传协议来上传文档,具体语法如下:

curl -XPUT 'http://10.211.55.9:9201/index_name/type_name/1?pretty' -d '
{ "name": "xuwl", "age": 18, "job": "Linux" }'

命令介绍
-X:指定http请求方式,这里为PUT上传方式
http://10.211.55.9:9201:指定一台es服务器对外的http端口
/index_name:文档的索引名称,必须小写
/type_name:文档的类型名称,必须小写
/1:文档的ID编号
?pretty:人性化创建索引
-d:指定使用JSON方式来撰写上传文档
{ "name": "xuwl", "age": 18, "job": "Linux" }':使用JSON格式来撰写上传文档内容

1.创建索引为dockerc_stack文档

1. 创建索引为docker_stack,ID编号为1的文档
[root@CentOS7_node2 ~]# curl -XPUT 'http://10.211.55.9:9201/dockerc_stack/elasticsearch_index/1?pretty' -d '
{ "name": "cerebro", "type": "plugin", "word_environment": "general" }'
{
  "_index" : "dockerc_stack",
  "_type" : "elasticsearch_index",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,    
    "failed" : 0
  },
  "created" : true     #创建为true
}

2. 创建索引为docker_stack,ID编号为2的文档
[root@CentOS7_node2 ~]# curl -XPUT 'http://10.211.55.9:9201/dockerc_stack/elasticsearch_index/2?pretty' -d '
{ "name": "es-cerebro", "type": "es-plugin", "word_environment": "linux" }'
{
  "_index" : "dockerc_stack",
  "_type" : "elasticsearch_index",
  "_id" : "2",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "created" : true
}

2.创建索引为migu_video文档

[root@CentOS7_node2 ~]# curl -XPUT 'http://10.211.55.9:9201/migu_video/migu_index/1?pretty' -d '
{ "movie_name": "avengers", "movie_type": "science_flction", "time": "three hours" }'
{
  "_index" : "migu_video",
  "_type" : "migu_index",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "created" : true
}

3.查看索引

[root@CentOS7_node2 ~]# curl -XGET 'http://10.211.55.9:9201/_cat/indices?v'
健康状态 索引状态 索引名称      索引UID               主分片 副本分片  文档数量  文档删除数量    分片总大小      主分片大小
health status index         uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   dockerc_stack dCqV4xRIR4i0147pToxaag   5   1          2            0     19.4kb          9.7kb
green  open   migu_video    Vzk4zxOvSRaZiSID9uUfeg   5   1          1            0     10.3kb          5.1kb

注:更多功能望各位自己摸索,其实elasticsearch-search这款插件并不美观,现在的cerebro插件可以更美观的展现ES cluster节点信息,界面美观,安装简单,功能强大,如果感兴趣去看cerebro插件讲解:https://www.dockerc.com/elasticsearch-cerebro/

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索