本文采用homebrew安装kafka,如果还未安装homebrew,请参考我的上篇博客homebrew安装
- 安装zookeeper
brew install zookeeper
默认安装位置
启动文件: /usr/local/Cellar/zookeeper/3.5.8/bin/
配置文件: /usr/local/etc/zookeeper/
- 启动zookeeper 服务
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties &
- 安装kafka
brew install kafka
- 修改Kafka服务配置文件
修改配置文件 /usr/local/etc/kafka/server.properties
解除注释: listeners=PLAINTEXT://localhost:9092
- 启动Kafka服务
kafka-server-start /usr/local/etc/kafka/server.properties &
- 新建topic
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看已有主题list
kafka-topics --list --zookeeper localhost:2181
修改分区数
kafka-topics --zookeeper localhost:2181 --alter --topic test --partitions 2
- 创建生产者
kafka-console-producer --topic test --broker-list localhost:9092
- 创建消费者
kafka-console-consumer --bootstrap-server localhost:9092 -topic test
这时生产者写入一条消息,消费者那里可以收到。
- 查看topic内容
kafka-console-consumer --bootstrap-server localhost:9092 --topic demo1 --from-beginning
本文详述了如何使用Homebrew在Mac系统上安装Kafka和Zookeeper,包括配置服务、启动流程、创建topic及使用生产者与消费者进行消息传递的方法。
2181

被折叠的 条评论
为什么被折叠?



