Kafka的下载安装以及使用

一、Kafka下载

下载地址:https://kafka.apache.org/downloads

二、Kafka安装

因为选择下载的是 .zip 文件,直接跳过安装,一步到位。

选择在任一磁盘创建空文件夹(不要使用中文路径),解压之后把文件夹内容剪切进去(本人选择 D:\env-java\路径下,即完成安装)。

linux解压命令tar -zxvf kafka_2.13-3.5.1.tgz,linux环境下指令是在\kafka_2.13-3.5.1\bin目录。

windows直接解压即可,windows环境下指令是在kafka_2.13-3.5.1\bin\windows目录。

注意:不同系统指令所在的目录不同。

执行命令当前目录D:\env-java\kafka_2.13-3.5.1

修改 kafka-server 和zookeeper配置

进入到目录:kafka_2.13-3.5.1/config/server.properties以及kafka_2.13-3.5.1/config/zookeeper.properties

  • linux系统:
xml 复制代码
broker.id=1
log.dir=/Users/imagetask/kafka-logs
  • windows系统:
xml 复制代码
broker.id=1
log.dirs=/env-java/kafka_2.13-3.5.1/kafka-logs


/:表示当前的根路径,即D盘。没有就会创建对应的文件夹。

三、启动Kafka服务

1、启动ZooKeeper

  • linux系统:
xml 复制代码
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
  • windows系统:
xml 复制代码
bin\windows\zookeeper-server-start.bat config\zookeeper.properties	

2、启动kafka

  • linux系统:
xml 复制代码
bin/kafka-server-start.sh config/server.properties
  • windows系统:
xml 复制代码
bin\windows\kafka-server-start.bat config\server.properties

四、Kafka的使用

1、创建主题

  • linux系统:
xml 复制代码
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
  • windows系统:
xml 复制代码
bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

2、删除主题

  • linux系统:
xml 复制代码
bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic test
  • windows系统:
xml 复制代码
bin\windows\kafka-topics.bat --delete --bootstrap-server localhost:9092 --topic test

3、查看Topic 列表

  • linux系统:
xml 复制代码
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
  • windows系统:
xml 复制代码
bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092

4、启动 Producer

  • linux系统:
xml 复制代码
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
  • windows系统:
xml 复制代码
bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test

5、启动 Consumer

  • linux系统:
xml 复制代码
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
  • windows系统:
xml 复制代码
bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

6、查看Topic 相关信息(test)

  • linux系统:
xml 复制代码
bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test
  • windows系统:
xml 复制代码
bin\windows\kafka-topics.bat --describe --bootstrap-server localhost:9092 --topic test

详细了解可参考以下视频:

实用开发篇-130-Kafka安装

相关推荐
linweidong1 天前
解锁 Ray 在 Kubernetes 上的弹性伸缩:打造高效、稳定的分布式作业
分布式·容器·kubernetes·ray·keda·autoscaling·ray推理
u0104058361 天前
淘客返利app的分布式追踪系统:基于Jaeger的全链路性能分析
分布式
马走日mazouri1 天前
深入理解MySQL主从架构中的Seconds_Behind_Master指标
数据库·分布式·mysql·系统架构·数据库架构
虫小宝1 天前
淘宝客app的API网关设计:认证授权与流量控制策略
java·分布式·架构
孟意昶1 天前
Spark专题-第一部分:Spark 核心概述(1)-Spark 是什么?
大数据·分布式·spark
u0104058361 天前
京东返利app的分布式ID生成策略:雪花算法在订单系统中的实践
分布式·算法
AcrelZYL1 天前
工商业屋顶分布式光伏监控系统助力园区企业错峰有序用电
分布式·分布式光伏·屋顶分布式光伏·工商业分布式光伏监控
thginWalker1 天前
分布式协议与算法实战-理论篇
分布式
失散131 天前
分布式专题——10.2 ShardingSphere-JDBC分库分表实战与讲解
java·分布式·架构·shardingsphere·分库分表
失散131 天前
分布式专题——10.4 ShardingSphere-Proxy服务端分库分表
java·分布式·架构·shardingsphere·分库分表