kafka需要zookeeper管理,所以需要先安装zookeeper。
yi、下载zookeeper镜像
docker pull wurstmeister/zookeeper
docker 生成zookeeper容器
docker run -d --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime wurstmeister/zookeeper
er.下载kafka镜像
docker pull wurstmeister/kafka
docker 生成kafka容器
docker run -d --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.115.128:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.115.128:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -v /etc/localtime:/etc/localtime wurstmeister/kafka
san.进入容器操作
docker exec -it kafka(docker容器id或者名称) /bin/bash
cd /opt/kafka/bin/
运行kafka生产者发送消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic topicName
运行kafka消费者接收消息
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicName
创建topic
kafka-topics.sh --create --topic example --replication-factor 1 --partitions 1 --zookeeper 192.168.115.128:2181/kafka
查看kafka topic
kafka-topics.sh --list --zookeeper 192.168.115.128:2181/kafka
查看kafka topic详细信息
kafka-topics.sh --zookeeper 192.168.115.128:2181/kafka --topic example --describe