3.head插件安装

head插件安装

1.准备的资料
https://download.csdn.net/download/wuzhuang12/10643242 相关数据下载

http://www.imooc.com/learn/920 相关学习视频

2.1 Head插件简介

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

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

2.2 Head插件安装

(1)安装NodeJS

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

或者自己下载tar文件解压

wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.5.0-linux-x64.tar.gz

tar -zxvf node-v4.5.0-linux-x64.tar.gz

配置下环境变量,编辑/etc/profile添加

export NODE_HOME=/usr/local/node-v4.5.0-linux-x64

export PATH=NODE_HOME/bin/

export NODE_PATH=$NODE_HOME/lib/node_modules

执行 source /etc/profile

  • 1

(2)安装npm

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

  • 1

(3)使用npm安装grunt

  1. [root@node1 ~]# npm install -g grunt

  2. npm WARN deprecated [email protected]: 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. └── [email protected]

  7. [root@node1 ~]#

  8. [root@node1 ~]# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy

  9. /usr/bin/grunt -> /usr/lib/node_modules/grunt-cli/bin/grunt

  10. /usr/lib

  11. └─┬ [email protected]

  12. ├─┬ [email protected]

  13. │ └─┬ [email protected]

  14. │ ├─┬ [email protected]

  15. │ │ └── [email protected]

  16. │ ├── [email protected]

  17. │ ├─┬ [email protected]

  18. │ │ └─┬ [email protected]

  19. │ │ ├── [email protected]

  20. │ │ └── [email protected]

  21. │ ├── [email protected]

  22. │ └── [email protected]

  23. ├── [email protected]

  24. ├─┬ [email protected]

  25. │ └── [email protected]

  26. └── [email protected]

  27. [root@node1 ~]#

(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 ~]$

(5)下载head插件源码

[es@node1 ~]$ wget https://github.com/mobz/elasticsearch-head/archive/master.zip

  1. 也可以在别的地方下载后上传到服务器
  2. [es@node1 ~]$ ls
  3. master.zip
  4. [es@node1 ~]$ unzip master.zip

(6)下载依赖

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

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

  2. [email protected] 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. [email protected] /home/es/elasticsearch-head-master

  13. └─┬ [email protected]

  14. └─┬ [email protected]

  15. └── [email protected]

  16. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):

  17. npm WARN [email protected] license should be a valid SPDX license expression

  18. [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. └─┬ [email protected]

  6. ├─┬ [email protected]

  7. │ ├── [email protected]

  8. │ ├── [email protected]

  9. │ └─┬ [email protected]

  10. │ └── [email protected]

  11. └─┬ [email protected]

  12. └─┬ [email protected]

  13. └─┬ [email protected]

  14. └─┬ [email protected]

  15. └─┬ [email protected]

  16. └── [email protected]

  17. [es@node1 elasticsearch-head-master]$ cnpm install

  18. ⠸ [6/10] Installing json-schema-traverse@^0.3.0platform unsupported [email protected][email protected] › fsevents@^1.0.0 Package require os(darwin) not compatible with your platform(linux)

  19. [fsevents@^1.0.0] optional install error: Package require os(darwin) not compatible with your platform(linux)

  20. ✔ Installed 10 packages

  21. ✔ Linked 313 latest versions

  22. PhantomJS not found on PATH

  23. Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2

  24. Verified checksum of previously downloaded file

  25. Extracting tar contents (via spawned process)

  26. Removing /home/es/elasticsearch-head-master/node_modules/[email protected]@phantomjs-prebuilt/lib/phantom

  27. 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/[email protected]@phantomjs-prebuilt/lib/phantom

  28. Writing location.js file

  29. Done. Phantomjs binary available at /home/es/elasticsearch-head-master/node_modules/[email protected]@phantomjs-prebuilt/lib/phantom/bin/phantomjs

  30. ✔ Run 1 scripts

  31. deprecate [email protected] › http2@^3.3.4 Use the built-in module in node 9.0.0 or newer, instead

  32. deprecate [email protected] › coffee-script@~1.10.0 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)

  33. anti semver [email protected][email protected][email protected] delcares [email protected](resolved as 0.0.33) but using ancestor(karma)'s dependency [email protected](resolved as 0.0.28)

  34. ✔ All packages installed (365 packages installed from npm registry, used 17s, speed 497.82kB/s, json 323(581.43kB), tarball 7.64MB)

  35. [es@node1 elasticsearch-head-master]$

2.3 配置

(0)停止ElasticSearch

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

  1. [es@node1 ~]$ jps
  2. 3261 Elasticsearch
  3. 3375 Jps
  4. [es@node1 ~]$ kill 3261

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

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

添加如下内容

  1. 增加新的参数,这样head插件可以访问es。设置参数的时候:后面要有空格

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

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

[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. }

2.4 启动

(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]$

(2)启动head

通过命令grunt server启动head

[es@node1 elasticsearch-head-master]$ grunt server

  1. 需要在head的目录下运行
  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. [email protected] 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

(3)访问9100端口

http://10.105.45.32:9100/

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

2.5 简单应用

(1)创建索引

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

(2)查看head变化

你可能感兴趣的:(3.head插件安装)