本文介绍: 下载适用于Apple M2 Pro的Zookeeper和Kafka Docker镜像下载成功后确认镜像下载完成。

前置准备

下载适用于Apple M2 Pro的Zookeeper和Kafka Docker镜像

docker pull zookeeper:3.6
docker pull cppla/kafka-docker:arm

下载成功后确认镜像无误

docker images

部署Zookeeper

执行部署命令后查看容器是否启动

docker run -d --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime  -e TZ=Asia/Shanghai  zookeeper:3.6
docker ps|grep zookeeper

部署Kafka

 执行Kafka 安装命令

docker run -d --name kafka  -v /etc/localtime:/etc/localtime:ro -p 9092:9092  -e TZ=Asia/Shanghai --link zookeeper:zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 --env KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 --env KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 cppla/kafka-docker:arm

验证Kafka服务正常

查看Kafka容器启动成功

docker ps|grep kafka

进入容器

docker exec -it kafka bash

创建topic

kafka-topics.sh --create --topic topic_create_test --partitions 1 --replication-factor 1 --zookeeper zookeeper:2181 

Kafka 常用命令(记录)

创建一个生产者,并插入数据

bash-4.4# kafka-console-producer.sh --bootstrap-server localhost:9092 --topic topic_create_test
>{"id":773320,"name":"杨娟","address":"吉林省杭州市合川梧州路L座 934689","create_time":1653905861,"event_time":1653905561,"price":40343.9750680629,"list_info":["QeWHWDTPqOyjxivCdHFb","mAEgJHRZnojFWbueQiiR","AZWPwVMRyJKCJMXaEJhp","cbeTljzvygYcDrwdLKel","HFiEKQiFkEejdZQftpbE"],"map_info":{"也是":"aHzrLubeXUZLbwURNwmK","搜索":"MXhrcgUVOmNTqDjIHGTD","一些":"reiKveakVvTvNoesUjYE","女人":"ckoKoxJCrxniQIFAUiZu","之间":"DUXVsnqwtDrnxAcwFcZx"}}

创建一个消费者,往生产者持续插入数据可以看到数据被消费到

bash-4.4#  kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_create_test
{"id":773320,"name":"杨娟","address":"吉林省杭州市合川梧州路L座 934689","create_time":1653905861,"event_time":1653905561,"price":40343.9750680629,"list_info":["QeWHWDTPqOyjxivCdHFb","mAEgJHRZnojFWbueQiiR","AZWPwVMRyJKCJMXaEJhp","cbeTljzvygYcDrwdLKel","HFiEKQiFkEejdZQftpbE"],"map_info":{"也是":"aHzrLubeXUZLbwURNwmK","搜索":"MXhrcgUVOmNTqDjIHGTD","一些":"reiKveakVvTvNoesUjYE","女人":"ckoKoxJCrxniQIFAUiZu","之间":"DUXVsnqwtDrnxAcwFcZx"}}

原文地址:https://blog.csdn.net/weixin_42262463/article/details/135978993

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_64831.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注