You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Docker容器中的3个Elasticsearch节点安装分析插件?

问题描述

我在服务器上用Docker部署了3个Elasticsearch节点和1个Kibana,容器信息如下:

CONTAINER ID   IMAGE                                                  COMMAND                  CREATED      STATUS                    PORTS                                                 NAMES
0545e200fc43   docker.elastic.co/kibana/kibana:7.17.9                 "\"/bin/tini -- /usr/l…\""   4 days ago   Up 43 minutes (healthy)   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp             ubuntu_kibana_1
d7ffcec877ae   docker.elastic.co/elasticsearch/elasticsearch:7.17.9   "\"/bin/tini -- /usr/l…\""   4 days ago   Up 43 minutes (healthy)   9200/tcp, 9300/tcp                                    ubuntu_es03_1
b68b45dde0c0   docker.elastic.co/elasticsearch/elasticsearch:7.17.9   "\"/bin/tini -- /usr/l…\""   4 days ago   Up 43 minutes (healthy)   9200/tcp, 9300/tcp                                    ubuntu_es02_1
24abbf05a06a   docker.elastic.co/elasticsearch/elasticsearch:7.17.9   "\"/bin/tini -- /usr/l…\""   4 days ago   Up 43 minutes (healthy)   9300/tcp, 0.0.0.0:9400->9200/tcp, :::9400->9200/tcp   ubuntu_es01_1

现在我要给这些节点安装一款用于analysis-filter的插件,安装命令如下:

bin/elasticsearch-plugin install https://www.dropbox.com/s/cr61dmnx95taivi/ParsiAnalyzer-7.13.1.zip?dl=1

请问怎么给所有3个节点完成插件安装?

更新
以下是我的docker-compose.yml文件中的services-setup配置:

command: >
  bash -c '
    if [ x${ELASTIC_PASSWORD} == ****** ]; then
      echo "\"Set the ELASTIC_PASSWORD environment variable in the .env file\"";
      exit 1;
    elif [ x${KIBANA_PASSWORD} == ****** ]; then
      echo "\"Set the KIBANA_PASSWORD environment variable in the .env file\"";
      exit 1;
    fi;
    if [ ! -f config/certs/ca.zip ]; then
      echo "\"Creating CA\"";
      bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
      unzip config/certs/ca.zip -d config/certs;
    fi;
    if [ ! -f config/certs/certs.zip ]; then
      echo "\"Creating certs\"";
      echo -ne \
      "\"instances:\
\""\
      "\"  - name: es01\
\""\
      "\"    dns:\
\""\
      "\"      - es01\
\""\
      "\"      - localhost\
\""\
      "\"    ip:\
\""\
      "\"      - 127.0.0.1\
\""\
      "\"  - name: es02\
\""\
      "\"    dns:\
\""\
      "\"      - es02\
\""\
      "\"      - localhost\
\""\
      "\"    ip:\
\""\
      "\"      - 127.0.0.1\
\""\
      "\"  - name: es03\
\""\
      "\"    dns:\
\""\
      "\"      - es03\
\""\
      "\"      - localhost\
\""\
      "\"    ip:\
\""\
      "\"      - 127.0.0.1\
\""\
      > config/certs/instances.yml;
      bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
      unzip config/certs/certs.zip -d config/certs;
    fi;
    echo "\"Setting file permissions\""
    chown -R root:root config/certs;
    find . -type d -exec chmod 750 \{\} \;;
    find . -type f -exec chmod 640 \{\} \;;
    echo "\"Waiting for Elasticsearch availability\"";
    until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "\"missing authentication credentials\""; do sleep 30; done;
    echo "\"Setting kibana_system password\"";
    until curl -s -X POST --cacert config/certs/ca/ca.crt -u "\"elastic:******\"" -H "\"Content-Type: application/json\"" https://es01:9200/_security/user/kibana_system/_password -d "\"{\\\"password\\\\":\\\"******\\\"}\"" | grep -q "\"^{}\""; do sleep 10; done;
    echo "\"All done!\"";
  '
解决方案

针对Docker部署的Elasticsearch集群,给所有节点安装插件有两种可靠方式,结合你的docker-compose环境,推荐优先使用构建自定义镜像的方式,避免临时安装后重启丢失的问题:

方式一:构建自定义Elasticsearch镜像(推荐)

  1. 在项目目录下创建Dockerfile,内容如下:
FROM docker.elastic.co/elasticsearch/elasticsearch:7.17.9

RUN bin/elasticsearch-plugin install --batch https://www.dropbox.com/s/cr61dmnx95taivi/ParsiAnalyzer-7.13.1.zip?dl=1

注意:--batch参数用于自动确认安装,无需交互

  1. 修改docker-compose.yml中所有Elasticsearch服务的image字段,替换为你构建的镜像名称,比如:
services:
  es01:
    image: custom-es:7.17.9  # 替换原来的官方镜像
    # 其他原有配置保持不变
  es02:
    image: custom-es:7.17.9
    # 其他原有配置保持不变
  es03:
    image: custom-es:7.17.9
    # 其他原有配置保持不变
  1. 构建镜像并重启集群:
# 构建自定义镜像
docker build -t custom-es:7.17.9 .

# 重启整个集群(确保数据安全,建议先备份)
docker-compose down
docker-compose up -d

方式二:临时进入容器安装(适合快速测试,不推荐生产环境)

如果只是临时测试,可以直接进入每个Elasticsearch容器执行安装命令,安装后需要重启容器:

  1. 给es01安装插件:
docker exec -it ubuntu_es01_1 bin/elasticsearch-plugin install --batch https://www.dropbox.com/s/cr61dmnx95taivi/ParsiAnalyzer-7.13.1.zip?dl=1
  1. 给es02安装插件:
docker exec -it ubuntu_es02_1 bin/elasticsearch-plugin install --batch https://www.dropbox.com/s/cr61dmnx95taivi/ParsiAnalyzer-7.13.1.zip?dl=1
  1. 给es03安装插件:
docker exec -it ubuntu_es03_1 bin/elasticsearch-plugin install --batch https://www.dropbox.com/s/cr61dmnx95taivi/ParsiAnalyzer-7.13.1.zip?dl=1
  1. 重启所有Elasticsearch容器:
docker restart ubuntu_es01_1 ubuntu_es02_1 ubuntu_es03_1

注意:这种方式下,容器重启后插件会丢失(因为容器是基于原镜像创建的),生产环境必须使用方式一。

验证安装结果

安装完成后,进入任意节点执行以下命令查看已安装插件:

docker exec -it ubuntu_es01_1 bin/elasticsearch-plugin list

如果输出中包含ParsiAnalyzer,说明安装成功。


内容的提问来源于stack exchange,提问作者miladjurablu0001002002

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 07:37:03