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

时间:2018-05-18 16:47:46

标签: docker solr docker-compose docker-cloud

我正试图在码头工人中设置一片闷闷不乐。 我正在使用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

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。需要在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'