赞
踩
vim docker-compose.yml version: '2' services: zookeeper: image: wurstmeister/zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka ports: - "9092" # kafka 把9092端口随机映射到主机的端口 environment: KAFKA_ADVERTISED_HOST_NAME: 192.168.199.163 #本机ip KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_CREATE_TOPICS: test:1:1 volumes: - /var/run/docker.sock:/var/run/docker.sock
运行
docker-compose -f docker-compose.yml up -d --scale kafka=2 本机启动一个有两个节点的 Kafka 集群
查看
docker ps -a
$KAFKA_HOME/bin/kafka-topics.sh --describe --zookeeper kafka01_zookeeper_1:2181 #可以通过容器的名字或者IP访问
$KAFKA_HOME/bin/kafka-topics.sh --describe --zookeeper 192.168.199.163:2181 #这里因为zookeeper映射到了主题的2181端口
$KAFKA_HOME/bin/kafka-topics.sh --create --topic chat --partitions 3 --zookeeper 192.168.199.163:2181 --replication-factor 2
$KAFKA_HOME/bin/kafka-topics.sh --describe --zookeeper kafka01_zookeeper_1:2181
./kafka-console-producer.sh --broker-list localhost:9092 --topic chat
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic chat --from-beginning
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。