我正在创建一个3节点的Zookeeper集群和3节点的Kafka集群。当我创建Zookeeper集群时,对于其他两个节点中的每个节点,仅创建一个Zookeeper节点,而其他两个以以下错误退出:

zookeeper-3_1  | 2018-02-13 17:38:22,310 [myid:] - INFO  [main:ServerCnxnFactory@117] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
zookeeper-3_1  | 2018-02-13 17:38:22,322 [myid:] - INFO  [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
zookeeper-3_1  | 2018-02-13 17:38:22,323 [myid:] - ERROR [main:ZooKeeperServerMain@66] - Unexpected exception, exiting abnormally
zookeeper-3_1  | java.net.BindException: Address in use
zookeeper-3_1  |    at sun.nio.ch.Net.bind0(Native Method)
zookeeper-3_1  |    at sun.nio.ch.Net.bind(Net.java:433)
zookeeper-3_1  |    at sun.nio.ch.Net.bind(Net.java:425)
zookeeper-3_1  |    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
zookeeper-3_1  |    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
zookeeper-3_1  |    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
zookeeper-3_1  |    at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:90)
zookeeper-3_1  |    at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:119)
zookeeper-3_1  |    at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:89)
zookeeper-3_1  |    at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:55)
zookeeper-3_1  |    at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:119)
zookeeper-3_1  |    at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:81)

我认为这是因为Zookeeper的所有节点都使用端口2181。但是,在我的docker-compose.yml文件中,我为每个节点指定了不同的客户端端口,并且为Zookeeper服务器指定了不同的端口。

我的docker-compose.yml代码是-
version: '2'
services:
  zookeeper-1:
    image: zookeeper:latest
    environment:
      ZOOKEEPER_SERVER_ID: 1
      ZOOKEEPER_CLIENT_PORT: 22181
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_INIT_LIMIT: 5
      ZOOKEEPER_SYNC_LIMIT: 2
      ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
    network_mode: host

  zookeeper-2:
    image: zookeeper:latest
    environment:
      ZOOKEEPER_SERVER_ID: 2
      ZOOKEEPER_CLIENT_PORT: 32181
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_INIT_LIMIT: 5
      ZOOKEEPER_SYNC_LIMIT: 2
      ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
    network_mode: host

  zookeeper-3:
    image: zookeeper:latest
    environment:
      ZOOKEEPER_SERVER_ID: 3
      ZOOKEEPER_CLIENT_PORT: 42181
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_INIT_LIMIT: 5
      ZOOKEEPER_SYNC_LIMIT: 2
      ZOOKEEPER_SERVERS: localhost:22888:23888;localhost:32888:33888;localhost:42888:43888
    network_mode: host

  kafka1:
    image: abc/kafka:latest
    hostname: kafka1
    network_mode: host
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:19092
    depends_on:
      - zookeeper-1
      - zookeeper-2
      - zookeeper-3

  kafka2:
    image: abc/kafka:latest
    hostname: kafka2
    network_mode: host
    environment:
      KAFKA_BROKER_ID: 2
      KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092
    depends_on:
      - zookeeper-1
      - zookeeper-2
      - zookeeper-3

  kafka3:
    image: abc/kafka:latest
    hostname: kafka3
    network_mode: host
    environment:
      KAFKA_BROKER_ID: 3
      KAFKA_ZOOKEEPER_CONNECT: localhost:22181,localhost:32181,localhost:42181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:39092
    depends_on:
      - zookeeper-1
      - zookeeper-2
      - zookeeper-3

我还放置了用于创建Kafka镜像的Dockerfile
FROM centos:7
MAINTAINER [email protected]

ENV KAFKA_BIN=http://www-eu.apache.org/dist/kafka/0.11.0.2/kafka_2.11-0.11.0.2.tgz

RUN yum install -y wget java-1.8.0-openjdk \
    && cd /tmp && wget -q $KAFKA_BIN \
    && export K_TAR=/tmp/$(ls kafka* | head -1) \
    && mkdir -p /opt/apache/kafka/ && tar -zxf $K_TAR -C /opt/apache/kafka/ \
    && cd /opt/apache/kafka && ln -s $(ls) current \
    && rm -rf $K_TAR

ENV KAFKA_HOME /opt/apache/kafka/current
ENV PATH $PATH:$KAFKA_HOME/bin

ADD resources /home/kafka

RUN groupadd -r kafka \
    && useradd -r -g kafka kafka \
    && mkdir -p /home/kafka \
    && chown -R kafka:kafka /home/kafka \
    && chmod -R +x /home/kafka/scripts \
    && mkdir -p /var/log/kafka \
    && chown -R kafka:kafka /var/log/kafka \
    && mkdir -p /etc/kafka \
    && chown -R kafka:kafka /etc/kafka

USER kafka

有人可以帮我吗-关于为什么我在运行docker-compose up命令时无法启动3节点Zookeeper集群?谢谢

最佳答案

您尝试使用主机网络,然后只能绑定(bind)一次地址。因此,您可能要使用其他端口,或者不使用主机网络,并在必要时公开端口。

然后,您可以将它们命名为zookeeper-1,zookeeper-2 ...

如果kafka节点要访问Zookeeper,则应对它们进行相同的操作,应通过zookeeper-1,zookeeper-2对其进行访问...
(我无法测试此操作,因为我无法构建abc / kafka镜像,因为我错过了Dockerfile中的资源文件夹)

关于docker - Zookeeper集群未在Docker上启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48772906/

10-15 19:15