Kafka:使用wurstmeister / zookeeper映像在Docker中设置Kafka Zookeeper群集时出错

时间:2018-07-31 09:39:53

标签: docker apache-kafka docker-compose dockerfile docker-swarm

我正在尝试使用以下docker-compose.yml文件在docker中设置多个zookeeper和多个kafka代理群集。

version: '3.1'

services:
  zookeeper1:
    image: wurstmeister/zookeeper
    ports:
      - "2185:2181"
  zookeeper2:
    image: wurstmeister/zookeeper
    ports:
      - "2186:2181"
    depends_on:
     - zookeeper1
  zookeeper3:
    image: wurstmeister/zookeeper
    ports:
      - "2187:2181"
    depends_on:
     - zookeeper1
     - zookeeper2
  kafka1:
    image: "wurstmeister/kafka"
    hostname: kafka1
    ports:
     - "9095:9092"
    depends_on:
     - zookeeper1
     - zookeeper2
     - zookeeper3
    environment:
     - KAFKA_ADVERTISED_HOST_NAME=kafka1
     - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
     - KAFKA_ADVERTISED_PORT=9092
     - KAFKA_BROKER_ID=1
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
  kafka2:
    image: "wurstmeister/kafka"
    hostname: kafka2
    ports:
     - "9096:9092"
    depends_on:
     - zookeeper1
     - zookeeper2
     - zookeeper3
    environment:
     - KAFKA_ADVERTISED_HOST_NAME=kafka2
     - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
     - KAFKA_ADVERTISED_PORT=9092
     - KAFKA_BROKER_ID=2
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
  kafka3:
    image: "wurstmeister/kafka"
    hostname: kafka3
    ports:
     - "9097:9092"
    depends_on:
     - zookeeper1
     - zookeeper2
     - zookeeper3
     - kafka1
     - kafka2
    environment:
     - KAFKA_ADVERTISED_HOST_NAME=kafka3
     - KAFKA_ZOOKEEPER_CONNECT=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
     - KAFKA_ADVERTISED_PORT=9092
     - KAFKA_CREATE_TOPICS=check_new:3:1
     - KAFKA_BROKER_ID=3
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock

但是Zookeeper群集无法获取 形成。例如使用命令

zookeeper1
kafka-topics.sh --create --topic test --replication-factor 1 --partitions 5 --zookeeper zookeeper1:2181
创建

topic,而使用以下命令,例如与zookeeper2zookeeper3

kafka-topics.sh --create --topic test --replication-factor 1 --partitions 5 --zookeeper zookeeper2:2181

OR

kafka-topics.sh --create --topic test --replication-factor 1 --partitions 5 --zookeeper zookeeper3:2181

我收到错误消息

Error while executing topic command : Replication factor: 1 larger than available brokers: 0.
[2018-07-31 09:17:55,326] ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 1 larger than available brokers: 0.
 (kafka.admin.TopicCommand$)

问题是什么,我需要在Zookeeper图片中提供broker_ids的任何地方吗?这样Zookeeper集群才能正常工作

0 个答案:

没有答案