单机版
window下
新建一个文件 kafka-alone.yml,文件内容如下:
version: '2'
services:
zk:
image: zookeeper:3.6
container_name: zk_c0
ports:
- 2181:2181
kafka:
image: wurstmeister/kafka:2.12-2.5.0
hostname: kafka-alone
container_name: kafka_c0
ports:
- 9092:9092
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zk:2181
volumes:
- D:/mount/kafka/logs:/kafka
D:/mount/kafka/logs 是挂载的目录,提前创建好即可
运行命令:
docker compose -f kafka-alone.yml create
linux下
修改一个挂载目录即可
集群版
新建一个文件 kafka-cloud.yml,文件内容如下:
version: '2'
services:
zk1:
image: zookeeper:3.6
restart: always
container_name: zk_c1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
zk2:
image: zookeeper:3.6
restart: always
container_name: zk_c2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
zk3:
image: zookeeper:3.6
restart: always
container_name: zk_c3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
kafka1:
image: wurstmeister/kafka:2.12-2.5.0
restart: always
hostname: kafka1
container_name: kafka1
ports:
- 9092:9092
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
volumes:
- /opt/kfkluster/kafka1/logs:/kafka
external_links:
- zk1
- zk2
- zk3
kafka2:
image: wurstmeister/kafka:2.12-2.5.0
restart: always
hostname: kafka2
container_name: kafka2
ports:
- 9093:9093
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka2
KAFKA_ADVERTISED_PORT: 9093
KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
volumes:
- /opt/kfkluster/kafka2/logs:/kafka
external_links:
- zk1
- zk2
- zk3
kafka3:
image: wurstmeister/kafka:2.12-2.5.0
restart: always
hostname: kafka3
container_name: kafka3
ports:
- 9094:9094
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka3
KAFKA_ADVERTISED_PORT: 9094
KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
volumes:
- /opt/kfkluster/kafka3/logs:/kafka
external_links:
- zk1
- zk2
- zk3
运行命令:
docker compose -f kafka-cloud.yml create
#下载Kafka可视化工具
具体使用步骤参考:https://www.cnblogs.com/frankdeng/p/9452982.html