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

相关推荐
安小牛5 分钟前
Kotlin 学习-集合
android·开发语言·学习·kotlin
小王努力学编程6 分钟前
【Linux网络编程】UDP Echo Server的实现
linux·运维·服务器·网络·c++·学习·udp
创码小奇客24 分钟前
Java 对象变形记:BeanUtils 与 MapStruct 的高阶魔法实战
java·spring boot·trae
吾日三省吾码42 分钟前
微服务入门:Spring Boot 初学者指南
spring boot·微服务·架构
计算机学长felix1 小时前
基于SpringBoot的“线上考试系统”的设计与实现(源码+数据库+文档+PPT)
spring boot·毕业设计
shepherd1111 小时前
从零搭建高可用Kafka集群与EFAK监控平台:全流程实战总结
分布式·后端·kafka
有诺千金1 小时前
深入理解 Spring Boot 的@AutoConfiguration注解
java·spring boot·后端
代码吐槽菌1 小时前
基于SpringBoot的律师事务所案件管理系统【附源码】
java·数据库·spring boot·后端·毕业设计
s_little_monster1 小时前
【Linux】线程控制函数
linux·运维·服务器·经验分享·笔记·学习·学习方法
十年之少1 小时前
粘性定位(position:sticky)——微信小程序学习笔记
笔记·学习·微信小程序