运行“docker compose up”时出错:配置无效,异常退出

6jjcrrmo  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(350)

我有三个不同的节点,每个节点上都有带有ubuntu的docker。我想用这三个节点组成kafka集群;事实上,我在每个节点上都安装了docker,并加载了ubuntu。我配置 "zookeeper.properties" 在“150.20.11.157”的docker环境中,如下所示:

dataDir=/tmp/zookeeper/data
tickTime=2000
initLimit=10
syncLimit=5
server.1=0.0.0.0:2888:3888
server.2=150.20.11.134:2888:3888
server.3=150.20.11.137:2888:3888
clientPort=2186

对于节点150.20.11.134,docker环境中的“zookeeper.properties”文件如下:

dataDir=/tmp/zookeeper/data
tickTime=2000
initLimit=10
syncLimit=5
server.1=150.20.11.157:2888:3888
server.2=0.0.0.0:2888:3888
server.3=150.20.11.137:2888:3888
clientPort=2186

对于节点150.20.11.137,docker环境中的“zookeeper.properties”文件如下:

dataDir=/tmp/zookeeper/data
tickTime=2000
initLimit=10
syncLimit=5
server.1=150.20.11.157:2888:3888
server.2=150.20.11.134:2888:3888
server.3=0.0.0.0:2888:3888
clientPort=2186

另外,我为节点150.20.11.157设置如下“server.properties”:

broker.id=0
port=9092
listeners = PLAINTEXT://150.20.11.157:9092
log.dirs=/tmp/kafka-logs 
zookeeper.connect=150.20.11.157:2186,150.20.11.134:2186,
150.20.11.137:2186

节点150.20.11.134的“server.properties”是:

broker.id=1
port=9092
listeners = PLAINTEXT://150.20.11.134:9092
log.dirs=/tmp/kafka-logs 
zookeeper.connect=150.20.11.157:2186,150.20.11.134:2186,
150.20.11.137:2186

节点150.20.11.137的“server.properties”是:

broker.id=2
port=9092
listeners = PLAINTEXT://150.20.11.137:9092
log.dirs=/tmp/kafka-logs 
zookeeper.connect=150.20.11.157:2186,150.20.11.134:2186,
150.20.11.137:2186

此外,每个节点在docker环境的“/tmp/zookeeper/data”中都有一个“myid”文件,其中包含服务器id。
为了创建一个由三个节点组成的kafka集群,我为它创建了一个“docker compose.yaml”文件和一个dockerfile。

这是我的docker撰写文件:

version: '3.7'

services:
    zookeeper:
       build: .
       command: /root/kafka_2.11-2.0.1/bin/zookeeper-server-start.sh 
       /root/kafka_2.11-2.0.1/config/zookeeper.properties
       ports:
        - 2186:2186
    kafka1:
       build:
        context: .
        args:
          brokerId: 0
        command: /root/kafka_2.11-2.0.1/bin/kafka-server-start.sh 
        /root/kafka_2.11-2.0.1/config/server.properties
        depends_on:
         - zookeeper
    kafka2:
       build:
        context: .
        args:
          brokerId: 1
        command: /root/kafka_2.11-2.0.1/bin/kafka-server-start.sh 
        /root/kafka_2.11-2.0.1/config/server.properties
        depends_on:
         - zookeeper
    kafka3:
       build:
         context: .
        args:
          brokerId: 2
        command: /root/kafka_2.11-2.0.1/bin/kafka-server-start.sh 
        /root/kafka_2.11-2.0.1/config/server.properties
        depends_on:
         - zookeeper
   producer:
       build: .
       command: bash -c "sleep 4 && /root/kafka_2.11-2.0.1/bin/kafka- 
       topics.sh --create --zookeeper zookeeper:2186 --replication- 
       factor 2 --partitions 3 --topic dates && while true; do date | 
       /kafka_2.11-2.0.1/bin/kafka-console-producer.sh --broker-list 
       kafka1:9092,kafka2:9092,kafka3:9092 --topic dates; sleep 1; 
       done "
      depends_on:
        - zookeeper
        - kafka1
        - kafka2
        - kafka3
  consumer:
      build: .
      command: bash -c "sleep 6 && /root/kafka_2.11-2.0.1/bin/kafka- 
      console-consumer.sh localhost:9092 --topic dates --bootstrap- 
      server kafka1:9092,kafka2:9092,kafka3:9092"
      depends_on:
        - zookeeper
        - kafka1
        - kafka2
        - kafka3

问题是在“dockerfile build”之后,当我在每个节点上执行“sudo docker compose up”时。它不能完全运行。我的一些日志如下:
zookeeper|[2019-01-17 16:09:27197]信息读取配置来自:/root/kafka|2.11-2.0.1/config/zookeeper.properties(org.apache.zookeeper.server.quorum.quorumpeerconfig)
kafka3|[2019-01-17 16:09:29426]信息注册kafka:type=kafka.log4jcontroller mbean(kafka.utils.log4jcontrollerregistration$)
kafka3|[2019-01-17 16:09:29702]信息启动(kafka.server.kafkaserver)
kafka3|[2019-01-17 16:09:29702]连接到zookeeper的信息:150.20.11.157:2186150.20.11.134:2186150.20.11.137:2186(kafka.server.kafkaserver)
Kafka1 |[2019-01-17 16:09:30012]信息注册kafka:type=kafka.log4jcontroller mbean(kafka.utils.log4jcontrollerregistration$)
zookeeper|[2019-01-17 16:09:27240]信息解析主机名:150.20.11.137到地址:/150.20.11.137(org.apache.zookeeper.server.quorum.quorumpeer)
kafka1|[2019-01-17 16:09:30486]信息启动(kafka.server.kafkaserver)
kafka3|[2019-01-17 16:09:29715]信息[zookeeperclient]初始化新会话至150.20.11.157:2186150.20.11.134:2186150.20.11.137:2186(Kafka。Zookeeper。Zookeeper)
zookeeper|[2019-01-17 16:09:27241]信息解析主机名:150.20.11.134到地址:/150.20.11.134(org.apache.zookeeper.server.quorum.quorumpeer)
zookeeper|[2019-01-17 16:09:27241]信息解析主机名:0.0.0.0到地址:/0.0.0.0(org.apache.zookeeper.server.quorum.quorumpeer)kafka3|[2019-01-17 16:09:29720]信息客户端environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03,建于2018年6月29日00:39 gmt(org.apache.zookeeper.zookeeper)
zookeeper|[2019-01-17 16:09:27241]默认为多数配额的信息(org.apache.zookeeper.server.quorum.quorumpeerconfig)kafka3|[2019-01-17 16:09:29721]信息客户端environment:host.name=be08b050be4c (org.apache.zookeeper.zookeeper)
zookeeper|[2019-01-17 16:09:27242]错误无效配置,异常退出(org.apache.zookeeper.server.quorum.quorumpeermain)zookeeper|u 1 | org.apache.zookeeper.server.quorum.quorumpeerconfig$configexception:在org.apache.zookeeper.server.quorum.quorumpeerconfig.parse(quorumpeerconfig)处理/root/kafka_.11-2.0.1/config/zookeer.properties zookeer|u 1 |时出错。java:156)Zookeeperorg.apache.zookeeper.server.quorum.quorumpeermain.initializeandrun(quorumpeermain。java:104)zookeeper|位于org.apache.zookeeper.server.quorum.quorumpeermain.main(quorumpeermain)。java:81)zookeeper|原因:java.lang.illegalargumentexception:/tmp/zookeeper/data/myid文件在org.apache.zookeeper.server.quorum.quorumpeerconfig.parseproperties(quorumpeerconfig。java:408)zookeeper|位于org.apache.zookeeper.server.quorum.quorumpeerconfig.parse(quorumpeerconfig)。java:152)Zookeeper。。。2个以上
kafka1|[2019-01-17 16:09:30487]连接到zookeeper的信息:150.20.11.157:2186150.20.11.134:2186150.20.11.137:2186(kafka.server.kafkaserver)zookeeper|配置无效,退出异常
事实上,我没有在每个节点上使用docker就配置了kafka集群,并且可以毫无问题地运行zookeeper和kafka服务器。Kafka星团就像这样:

你能告诉我配置这个群集有什么不对吗?
任何帮助都将不胜感激。

9udxz4iz

9udxz4iz1#

我修改了docker文件并解决了问题。zookeeper和kafka服务器运行正常。主题已创建。此外,消费者和生产者在三个节点中处理主题。我为一个节点编写的docker如下所示:

version: '3.7'
 services:
   zookeeper:
     image: ubuntu_mesos
     command: /root/kafka_2.11-2.0.1/bin/zookeeper-server-start.sh 
     /root/kafka_2.11-2.0.1/config/zookeeper.properties
     environment:
      ZOOKEEPER_SERVER_ID: 1
      ZOOKEEPER_CLIENT_PORT: 2186
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_INIT_LIMIT: 10
      ZOOKEEPER_SYNC_LIMIT: 5
      ZOOKEEPER_SERVERS: 
      0.0.0.0:2888:3888;150.20.11.134:2888:3888;150.20.11.137:2888:3888
    network_mode: host
    expose:
    - 2186 
    - 2888
    - 3888
    ports:
    - 2186:2186
    - 2888:2888
    - 3888:3888

kafka:
    image: ubuntu_mesos
    command: bash -c "sleep 20; /root/kafka_2.11-2.0.1/bin/kafka-server- 
    start.sh /root/kafka_2.11-2.0.1/config/server.properties"
    network_mode: host
    depends_on:
     - zookeeper
    environment:
     KAFKA_BROKER_ID: 0
     KAFKA_ZOOKEEPER_CONNECT: 
     150.20.11.157:2186,150.20.11.134:2186,150.20.11.137:2186
     KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://150.20.11.157:9092
   expose:
      - 9092
    ports:
      - 9092:9092      

producer:
    image: ubuntu_mesos
    command: bash -c "sleep 40; /root/kafka_2.11-2.0.1/bin/kafka-topics.sh -- 
    create --zookeeper 150.20.11.157:2186 --replication-factor 2 --partitions 
    3 --topic testFlink -- /root/kafka_2.11-2.0.1/bin/kafka-console- 
    producer.sh --broker-list 150.20.11.157:9092 --topic testFlink"
    depends_on:
    - zookeeper
    - kafka

consumer:
    image: ubuntu_mesos
    command: bash -c "sleep 44; /root/kafka_2.11-2.0.1/bin/kafka-console- 
    consumer.sh --bootstrap-server 150.20.11.157:9092 --topic testFlink -- 
    from-beginning"
    depends_on:
    - zookeeper
    - kafka

另外两个节点的docker组成也和上面一样。希望对其他人有帮助。

相关问题