mac环境下使用brew安装kafka

 1.安装kafka

brew install kafka

 note:

·kafka使用zookeeper管理,安装过程会自动安装zookeeper

·安装目录:/usr/local/Cellar/kafka/*    (*为具体安装的版本)

·配置文件目录:/usr/local/etc/kafka

 

2.修改kafka启动配置文件

vi /usr/local/etc/kafka/server.properties

note:

·该配置为单机版,集群配置另开文章讲述

修改kafka的监听地址和端口为localhost:9092

listeners=PLAINTEXT://localhost:9092

 

3.依次启动服务

brew services start zookeeper
brew services start kafka

note:

·由于kafka依赖zookeeper管理,所以zookeeper需要先启动

 

4.创建topic

使用单个分区和只有一个副本的方式来创建一个名为“test”的topic

kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

 

5.查看创建的topic

kafka-topics --list --zookeeper localhost:2181

 

6.生产消息

通过控制台向“test”topic添加消息

kafka-console-producer --broker-list localhost:9092 --topic test

 

7.消费消息

通过控制台消费“test”topic中的消息

kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning

 

posted @ 2017-10-15 16:13  lusecond  阅读(2691)  评论(2编辑  收藏  举报