MacOS安装kafka

安装

如果还没有安装Java, 可以先安装Java: brew cask install java

然后安装zookeeper和kafka。

bash-3.2$ brew install kafka
 

==> Downloading https://homebrew.bintray.com/bottles/kafka-2.3.1.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/0d/0d3bdac93bd2602f0a7ee444fa77081362da52ea54e3d66488904a67128b7afd?__gda__=
######################################################################## 100.0%
==> Pouring kafka-2.3.1.catalina.bottle.tar.gz
==> Caveats
To have launchd start kafka now and restart at login:
  brew services start kafka
Or, if you don't want/need a background service you can just run:
  zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties
==> Summary
🍺  /usr/local/Cellar/kafka/2.3.1: 171 files, 59.5MB
bash-3.2$ brew install zookeeper
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
==> Downloading https://homebrew.bintray.com/bottles/zookeeper-3.4.14.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/85/854225ed94e18cdf9a08b992a658e851d4c4d77d826e8ae243488e65b38af84c?__gda__=
######################################################################## 100.0%
==> Pouring zookeeper-3.4.14.catalina.bottle.tar.gz
==> Caveats
To have launchd start zookeeper now and restart at login:
  brew services start zookeeper
Or, if you don't want/need a background service you can just run:
  zkServer start
==> Summary
🍺  /usr/local/Cellar/zookeeper/3.4.14: 430 files, 36.5MB

修改 /usr/local/etc/kafka/server.properties, 找到 listeners=PLAINTEXT://:9092 那一行,把注释取消掉。
然后修改为:

############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://localhost:9092

启动

如果想以服务的方式启动,那么可以:

$ brew services start zookeeper
$ brew services start kafka

如果只是临时启动,可以:

$ zkServer start
$ kafka-server-start
 /usr/local/etc/kafka/server.properties

创建Topic

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

产生消息

$ kafka-console-producer --broker-list localhost:9092 --topic test
>HELLO Kafka

消费

简单方式:

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

如果使用消费组:

kafka-console-consumer --bootstrap-server localhost:9092 --topic test --group test-consumer1 --from-beginning
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

正说杂谈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值