安装Head 插件 -- Elasticsearch Offical Docker Image 5.2

安装Head 插件 -- Elasticsearch Offical Docker Image 5.2

1. 拉取最新的docker image

docker pull elasticsearch

2. 启动一个container,命名为elasticsearch,并添加9100,9200,9300 三个端口

docker run -d -p 9100:9100 -p 9200:9200 -p 9300:9300 --name elasticsearch elasticsearch:latest

放开9100端口是因为需要安装head plugin,5.0+以上版本的插件安装方式跟以前版本还是很不一样,我在后面会介绍到。

3. 进入container, 安装插件

docker exec -it elasticsearch /bin/bash

3.1 因为elasticsearch的docker image是基于debian制作的,里面除了java,像vim,git这些都没有的,所以首先需要安装这些工具

apt-get update
apt-get install vim
apt-get install git

注意: update命令需要耗费一些时间安装更新,取决于网络速度,我的虚机是在china azure上。

3.2 因为 head 插件在5.0+版本以后是基于nodejs 和 grunt的,所以需要安装nodejs,首先下载nodejs,

cd /opt
wget https://nodejs.org/dist/v7.7.1/node-v7.7.1-linux-x64.tar.xz
tar -xvf node-v7.7.1-linux-x64.tar.xz
mv node-v7.7.1-linux-x64.tar.xz node

然后把nodejs添加到环境变量里面

vim /etc/profile

在最后面加上

export NODE_HOME=/etc/node/bin
export PATH=$PATH:$NODE_HOME

保存退出vim, source 一下,让配置立即生效

source /etc/profile

测试一下, 能出来版本好就说明配置成功

node -v
npm -v

3.3 开始安装Head插件

cd /usr/share/elasticsearch/plugins/
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm install grunt --save

速度较慢或者安装失败,所以使用国内镜像

修改elasticsearch-head下Gruntfile.js文件,默认监听在127.0.0.1下9100端口

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

然后运行 grunt server

cd node_modules/grunt/bin
./grunt server

会出现下面的错误:

root@931a920a04b6:/usr/share/elasticsearch/plugins/elasticsearch-head/node_modules/grunt/bin# ./grunt server
Local Npm module "grunt-contrib-clean" not found. Is it installed?
Local Npm module "grunt-contrib-concat" not found. Is it installed?
Local Npm module "grunt-contrib-watch" not found. Is it installed?
Local Npm module "grunt-contrib-connect" not found. Is it installed?
Local Npm module "grunt-contrib-copy" not found. Is it installed?
Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Warning: Task "connect:server" not found. Use --force to continue.

需要安装这些缺失的node modules, 注意需要回到elasticsearch_head目录下安装,

npm install grunt-contrib-clean grunt-contrib-concat grunt-contrib-watch grunt-contrib-connect grunt-contrib-copy grunt-contrib-jasmine

再次运行grunt server

猜你喜欢

转载自blog.csdn.net/qq_40597878/article/details/89031453
今日推荐