我正在尝试创建一个docker-compose文件来运行zookeeper和solr(3节点群集-官方映像)。我正在尝试使用撰写文件中的“命令”属性在zookeeper中定义一个znode。
command: bash -c "/apache-zookeeper-3.5.8-bin/bin/zkCli.sh -server zoo1:2181 create /solr '' && zkServer.sh start-foreground"
使用此命令的zookeeper节点不断崩溃。
我的docker compose文件是:
version: '3.7'
services:
zoo1:
image: zookeeper:3.5
container_name: zoo1
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- solr
volumes:
- 'zoo1_data:/data'
zoo2:
image: zookeeper:3.5
container_name: zoo2
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- solr
volumes:
- 'zoo2_data:/data'
zoo3:
image: zookeeper:3.5
container_name: zoo3
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
command: bash -c "/apache-zookeeper-3.5.8-bin/bin/zkCli.sh -server zoo2:2181 create /solr '' && zkServer.sh start-foreground"
networks:
- solr
volumes:
- 'zoo3_data:/data'
depends_on:
- zoo1
- zoo2
solr1:
image: solr:8.3
container_name: solr1
ports:
- "8981:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr1varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
solr2:
image: solr:8.3
container_name: solr2
ports:
- "8982:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr2varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
solr3:
image: solr:8.3
container_name: solr3
ports:
- "8983:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr3varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
networks:
solr:
volumes:
zoo1_data:
zoo2_data:
zoo3_data:
solr1varsolr:
solr2varsolr:
solr3varsolr:
从我看来,用于启动容器中的zookeeper的命令的第二部分未执行,但我不知道为什么?并且还有其他方法可以实现这一目标吗?
找到原因。命令选项中的“ zkServer.sh start-foreground”之前缺少“ exec”。执行命令后导致容器关闭。 感谢@Yoeri Van Nieuwerburg提供的示例撰写文件进行比较。
有效的撰写文件:
version: '3.7'
services:
zoo1:
image: zookeeper:3.5
container_name: zoo1
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- solr
volumes:
- 'zoo1_data:/data'
zoo2:
image: zookeeper:3.5
container_name: zoo2
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- solr
volumes:
- 'zoo2_data:/data'
zoo3:
image: zookeeper:3.5
container_name: zoo3
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
ZOO_4LW_COMMANDS_WHITELIST: mntr,conf,ruok
command: bash -c "/apache-zookeeper-3.5.8-bin/bin/zkCli.sh -server zoo2:2181 create /solr '' && exec zkServer.sh start-foreground"
networks:
- solr
volumes:
- 'zoo3_data:/data'
depends_on:
- zoo1
- zoo2
solr1:
image: solr:8.3
container_name: solr1
ports:
- "8981:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr1varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
solr2:
image: solr:8.3
container_name: solr2
ports:
- "8982:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr2varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
solr3:
image: solr:8.3
container_name: solr3
ports:
- "8983:8983"
environment:
- ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181/solr
volumes:
- 'solr3varsolr:/var/solr'
networks:
- solr
depends_on:
- zoo1
- zoo2
- zoo3
networks:
solr:
volumes:
zoo1_data:
zoo2_data:
zoo3_data:
solr1varsolr:
solr2varsolr:
solr3varsolr:
答案 0 :(得分:0)
我可能在这里丢失了一些东西,但是我不确定为什么要在Zookeeper实例上“创建” solr目录?
Solr只是一个实例,它连接到zookeeper节点,对吧?
还是要在集成系统中连接多个系统?如果是这样的话,我认为您应该签出this solr-doc,它准确地表明了这一点(“使用chroot”)。
无论如何,如果您只想在不使用/solr
端点的情况下启动并运行它,这就是我的一个zookeeper节点在docker-compose中的样子(仅用于本地开发):>
zoo3:
image: library/zookeeper:3.5.7
container_name: zoo3
restart: always
hostname: zoo3
ports:
- 8384:8080
environment:
TZ: Europe/Paris
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
- solr
command: >
sh -c "ln -snf /usr/share/zoneinfo/$TZ /etc/localtime &&
echo $TZ > /etc/timezone &&
sed -i 's/autopurge.purgeInterval=0/autopurge.purgeInterval=1/g' /conf/zoo.cfg &&
echo 4lw.commands.whitelist=mntr,conf,ruok >> /conf/zoo.cfg &&
exec zkServer.sh start-foreground"
您唯一需要在solr-service中更改的是zoo3的URL,它从zoo3:2181/solr
到zoo3:2181
...已经被其他2个节点使用了; )
所有节点都使用相同的设置(当然,命名和ZOO_SERVERS
环境变量除外:))
希望这对您有所帮助,希望我没有让您感到困惑;)