Docker中的Solr,如何在挂载卷目录中创建共享的分布式集合

Solr in Docker, How to create a distributed collection shared in mounted volume directory

我正试图在 docker 内设置太阳云。 我正在使用 docker-compose 来启动云。 我创建了一个云,其中包含 3 个动物园管理员和 4 个 solrs(solr1、solr2、solr3、solr4)容器。 创建 4 个分片和 2 个副本的分布式集合很酷。 问题是当它在已安装的卷中创建集合以在 docker 之外的机器上进行备份时。 我可以为每个容器将目录卷从机器挂载到 solr 云,但我无法在那里创建集合。 当我通过

创建分布式集合时
docker exec -it solr1 /opt/solr/bin/solr create_collection -c publications -s 4 -rf 2 -p 8983

我在容器中有两个核心的目录,例如对于 solr1 有

/opt/solr/server/solr/publications_shard2_replica_n6

/opt/solr/server/solr/publications_shard4_replica_n14

对于 shard2,我有 我在容器中有一个包含两个核心的目录,例如对于 solr1 有

/opt/solr/server/solr/publications_shard1_replica_n1

/opt/solr/server/solr/publications_shard3_replica_n8

等 核心名称是动态的。

如何在我的卷目录中创建它们

/root/solr/cores

我的docker-compose.yml如下

version: "3.1"
services:
  solr1:
    image: solr:latest
    environment:
      - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=1024m
    ports:
      - "8983:8983"
    restart: always
    container_name: solr1
    volumes:
     - /root/solr/mycores:/opt/solr/server/solr/mycores
    deploy:
      mode: replicated
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper2:2183 -m 1g'
  solr2:
    image: solr:latest
    ports:
      - "8984:8984"
    restart: always
    container_name: solr2
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  solr3:
    image: solr:latest
    ports:
      - "8985:8985"
    restart: always
    container_name: solr3
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
      - solr2
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  solr4:
    image: solr:latest
    ports:
      - "8986:8986"
    restart: always
    container_name: solr4
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
      - solr2
      - solr3
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  zookeeper1:
    image: jplock/zookeeper:latest
    container_name: zookeeper1
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    restart: always
  zookeeper2:
    image: jplock/zookeeper:latest
    container_name: zookeeper2
    ports:
      - "2182:2182"
      - "2889:2889"
      - "3889:3889"
    restart: always
  zookeeper3:
    image: jplock/zookeeper:latest
    container_name: zookeeper3
    ports:
      - "2183:2183"
      - "2890:2890"
      - "3890:3890"
    restart: always

我找到了解决办法。需要在 docker-compose.yml 文件中添加 -t 参数并提供数据目录 /opt/solr/server/solr/mycores。 下面编辑的行

command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper2:2183 -m 1g -t /opt/solr/server/solr/mycores'