docker-compose快速部署Kafka集群

概述

单节点移步 ==> docker-compose快速部署Kafka,以及常见问题解决

注意事项

  • 不要配置restart: always,如果有问题,会一直重启。
  • 将数据挂载到本地并指定路径,可能会有Permission denied问题。
  • KAFKA_CFG_LISTENERS=CLIENT://:9092,端口前不要加IP,否则无法启动。
  • kafka3需要jdk11,容器内置。
  • 启动完成之后,ps命令检查一下,如果未完全启动,则down掉再up几遍。

脚本

docker-compose.yml

version: '2'

services:
  zk1:
    image: bitnami/zookeeper:3.7
    container_name: zk1
    hostname: zk1
    ports:
      - "2181:2181"
    volumes:
      - "zk1_data:/bitnami"
    environment:
      - ZOO_SERVER_ID=1
      - ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
      - ALLOW_ANONYMOUS_LOGIN=yes

  zk2:
    image: bitnami/zookeeper:3.7
    container_name: zk2
    hostname: zk1
    ports:
      - "2182:2181"
    volumes:
      - "zk2_data:/bitnami"
    environment:
      - ZOO_SERVER_ID=2
      - ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
      - ALLOW_ANONYMOUS_LOGIN=yes

  zk3:
    image: bitnami/zookeeper:3.7
    container_name: zk3
    hostname: zk1
    ports:
      - "2183:2181"
    volumes:
      - "zk3_data:/bitnami"
    environment:
      - ZOO_SERVER_ID=3
      - ZOO_SERVERS=zk1:2888:3888,zk2:2888:3888,zk3:2888:3888
      - ALLOW_ANONYMOUS_LOGIN=yes

  kafka1:
    image: bitnami/kafka:3
    container_name: kafka1
    depends_on:
      - zk1
      - zk2
      - zk3
    hostname: kafka1
    ports:
      - 20123:20123
    volumes:
      - "kafka1_data:/bitnami"
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20123
      - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka1:9092,EXTERNAL://192.168.2.134:20123
      - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true

  kafka2:
    image: bitnami/kafka:3
    container_name: kafka2
    depends_on:
      - zk1
      - zk2
      - zk3
    hostname: kafka2
    ports:
      - 20124:20124
    volumes:
      - "kafka2_data:/bitnami"
    environment:
      - KAFKA_BROKER_ID=2
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20124
      - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka2:9092,EXTERNAL://192.168.2.134:20124
      - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true

  kafka3:
    image: bitnami/kafka:3
    container_name: kafka3
    depends_on:
      - zk1
      - zk2
      - zk3
    hostname: kafka3
    ports:
      - 20125:20125
    volumes:
      - "kafka3_data:/bitnami"
    environment:
      - KAFKA_BROKER_ID=3
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CLIENT:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=CLIENT://:9092,EXTERNAL://:20125
      - KAFKA_CFG_ADVERTISED_LISTENERS=CLIENT://kafka3:9092,EXTERNAL://192.168.2.134:20125
      - KAFKA_INTER_BROKER_LISTENER_NAME=CLIENT
      - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true

  kafdrop:
    image: obsidiandynamics/kafdrop:latest
    container_name: kafdrop
    depends_on:
      - kafka1
      - kafka2
      - kafka3
    ports:
      - 9000:9000
    environment:
      - KAFKA_BROKERCONNECT=kafka1:9092,kafka2:9092,kafka3:9092
      
volumes:
  zk1_data:
    driver: local
  zk2_data:
    driver: local
  zk3_data:
    driver: local
  kafka1_data:
    driver: local
  kafka2_data:
    driver: local
  kafka3_data:
    driver: local

管理页面

http://localhost:9000/

基础命令

# 启动
docker-compose up -d 
# 停止
docker-compose down
# 查看
docker-compose ps 
# 日志
docker-compose logs <container_name>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码上富贵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值