基于this example,我们创建了以下docker-compose文件docker-compose.yaml:
<table>
<thead><th>#</th><th>Name</th>
</thead>
<tbody>
<tr><td>1<td>Susie</td></tr>
<tr><td>2<td>John</td></tr>
</tbody>
运行version: '2'
services:
kafka1:
image: wurstmeister/kafka
depends_on:
- zoo1
- zoo2
- zoo3
ports:
- "9092:9092"
environment:
KAFKA_LOG_DIRS: /kafka1
KAFKA_BROKER_ID: 1
KAFKA_CREATE_TOPICS: my-topic-1:1:2,my-topic-2:1:2
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
kafka2:
image: wurstmeister/kafka
depends_on:
- zoo1
- zoo2
- zoo3
ports:
- "9093:9092"
environment:
KAFKA_LOG_DIRS: /kafka2
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9093
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
kafka3:
image: wurstmeister/kafka
depends_on:
- zoo1
- zoo2
- zoo3
ports:
- "9094:9092"
environment:
KAFKA_LOG_DIRS: /kafka3
KAFKA_BROKER_ID: 3
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_ADVERTISED_PORT: 9094
KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
zoo1:
image: elevy/zookeeper:latest
environment:
MYID: 1
SERVERS: zoo1,zoo2,zoo3
ports:
- "2181:2181"
- "2888"
- "3888"
zoo2:
image: elevy/zookeeper:latest
environment:
MYID: 2
SERVERS: zoo1,zoo2,zoo3
ports:
- "2182:2181"
- "2888"
- "3888"
zoo3:
image: elevy/zookeeper:latest
environment:
MYID: 3
SERVERS: zoo1,zoo2,zoo3
ports:
- "2183:2181"
- "2888"
- "3888"
显示了三个Zookeeper实例和三个kafka代理正在启动。实际尝试在localhost:9092上连接到kafka时,出现错误。检查日志显示kafka1可以正常启动,但是kafka2和kafka3都存在以下错误:
docker-compose up -d