环境运维

kafka在mac下的安装与测试

1. 下载Kafka

到http://kafka.apache.org/downloads.html下载相应的版本,我使用的是kafka_2.9.1-0.8.2.2.tgz。

2. 下载完解压到你喜欢的目录

我是解压到 /usr/local/kafka/kafka_2.9.1-0.8.2.2

3. 运行默认的Kafka

启动Zookeeper server

[root@localhost kafka_2.9.1-0.8.2.2]# sh bin/zookeeper-server-start.sh config/zookeeper.properties &

启动Kafka server

[root@localhost kafka_2.9.1-0.8.2.2]# sh bin/kafka-server-start.sh config/server.properties &

运行生产者producer

[root@localhost kafka_2.9.1-0.8.2.2]# sh bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

运行消费者consumer

[root@localhost kafka_2.9.1-0.8.2.2]# sh bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

这样,在producer那边输入内容,consumer马上就能接收到。(然而并不能!!!! 报zookeeper is not a recognized option的错误)

0.90版本之后启动消费者的方法如下:

sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

=====================================

zookeeper is not a recognized option

创建消费者时候报错:

D:\kafka_2.12-2.3.0\bin\windows>kafka-console-consumer.bat --zookeeper localhost:2181 --topic test
zookeeper is not a recognized option

问题原因:

新版本kafka中,--zookeeper这种启动方式已删除。

解决办法:

0.90版本之后启动消费者的方法如下:

sh bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

windows下输入以下命令

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

 

 

====================================

kafka在windows下的启动命令

D:\xxxxx\kafka_2.12-2.8.1\bin\windows\zookeeper-server-start.bat D:\xxxxx\kafka_2.12-2.8.1\config\zookeeper.properties
执行结果


默认端口号是 2181

运行 kafka
打开新的命令行,执行:

D:\xxxxx\kafka_2.12-2.8.1\bin\windows\kafka-server-start.bat D:\xxxxx\kafka_2.12-2.8.1\config\server.properties
执行结果:

创建主题
创建一个名为 topic_test 的主题,包含一个分区,只有一个副本

D:\xxxxx\kafka_2.12-2.8.1\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic_test
生产消息
D:\xxxxx\kafka_2.12-2.8.1\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic topic_test
消费消息
D:\xxxxx\kafka_2.12-2.8.1\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic topic_test --from-beginning