一、Kafka下载
下载地址:https://kafka.apache.org/downloads
二、Kafka安装
修改 kafka-server 和zookeeper配置
进入到目录:kafka_2.13-3.5.1/config/server.properties
以及kafka_2.13-3.5.1/config/zookeeper.properties
- linux系统:
broker.id=1
log.dir=/Users/imagetask/kafka-logs
- windows系统:
broker.id=1
log.dirs=/env-java/kafka_2.13-3.5.1/kafka-logs
/:表示当前的根路径,即D盘。没有就会创建对应的文件夹。
三、启动Kafka服务
1、启动ZooKeeper
- linux系统:
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
- windows系统:
bin\windows\zookeeper-server-start.bat config\zookeeper.properties
2、启动kafka
- linux系统:
bin/kafka-server-start.sh config/server.properties
- windows系统:
bin\windows\kafka-server-start.bat config\server.properties
四、Kafka的使用
1、创建主题
- linux系统:
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
- windows系统:
bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
2、删除主题
- linux系统:
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test
- windows系统:
bin\windows\kafka-topics.bat --delete --bootstrap-server localhost:9092 --topic test
3、查看Topic 列表
- linux系统:
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
- windows系统:
bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092
4、启动 Producer
- linux系统:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
- windows系统:
bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test
5、启动 Consumer
- linux系统:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
- windows系统:
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
6、查看Topic 相关信息(test)
- linux系统:
bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test
- windows系统:
bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092 --topic test
详细了解可参考以下视频:
实用开发篇-130-Kafka安装