docker部署kafka

1.拉取镜像

docker pull wurstmeister/zookeeper

docker pull wurstmeister/kafka

2.启动,先启动zookeeper

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

再启动kafka

docker run -d –name kafka –publish 9092:9092 –link zookeeper:zookeeper -e KAFKA_BROKER_ID=1 -e HOST_IP=172.17.137.55 -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.17.137.55:9092 -e KAFKA_ADVERTISED_HOST_NAME=172.17.137.55 -e KAFKA_ADVERTISED_PORT=9082 –restart=always -t wurstmeister/kafka

3.创建Replication为1,Partition为1的topic

进入kafka容器

docker exec -it kafka /bin/sh

cd opt/kafka_2.13-2.8.1

bin/kafka-topics.sh –create –zookeeper 172.17.137.55:2181 –replication-factor 1 –partitions 1 –topic partopic

4.查看topic的状态,在kafka容器中的opt/kafka_2.11-2.0.0/目录下输入bin/kafka-topics.sh –describe –zookeeper 172.17.137.55:2181 –topic partopic

docker部署kafka插图

5.发送kafka消息,在kafka容器内,/opt/kafka_2.11-2.0.0/bin目录下执行

./kafka-console-producer.sh –broker-list 172.17.137.55:9092 –topic partopic

docker部署kafka插图1

接收消息

kafka-console-consumer.sh –bootstrap-server 172.17.137.55:9092 –topic partopic –from-beginning

docker部署kafka插图2

原文链接:https://blog.csdn.net/letterss/article/details/122836650?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836840916800197020748%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836840916800197020748&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-15-122836650-null-null.nonecase&utm_term=docker%E3%80%81%E5%A5%BD%E7%94%A8

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享