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

相关推荐
一隅论数智2 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
XiHongShi20162 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本2 天前
离散数学第六课
学习·离散数学
vipxieliang2 天前
ValidX 在 DDD 领域驱动设计中的实践
java·spring boot
AI职业加油站3 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
旖旎夜光3 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
奇思妙想聪明勤奋的小羊3 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
霍霍的袁3 天前
【C++】map 和 set 的使用 | 从用法到底层
开发语言·c++·学习·visual studio
彧azz3 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试