容器化部署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

相关推荐
c无序8 分钟前
【Docker-7】Docker是什么+Docker版本+Docker架构+Docker生态
docker·容器·架构
FixBug_Nick10 分钟前
使用Docker安装及使用最新版本的Jenkins
docker·容器·jenkins
数据智能老司机22 分钟前
CockroachDB权威指南——CockroachDB 架构
数据库·分布式·架构
IT成长日记27 分钟前
【Kafka基础】Kafka工作原理解析
分布式·kafka
州周2 小时前
kafka副本同步时HW和LEO
分布式·kafka
Zero_to_zero12342 小时前
解决docker的ubuntu系统中文乱码问题
ubuntu·docker·容器
@郭小茶2 小时前
docker-compose方式部署docker项目
运维·docker·容器
爱的叹息4 小时前
主流数据库的存储引擎/存储机制的详细对比分析,涵盖关系型数据库、NoSQL数据库和分布式数据库
数据库·分布式·nosql
程序媛学姐4 小时前
SpringKafka错误处理:重试机制与死信队列
java·开发语言·spring·kafka
千层冷面5 小时前
RabbitMQ 发送者确认机制详解
分布式·rabbitmq·ruby