Docker 如何安装Kafka

1、下载镜像

docker pull wurstmeister/zookeeper  
docker pull wurstmeister/kafka

2、启动zookeeper

docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper

3、启动kafka

docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=127.0.0.1 --env KAFKA_ADVERTISED_PORT=9092 wurstmeister/kafka 

4、创建主题

docker exec -it kafka /bin/bash
cd opt/kafka_2.12-2.3.0/
bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic mykafka

5、启动消息发送方

docker exec -it kafka /bin/bash
cd opt/kafka_2.12-2.3.0/
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mykafka

6、启动消息接收方

docker exec -it kafka /bin/bash
cd opt/kafka_2.12-2.3.0/
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mykafka --from-beginning

7、主题列表

docker exec -it kafka /bin/bash
cd opt/kafka_2.12-2.3.0/
bin/kafka-topics.sh --list --zookeeper zookeeper:2181

8、查看topic的状态

docker exec -it kafka /bin/bash
cd opt/kafka_2.12-2.3.0/
bin/kafka-topics.sh --describe --zookeeper zookeeper:2181 --topic mykafka

你可能感兴趣的:(Docker 如何安装Kafka)