kafka集群搭建
docker-compose.yaml
version: '3.9'
services:
zookeeper:
image: wurstmeister/zookeeper
restart: always
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
volumes:
- ./zookeeper/data:/data
- ./zookeeper/datalog:/datalog
kafka1:
image: wurstmeister/kafka
restart: always
hostname: kafka1
container_name: kafka1
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_PORT: 9092
KAFKA_BROKER_ID: 1
volumes:
- ./kafka1/logs:/kafka/logs
kafka2:
image: wurstmeister/kafka
restart: always
hostname: kafka2
container_name: kafka2
ports:
- "9093:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_PORT: 9092
KAFKA_BROKER_ID: 2
volumes:
- ./kafka2/logs:/kafka/logs
测试运行状态
# 进入到kafka工具集
/opt/kafka_2.12-2.3.0
# broker能够响应请求,通常意味着它正在运行
bin/kafka-broker-api-versions.sh --bootstrap-server kafka1:9092,kafka2:9092