来源:https://www.cnblogs.com/liuyuhua/p/5329926.html
https://www.cnblogs.com/xinlingyoulan/p/6054361.html
Windows 安装Kafka
Windows 7 安装Apache kafka_2.11-0.9.0.1
下载所需文件
Zookeeper: http://www.apache.org/dyn/closer.cgi/zookeeper/
Kafka :http://kafka.apache.org/downloads.html
安装Zookeeper
- 进入zookeeper设置目录,E:softelkzookeeper-3.4.8conf
- 将"zoo_sample.cfg" 复制一份,重命名为"zoo.cfg"
- 打开并编辑 并编辑dataDir=/tmp/zookeeper为指定目录为E:/soft/elk/zookeeper-3.4.8/data
- 编辑环境变量,Path加 E:softelkzookeeper-3.4.8in
-
运行cmd,输入zkserver ,成功如下
安装Kafka
打开CMD 到E:softelkkafka_2.11-0.9.0.1这个路径下
输入binwindowskafka-server-start.bat configserver.properties
现在Kafka已经准备好并开始运行,可以创建主题来存储消息了
创建主题
输入
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
创建Producer及Consumer来测试服务器。
输入
kafka-console-producer.bat --broker-list localhost:9092 --topic test1
再打开一个cmd,输入
kafka-console-consumer.bat --zookeeper localhost:2181 --topic test1
kafka-console-producer.bat --broker-list localhost:9092 --topic test1
在producer命令行中任意输入内容,回车;在其他consumer命令行中能看到相应消息
kafka常用命令
- 列出主题
kafka-topic.bat -list -zookeeper localhost:2181
- 描述主题
kafka-topics.bat -describe -zookeeper localhost:2181 -topic [topic name]
- 从头读取消息
kafka-console-consumer.bat -zookeeper localhost:2181 -topic [topic name] -from-beginning
- 删除主题
kafka-run-class.bat kafka.admin.TopicCommand -delete -topic [topic_to_delete] -zookeeper localhost:2181
- 查看topic的详细信息
./kafka-topic.sh -zookeeper localhost:2181 -describe -topic [topic name]
- 为topic增加副本
./kafka-reassign-partitions.sh -zookeeper localhost:2181 -reassignment-json-file json/partitions-to-move.json -execute
- 为topic增加partition
./bin/kafka-topics.sh -zookeeper localhost:2181 -alter -partitions 20 -topic [topic name]
- 下线broker
./kafka-run-class.sh kafka.admin.ShutdownBroker --zookeeper localhost:2181 broker [brokerId] --num.retries 3 --retry.interval.ms 60
shutdown broker