Elasticsearch中安装插件(Docker-Compose版)

docker-compose.yml

这里在原来的基础上面增加安装插件功能(shell脚本)

version: '2.2'
services:
  cerebro:
    image: lmenezes/cerebro:0.8.5
    container_name: cerebro
    ports:
      - "9000:9000"
    command:
      - -Dhosts.0.host=http://es01:9200
    networks:
      - elastic
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1
    container_name: es01
    entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.enabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
      - .:/apps
    ports:
      - 9200:9200
    networks:
      - elastic

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1
    container_name: es02
    entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.enabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
      - .:/apps
    ports:
      - 9201:9201
    networks:
      - elastic

  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1
    container_name: es03
    entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - xpack.security.enabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
      - .:/apps
    ports:
      - 9202:9202
    networks:
      - elastic

  kib01:
    image: docker.elastic.co/kibana/kibana:7.6.1
    container_name: kib01
    ports:
      - 5601:5601
    environment:
      - I18N_LOCALE=zh-CN
      - XPACK_GRAPH_ENABLED=true
      - XPACK_MONITORING_KIBANA_COLLECTION_ENABLED=true
      - ELASTICSEARCH_URL=http://es01:9200
      - ELASTICSEARCH_HOSTS=http://es01:9200
    networks:
      - elastic

volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge

最主要的行,如下:
entrypoint: ["sh", "/apps/docker-entrypoint-es-plugins.sh"]
主要的意思即使运行这个shell脚本,通过这个shell脚本来安装elasticsearch的插件。

docker-entrypoint-es-plugins.sh

#!/bin/bash
# setting up prerequisites

bin/elasticsearch-plugin install analysis-icu
bin/elasticsearch-plugin install analysis-smartcn
bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.1/elasticsearch-analysis-ik-7.6.1.zip

exec /usr/local/bin/docker-entrypoint.sh elasticsearch

验证

远程登录到docker容器内部,使用elasticsearch-plugin来进行验证,具体如下:

docker exec -it es01 bash
bin/elasticsearch-plugin list
analysis-icu

查询出已经安装的插件为analysis-icu,这表示插件安装成功。

参考

  • Install plugins on elasticsearch with docker-compose
  • docker使用entrypoint执行时报permission denied错误
  • Running the Elastic Stack on Docker

你可能感兴趣的:(Elasticsearch中安装插件(Docker-Compose版))