docker-compose部署 kafka 3.7 集群(3台服务器)并启用账号密码认证

文章目录

  • [1. 规划](#1. 规划)
  • [2. 服务部署](#2. 服务部署)
    • [2.1 kafka-01](#2.1 kafka-01)
    • [2.2 kafka-02](#2.2 kafka-02)
    • [2.3 kafka-03](#2.3 kafka-03)
    • [2.4 启动服务](#2.4 启动服务)
  • [3. 测试](#3. 测试)
    • [3.1 kafkamap搭建(测试工具)](#3.1 kafkamap搭建(测试工具))
    • [3.2 测试](#3.2 测试)

1. 规划

服务 IP
kafka-01 10.10.xxx.199
kafka-02 10.10.xxx.198
kafka-03 10.10.xxx.197
kafkamp 10.10.xxx.199

2. 服务部署

2.1 kafka-01

  • 登录10.10.xxx.199,创建目录 kafka-01,进入该目录
  • 目录下创建docker-compose.yml 文件
yml 复制代码
version: "3"
services:
   kafka:
     image: 'bitnami/kafka:3.7.0'
     user: root
     ports:
       - '9092:9092'
       - '9093:9093'
     environment:
       - TZ=Asia/Shanghai
       - KAFKA_CFG_PROCESS_ROLES=broker,controller
       - BITNAMI_DEBUG=true 
       - ALLOW_PLAINTEXT_LISTENER=no
       - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
       - KAFKA_CFG_NUM_PARTITIONS=1
       - KAFKA_CFG_LISTENERS=INTERNAL://:9094,CLIENT://:9095,CONTROLLER://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092
       - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://10.10.181.199:9094,CLIENT://:9095,EXTERNAL://10.10.181.199:9092
       - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:SASL_PLAINTEXT,CLIENT:SASL_PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:SASL_PLAINTEXT   
       - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
       - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN
       - KAFKA_CFG_SASL_ENABLED_MECHANISMS=PLAIN
       - KAFKA_CLIENT_USERS=liubei
       - KAFKA_CLIENT_PASSWORDS=liubei@161
       - KAFKA_INTER_BROKER_USER=liuwei
       - KAFKA_INTER_BROKER_PASSWORD=liubei@161
       - KAFKA_CFG_NODE_ID=1
       - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@10.10.181.199:9093,2@10.10.181.198:9093,3@10.10.181.197:9093
       - KAFKA_KRAFT_CLUSTER_ID=xishu
       - KAFKA_OPTS=-Djava.security.auth.login.config=/bitnami/kafka/data/kafka_server_jaas.conf
     volumes:
       - ./data:/bitnami/kafka/data:rw

2.2 kafka-02

  • 登录10.10.xxx.198,创建目录 kafka-02,进入该目录
  • 目录下创建docker-compose.yml 文件
yml 复制代码
version: "3"
services:
   kafka:
     image: bitnami/kafka:3.7.0'
     user: root
     ports:
       - '9092:9092'
       - '9093:9093'
     environment:
       - TZ=Asia/Shanghai
       - KAFKA_CFG_PROCESS_ROLES=broker,controller
       - BITNAMI_DEBUG=true 
       - ALLOW_PLAINTEXT_LISTENER=no
       - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
       - KAFKA_CFG_NUM_PARTITIONS=1
       - KAFKA_CFG_LISTENERS=INTERNAL://:9094,CLIENT://:9095,CONTROLLER://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092
       - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://10.10.181.198:9094,CLIENT://:9095,EXTERNAL://10.10.181.198:9092
       - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:SASL_PLAINTEXT,CLIENT:SASL_PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:SASL_PLAINTEXT   
       - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
       - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN
       - KAFKA_CFG_SASL_ENABLED_MECHANISMS=PLAIN
       - KAFKA_CLIENT_USERS=liubei
       - KAFKA_CLIENT_PASSWORDS=liubei@161
       - KAFKA_INTER_BROKER_USER=liuwei
       - KAFKA_INTER_BROKER_PASSWORD=liubei@161
       - KAFKA_CFG_NODE_ID=2
       - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@10.10.181.199:9093,2@10.10.181.198:9093,3@10.10.181.197:9093
       - KAFKA_KRAFT_CLUSTER_ID=xishu
       - KAFKA_OPTS=-Djava.security.auth.login.config=/bitnami/kafka/data/kafka_server_jaas.conf
     volumes:
       - ./data:/bitnami/kafka/data:rw

2.3 kafka-03

  • 登录10.10.xxx.197,创建目录 kafka-03,进入该目录
  • 目录下创建docker-compose.yml 文件
yml 复制代码
version: "3"
services:
   kafka:
     image: bitnami/kafka:3.7.0'
     user: root
     ports:
       - '9092:9092'
       - '9093:9093'
     environment:
       - TZ=Asia/Shanghai
       - KAFKA_CFG_PROCESS_ROLES=broker,controller
       - BITNAMI_DEBUG=true 
       - ALLOW_PLAINTEXT_LISTENER=no
       - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
       - KAFKA_CFG_NUM_PARTITIONS=1
       - KAFKA_CFG_LISTENERS=INTERNAL://:9094,CLIENT://:9095,CONTROLLER://0.0.0.0:9093,EXTERNAL://0.0.0.0:9092
       - KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://10.10.181.197:9094,CLIENT://:9095,EXTERNAL://10.10.181.197:9092
       - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:SASL_PLAINTEXT,CLIENT:SASL_PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:SASL_PLAINTEXT   
       - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
       - KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=PLAIN
       - KAFKA_CFG_SASL_ENABLED_MECHANISMS=PLAIN
       - KAFKA_CLIENT_USERS=liubei
       - KAFKA_CLIENT_PASSWORDS=liubei@161
       - KAFKA_INTER_BROKER_USER=liuwei
       - KAFKA_INTER_BROKER_PASSWORD=liubei@161
       - KAFKA_CFG_NODE_ID=2
       - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@10.10.181.199:9093,2@10.10.181.198:9093,3@10.10.181.197:9093
       - KAFKA_KRAFT_CLUSTER_ID=xishu
       - KAFKA_OPTS=-Djava.security.auth.login.config=/bitnami/kafka/data/kafka_server_jaas.conf
     volumes:
       - ./data:/bitnami/kafka/data:rw

2.4 启动服务

  • 每台服务器上执行
shell 复制代码
docker-compose up -d

3. 测试

3.1 kafkamap搭建(测试工具)

  • 登录10.10.xxx.199,创建kafkamap目录,进入该目录
  • 创建docker-compose.yml文件如下
shell 复制代码
version: "3"
services:
   kafka_map:
     image: dushixiang/kafka-map:latest
     environment:
       - DEFAULT_USERNAME=liubei
       - DEFAULT_PASSWORD=liubei@161
     ports:
       - '8080:8080'

3.2 测试

  • 连接集群
  • 连接成功
  • 进入topic
  • 创建topic

相关推荐
LIKEYYLL1 小时前
GNU Octave:特性、使用案例、工具箱、环境与界面
服务器·gnu
云云3212 小时前
搭建云手机平台的技术要求?
服务器·线性代数·安全·智能手机·矩阵
云云3212 小时前
云手机有哪些用途?云手机选择推荐
服务器·线性代数·安全·智能手机·矩阵
玖疯子2 小时前
介绍 Docker 的基本概念和优势,以及在应用程序开发中的实际应用。
docker
暴富的Tdy2 小时前
【快速上手Docker 简单配置方法】
docker·容器·eureka
CircleMouse2 小时前
Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org
linux·运维·服务器·centos
Karoku0663 小时前
【k8s集群应用】kubeadm1.20高可用部署(3master)
运维·docker·云原生·容器·kubernetes
木子Linux3 小时前
【Linux打怪升级记 | 问题01】安装Linux系统忘记设置时区怎么办?3个方法教你回到东八区
linux·运维·服务器·centos·云计算
不惑_4 小时前
小白入门 · 腾讯云轻量服务器部署 Hadoop 3.3.6
服务器·hadoop·腾讯云
阿甘知识库4 小时前
宝塔面板跨服务器数据同步教程:双机备份零停机
android·运维·服务器·备份·同步·宝塔面板·建站