本地windows搭建kafka
记录一下在window环境下搭建kafka的情况,说简单也简单,说不简单也不简单。在搭建的过程遇到过几个问题。
下载安装包
这里下载的是kafka_2.13-3.4.1
https://archive.apache.org/dist/kafka/3.4.1/kafka_2.13-3.4.1.tgz
正常情况下会下载比较慢
解压安装包及做简单配置
在解压的文件夹下新建data和kafka-logs文件夹
在config目录下的server.properties和zookeeper.properties分别配置
server.properties中配置log.dirs=D:\software\kafka_2.13-3.4.1\kafka-logs
zookeeper.properties中配置dataDir=D:\software\kafka_2.13-3.4.1\data
后面发现并没有按照配置生成,先不研究了什么原因了,能用就行吧~
启动服务
先启动zookeeper
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
正常会看到binding to port…… 不关闭页面
启动Kafka
.\bin\windows\kafka-server-start.bat .\config\server.properties
启动成功后会有complete字眼打出
创建测试topic
.\bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
启动生产者
.\bin\windows\kafka-console-producer.bat --bootstrap-server localhost:9092 --topic test
启动消费者
.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
在创建消费者的过程中出现这个错误java.io.IOException: Map failed
去调整kafka-server-start.bat文件中参数,根据电脑版本32位还是64位的,这里将64位的地方1G修改为了256M,再去启动消费者,就没有错误了
Tips:
在cmd中窗口中发送中文字符,在消费者端接收的是乱码,是因为cmd窗口是gbk编码导致的