Docker安装Kafka
官方文档地址:https://kafka.apache.org/documentation/#docker
镜像地址:https://hub.docker.com/r/apache/kafka
官方案例及说明地址:https://github.com/apache/kafka/tree/trunk/docker/examples
一些第三方参考文档:https://docs.confluent.io/platform/current/installation/docker/config-reference.html
Apache Kafka 从版本 3.7.0 开始在Docker Hub 上提供 Docker 映像
1.docker compose 文件
version: '2'
services:
kafka-kraft:
image: apache/kafka:latest
hostname: kafka-kraft
container_name: kafka-kraft
ports:
- '9092:9092'
environment:
KAFKA_NODE_ID: 1
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT'
# KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT_HOST://localhost:9092,PLAINTEXT://kafka-kraft:29092' 向外暴露则改成宿主机的IP地址
KAFKA_ADVERTISED_LISTENERS: 'PLAINTEXT_HOST://192.168.58.134:9092,PLAINTEXT://kafka-kraft:29092'
KAFKA_PROCESS_ROLES: 'broker,controller'
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka-kraft:29093'
KAFKA_LISTENERS: 'CONTROLLER://kafka-kraft:29093,PLAINTEXT_HOST://0.0.0.0:9092,PLAINTEXT://kafka-kraft:29092'
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
CLUSTER_ID: '4L6g3nShT-eMCtK--X86sw'
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_LOG_DIRS: '/tmp/kraft-combined-logs'
2.运行
docker compose up -d