容器化部署kafka内外网分流

一、清理卷:

bash 复制代码
docker volume rm docker-kafka_kafka_0_data  docker-kafka_kafka_1_data  docker-kafka_kafka_2_data  docker-kafka_zookeeper_data

二、编辑yml:

bash 复制代码
vi docker-compose.yml
yaml 复制代码
version: "2"

services:
  
  zookeeper:
    container_name: zookeeper
    hostname: zookeeper
    image: bitnami/zookeeper:3.8
    ports:
      - "2181"
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
    volumes:
      - zookeeper_data:/bitnami/zookeeper

  kafka-0:
    container_name: kafka-0
    hostname: kafka-0
    image: bitnami/kafka:3.2
    ports:
      - "9092"
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_BROKER_ID=0
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=INTERNAL://:9092,EXTERNAL://0.0.0.0:9093
      - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka-0:9092,EXTERNAL://192.168.71.33:9093
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
    volumes:
      - kafka_0_data:/bitnami/kafka
    depends_on:
      - zookeeper

  kafka-1:
    container_name: kafka-1
    hostname: kafka-1
    image: bitnami/kafka:3.2
    ports:
      - "9092"
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_BROKER_ID=1
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=INTERNAL://:9092,EXTERNAL://0.0.0.0:9094
      - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka-1:9092,EXTERNAL://192.168.71.33:9094
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
    volumes:
      - kafka_1_data:/bitnami/kafka
    depends_on:
      - zookeeper

  kafka-2:
    container_name: kafka-2
    hostname: kafka-2
    image: bitnami/kafka:3.2
    ports:
      - "9092"
    environment:
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_CFG_BROKER_ID=2
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
      - KAFKA_CFG_LISTENERS=INTERNAL://:9092,EXTERNAL://0.0.0.0:9095
      - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://kafka-2:9092,EXTERNAL://192.168.71.33:9095
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
    volumes:
      - kafka_2_data:/bitnami/kafka
    depends_on:
      - zookeeper

  nginx:
    container_name: nginx
    hostname: nginx
    image: nginx:1.22.0-alpine
    volumes:
    - /opt/kafka/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "9093-9095:9093-9095"
    depends_on:
      - kafka-0
      - kafka-1
      - kafka-2

volumes:
  zookeeper_data:
    driver: local
  kafka_0_data:
    driver: local
  kafka_1_data:
    driver: local
  kafka_2_data:
    driver: local

三、运行容器:

bash 复制代码
docker compose up -d

四、测试:

bash 复制代码
docker exec -it kafka-0 /opt/bitnami/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka-0:9092 --topic mytopic

EOF

相关推荐
染诗3 小时前
docker部署flask项目后,请求时总是报拒绝连接错误
docker·容器·flask
小林想被监督学习5 小时前
RabbitMQ 在实际应用时要注意的问题
分布式·rabbitmq
S-X-S5 小时前
项目集成RabbitMQ
分布式·rabbitmq
DA02215 小时前
Win10系统部署RabbitMQ Server
分布式·rabbitmq
张3蜂5 小时前
docker 部署.netcore应用优势在什么地方?
docker·容器·.netcore
费曼乐园7 小时前
Kafka与ZooKeeper
zookeeper·kafka
心惠天意7 小时前
docker-compose篇---创建jupyter并可用sudo的创建方式
docker·jupyter·容器
huaweichenai8 小时前
windows下修改docker的镜像存储地址
运维·docker·容器
菠萝炒饭pineapple-boss8 小时前
Dockerfile另一种使用普通用户启动的方式
linux·docker·dockerfile
想做富婆10 小时前
大数据,Hadoop,HDFS的简单介绍
大数据·hadoop·分布式