1.Head插件简介

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

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

    2.Head插件安装

    2.1安装NodeJS

    1. [root@node1 ~]# yum install -y nodejs

    2.2安装npm

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

    2.3使用npm安装grunt

    1. [root@node1 ~]# npm install -g grunt
    2. npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
    3. npm WARN gentlyRm not removing /usr/bin/grunt as it wasn't installed by /usr/lib/node_modules/grunt
    4. /usr/bin/grunt -> /usr/lib/node_modules/grunt/bin/grunt
    5. /usr/lib
    6. └── grunt@1.0.1
    7. [root@node1 ~]#
    1. [root@node1 ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
    2. /usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt
    3. /usr/lib
    4. └─┬ grunt-cli@1.2.0
    5. ├─┬ findup-sync@0.3.0
    6. └─┬ glob@5.0.15
    7. ├─┬ inflight@1.0.6
    8. └── wrappy@1.0.2
    9. ├── inherits@2.0.3
    10. ├─┬ minimatch@3.0.4
    11. └─┬ brace-expansion@1.1.8
    12. ├── balanced-match@1.0.0
    13. └── concat-map@0.0.1
    14. ├── once@1.4.0
    15. └── path-is-absolute@1.0.1
    16. ├── grunt-known-options@1.1.0
    17. ├─┬ nopt@3.0.6
    18. └── abbrev@1.1.1
    19. └── resolve@1.1.7
    20. [root@node1 ~]#

    2.4版本确认

    1. [es@node1 ~]$ node -v
    2. v6.12.0
    3. [es@node1 ~]$ npm -v
    4. 3.10.10
    5. [es@node1 ~]$ grunt -version
    6. grunt-cli v1.2.0
    7. [es@node1 ~]$

    3.安装head

    3.1下载head插件源码

    1. [es@node1 ~]$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip
    2. --2017-12-18 09:58:08-- https://github.com/mobz/elasticsearch-head/archive/master.zip
    3. Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
    4. Connecting to github.com (github.com)|192.30.255.113|:443... connected.
    5. HTTP request sent, awaiting response... 302 Found
    6. Location: https://codeload.github.com/mobz/elasticsearch-head/zip/master [following]
    7. --2017-12-18 09:58:09-- https://codeload.github.com/mobz/elasticsearch-head/zip/master
    8. Resolving codeload.github.com (codeload.github.com)... 192.30.255.120, 192.30.255.121
    9. Connecting to codeload.github.com (codeload.github.com)|192.30.255.120|:443... connected.
    10. HTTP request sent, awaiting response... 200 OK
    11. Length: 921421 (900K) [application/zip]
    12. Saving to: master.zip
    13. 100%[===============================================================>] 921,421 9.64KB/s in 67s
    14. 2017-12-18 09:59:18 (13.4 KB/s) - master.zip saved [921421/921421]
    15. [es@node1 ~]$ ls
    16. master.zip
    17. [es@node1 ~]$ unzip master.zip

    3.2下载依赖

    进入elasticsearch-head-master目录,执行下面命令:
    1. [es@node1 elasticsearch-head-master]$ npm install
    2. > phantomjs-prebuilt@2.1.16 install /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt
    3. > node install.js
    4. PhantomJS not found on PATH
    5. Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
    6. Verified checksum of previously downloaded file
    7. Extracting tar contents (via spawned process)
    8. Removing /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
    9. Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1515165531727/phantomjs-2.1.1-linux-x86_64 -> /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
    10. Writing location.js file
    11. Done. Phantomjs binary available at /home/es/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
    12. elasticsearch-head@0.0.0 /home/es/elasticsearch-head-master
    13. └─┬ grunt-contrib-jasmine@1.0.3
    14. └─┬ grunt-lib-phantomjs@1.1.0
    15. └── phantomjs-prebuilt@2.1.16
    16. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
    17. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    18. npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
    19. [es@node1 elasticsearch-head-master]$

    如果上面命令安装较慢或失败,可以尝试国内镜像安装
    1. [es@node1 elasticsearch-head-master]$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
    2. [sudo] password for es:
    3. /usr/bin/cnpm -> /usr/lib/node_modules/cnpm/bin/cnpm
    4. /usr/lib
    5. └─┬ cnpm@5.1.1
    6. ├─┬ npminstall@3.3.0
    7. ├── binary-mirror-config@1.7.3
    8. ├── moment@2.20.1
    9. └─┬ tar@4.2.0
    10. └── minizlib@1.1.0
    11. └─┬ urllib@2.25.3
    12. └─┬ proxy-agent@2.1.0
    13. └─┬ pac-proxy-agent@2.0.0
    14. └─┬ socks-proxy-agent@3.0.1
    15. └─┬ agent-base@4.1.2
    16. └─┬ es6-promisify@5.0.0
    17. └── es6-promise@4.2.2
    18. [es@node1 elasticsearch-head-master]$ cnpm install
    19. [6/10] Installing json-schema-traverse@^0.3.0platform unsupported karma@1.3.0 chokidar@1.7.0 fsevents@^1.0.0 Package require os(darwin) not compatible with your platform(linux)
    20. [fsevents@^1.0.0] optional install error: Package require os(darwin) not compatible with your platform(linux)
    21. Installed 10 packages
    22. Linked 313 latest versions
    23. PhantomJS not found on PATH
    24. Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
    25. Verified checksum of previously downloaded file
    26. Extracting tar contents (via spawned process)
    27. Removing /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom
    28. Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1515223629881/phantomjs-2.1.1-linux-x86_64 -> /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom
    29. Writing location.js file
    30. Done. Phantomjs binary available at /home/es/elasticsearch-head-master/node_modules/_phantomjs-prebuilt@2.1.16@phantomjs-prebuilt/lib/phantom/bin/phantomjs
    31. Run 1 scripts
    32. deprecate grunt-contrib-connect@1.0.2 http2@^3.3.4 Use the built-in module in node 9.0.0 or newer, instead
    33. deprecate grunt@1.0.1 coffee-script@~1.10.0 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
    34. anti semver karma@1.3.0 useragent@2.2.1 tmp@0.0.x delcares tmp@0.0.x(resolved as 0.0.33) but using ancestor(karma)'s dependency tmp@0.0.28(resolved as 0.0.28)
    35. ✔ All packages installed (365 packages installed from npm registry, used 17s, speed 497.82kB/s, json 323(581.43kB), tarball 7.64MB)
    36. [es@node1 elasticsearch-head-master]$

    4.配置

    4.1停止ElasticSearch

    如果ElasticSearch已经启动,需要先停止
    1. [es@node1 ~]$ jps
    2. 3261 Elasticsearch
    3. 3375 Jps
    4. [es@node1 ~]$ kill 3261

    4.2配置 ElasticSearch,使得HTTP对外提供服务

    1. [es@node1 elasticsearch-6.1.1]$ vi config/elasticsearch.yml
    添加如下内容
    1. # 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格
    2. http.cors.enabled: true
    3. http.cors.allow-origin: "*"

    4.3 修改Head插件配置文件

    1. [es@node1 elasticsearch-head-master]$ vi Gruntfile.js
    找到connect:server,添加hostname一项,如下
    1. connect: {
    2. server: {
    3. options: {
    4. hostname: '0.0.0.0',
    5. port: 9100,
    6. base: '.',
    7. keepalive: true
    8. }
    9. }
    10. }

    5.启动

    5.1启动elasticsearch

    首先确认elasticsearch已经启动
    1. [es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
    2. [es@node1 elasticsearch-6.1.1]$ jps
    3. 3451 Jps
    4. 3436 Elasticsearch
    5. [es@node1 elasticsearch-6.1.1]$

    5.2启动head

    通过命令grunt server启动head
    1. [es@node1 elasticsearch-head-master]$ grunt server
    2. Running "connect:server" (connect) task
    3. Waiting forever...
    4. Started connect web server on http://node1:9100
    或者通过命令npm run start也可以启动head
    1. [es@node1 elasticsearch-head-master]$ npm run start
    2. > elasticsearch-head@0.0.0 start /home/es/elasticsearch-head-master
    3. > grunt server
    4. Running "connect:server" (connect) task
    5. Waiting forever...
    6. Started connect web server on http://node1:9100

    5.3访问9100端口

    http://node1:9100/
    ES系列二、CentOS7安装ES head6.3.1 - 图2
    如果出现“未连接”,请修改localhost为node1,然后单击“连接”按钮
    ES系列二、CentOS7安装ES head6.3.1 - 图3

    6 简单应用

    6.1创建索引

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

    6.2查看head变化 ES系列二、CentOS7安装ES head6.3.1 - 图4