SpringBoot学习之Kafka下载安装和启动(三十三)

一、Mac环境

1、下载Kafka:Apache Kafka

2、这里我选择的版本是kafka_2.12-3.7.0,下载最新版的Kafka二进制文件,解压到你喜欢的目录(建议目录不要带中文)。

3、启动ZooKeeper服务,Kafka需要使用ZooKeeper,所以首先需要启动ZooKeeper服务,注意了Kafka是自带了Zookeeper的

4、进入到bin目录下执行下面命令

./zookeeper-server-start.sh ../config/zookeeper.properties

#或者

sh zookeeper-server-start.sh ../config/zookeeper.properties

1、如果启动报错:INFO ZooKeeper audit is disabled.

2、修改config目录下的zookeeper.properties,添加audit.enable=true

3、关闭窗口重新执行上面的启动Zookeeper命令,看到截图中的result=success****即表示Zookeeper启动成功

5、启动Kafka服务器:

./kafka-server-start.sh ../config/server.properties

#或者

sh kafka-server-start.sh ../config/server.properties

看到截图这个就表示Kafka启动成功了

6、创建一个测试主题(可选):

参数说明:

  • --create:表示创建操作
  • --bootstrap-server localhost:2181:指定zookeeper的地址和端口
  • --topic:指定topic的名称
  • --partitions:指定分片数
  • --replication-factor:指定每个分片的副本数量

./kafka-topics.sh --create --bootstrap-server localhost:2181 --replication-factor 1 --partitions 1 --topic test1

#或者

sh kafka-topics.sh --create --bootstrap-server localhost:2181 --replication-factor 1 --partitions 1 --topic test1

#输出:Created topic "test1".

6.1、#如果你创建Topic失败,如下截图:原因就是连接服务超时,导致创建Topic失败

6.2、你需要进入到kafka_2.12-3.7.0下的conf目录下,找到server.perperties配置文件

6.3、用编辑器打开,这里我用的是VSCode,找到#listeners=PLAINTEXT://:9092这行修改成如下:

6.4、在bin目录下执行下面命令关闭kafka然后执行上面启动Kafka启动命令重启kafka

./kafka-server-stop.sh

#或者

sh kafka-server-stop.sh

7、查看topic列表(可选)

./kafka-topics.sh --list --bootstrap-server localhost:2181

#或者

sh kafka-topics.sh --list --bootstrap-server localhost:2181

# 输出:test1

8、查看某一个Topic的详细信息

./kafka-topics.sh --describe -bootstrap-server localhost:2181 --topic test1

#或者

sh kafka-topics.sh --describe -bootstrap-server localhost:2181 --topic test1

9、修改Topic

./kafka-topics.sh --alter --bootstrap-server localhost:2181 --topic test1 --partitions 1

#或者

sh kafka-topics.sh --alter --bootstrap-server localhost:2181 --topic test1 --partitions 1

10、删除Topic

./kafka-topics.sh --delete -bootstrap-server localhost:2181 --topic test1

#或者

sh kafka-topics.sh --delete -bootstrap-server localhost:2181 --topic test1

11、创建一个生产者(可选):

./kafka-console-producer.sh --broker-list localhost:9092 --topic test1

#或者

sh kafka-console-producer.sh --broker-list localhost:9092 --topic test1

12、启动一个消费者(可选):(./和sh都是mac或者Linux系统中执行的意思)

从头开始消费

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

从某个指定的分区消费

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test1 --partition 1

相关推荐
阿蒙Amon10 小时前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
AI绘画哇哒哒10 小时前
【干货收藏】深度解析AI Agent框架:设计原理+主流选型+项目实操,一站式学习指南
人工智能·学习·ai·程序员·大模型·产品经理·转行
风流倜傥唐伯虎10 小时前
Spring Boot Jar包生产级启停脚本
java·运维·spring boot
fuquxiaoguang11 小时前
深入浅出:使用MDC构建SpringBoot全链路请求追踪系统
java·spring boot·后端·调用链分析
戌中横11 小时前
JavaScript——预解析
前端·javascript·学习
毕设源码_廖学姐11 小时前
计算机毕业设计springboot招聘系统网站 基于SpringBoot的在线人才对接平台 SpringBoot驱动的智能求职与招聘服务网
spring boot·后端·课程设计
●VON12 小时前
React Native for OpenHarmony:2048 小游戏的开发与跨平台适配实践
javascript·学习·react native·react.js·von
顾北1212 小时前
MCP服务端开发:图片搜索助力旅游计划
java·spring boot·dubbo
ZH154558913112 小时前
Flutter for OpenHarmony Python学习助手实战:自动化脚本开发的实现
python·学习·flutter
昀贝12 小时前
IDEA启动SpringBoot项目时报错:命令行过长
java·spring boot·intellij-idea