赞
踩
镜像拉取
docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
定义docker-compose.yml
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka:2.12-2.0.1
depends_on: [ zookeeper ]
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.10.185
# KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- "./kafka/kafka_compose/docker.sock:/var/run/docker.sock"
- "./kafka/kafka_compose/data/:/kafka"
或者
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka:2.12-2.0.1
depends_on: [ zookeeper ]
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.10.185
# KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- "./kafka/kafka_compose/docker.sock:/var/run/docker.sock"
- "./kafka/kafka_compose/data/:/kafka"
kafka-manager:
image: sheepkiller/kafka-manager
environment:
ZK_HOSTS: 192.168.10.185
ports:
- "9001:9000"
[注] 192.168.10.185是本机(vm)地址。
启动服务
docker-compose up -d
启动测试
记住启动的启动名称,kafka为 kafka_kafka_1 ,zookeeper 为 kafka_zookeeper_1 .
如果docker-compose正常启动,此时docker ps会看到以上两个容器。进入kafka容器。
docker exec -it kafka_kafka_1 bash
创建一个topic:
$KAFKA_HOME/bin/kafka-topics.sh --create --topic test --partitions 4 --zookeeper kafka_zookeeper_1:2181 --replication-factor 1
发布信息:
$KAFKA_HOME/bin/kafka-console-producer.sh --topic=test --broker-list kafka_kafka_1:9092
接收消息
$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka_kafka_1:9092 --from-beginning --topic test
kafka集群管理界面
docker run -itd --name=kafka-manager -p 9001:9000 -e ZK_HOSTS="192.168.10.185:2181" sheepkiller/kafka-manager
[注] 新建Cluster的时候,Cluster Zookeeper Hosts 为 zookeeper的地址端口,如:192.168.10.185:2181。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。