docker run 部署
shell
docker run -d --name zookeeper --restart always -p 2181:2181 wurstmeister/zookeeper
docker run -d --name kafka1 --restart always -p 9094:9092 \
-e KAFKA_ADVERTISED_HOST_NAME=182.54.14.45 \
-e KAFKA_ZOOKEEPER_CONNECT=182.54.14.45:2181 \
-e KAFKA_BROKER_ID=1 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.54.14.45:9094 \
-e KAFKA_LISTENERS=PLAINTEXT://:9092 \
-v /var/run/docker.sock:/var/run/docker.sock \
wurstmeister/kafka:0.10.2.1
docker run -d --name kafka2 --restart always -p 9093:9092 \
-e KAFKA_ADVERTISED_HOST_NAME=182.54.14.45 \
-e KAFKA_ZOOKEEPER_CONNECT=182.54.14.45:2181 \
-e KAFKA_BROKER_ID=2 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.54.14.45:9093 \
-e KAFKA_LISTENERS=PLAINTEXT://:9092 \
-v /var/run/docker.sock:/var/run/docker.sock \
wurstmeister/kafka:0.10.2.1
docker-compose.yml 部署
shell
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
container_name: zookeeper
ports:
- "2181:2181"
kafka1:
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_CREATE_TOPICS: "topic1:1:1,topic2:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
container_name: kafka1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
kafka2:
image: wurstmeister/kafka
ports:
- "9093:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: localhost
KAFKA_CREATE_TOPICS: "topic3:1:1,topic4:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9093
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
container_name: kafka2
volumes:
- /var/run/docker.sock:/var/run/docker.sock