zookeeper-kafka
kafka架构原理
https://blog.csdn.net/weixin_42073408/article/details/119751796?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168802169716800215024279%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168802169716800215024279&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-119751796-null-null.142^v88^control_2,239^v2^insert_chatgpt&utm_term=kafka%E5%8E%9F%E7%90%86&spm=1018.2226.3001.4187
常用命令
zookeeper启动、停止
/home/kafaka-zookeeper/apache-zookeeper-3.6.3/bin/zkServer.sh start/stop
zookeeper查看状态
/home/kafaka-zookeeper/apache-zookeeper-3.6.3/bin/zkServer.sh status mode:leader # 主 mode:follower # 从
客户端连接zookeeper集群
./zkCli.sh -server <Zookeeper服务器IP>:<Zookeeper服务器端口>
连接到zookeeper集群。如果连接成功,则说明至少有一个zookeeper节点处于可用状态。
查看kafka可用节点
#连接zookeeper后输入以下指令
ls /brokers/ids #kafka节点id,kafka配置文件中设置 ls /brokers/topics
注:若多套kafka连接同一套zookeeper集群,可在kafka配置文件中的zookeeper地址后增加路径来区分;至此另一套查看路径为ls /路径名/brokers/ids
查看topic列表
./kafka-topics.sh --list --zookeeper 172.25.209.12:2181
创建topic
bin/kafka-topics.sh -zookeeper localhost:2181 --create --partitions 5 --replication-factor 1 --topic test_kafka_topic
#创建名为 test_kafka_topic 的 Topic; --topic 指定 Topic 名,–partitions 指定分区数,–replication-factor 指定备份(副本)数
查看topic详情
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test_kafka_topic
增加 Topic 的 partition 数
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic test_kafka_topic --partitions 5
删除Topic
bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test_kafka_topic
生产者发送消息
bin/kafka-console-producer.sh --broker-list 10.80.39.76:9092 --topic test_kafka_topic
消费消息(从头开始),可查看所有消息
bin/kafka-console-consumer.sh --bootstrap-server 10.80.39.76:9092 --from-beginning --topic test_kafka_topic
消费消息(从尾开始)
bin/kafka-console-consumer.sh --bootstrap-server 10.80.39.76:9092 --topic test_kafka_topic --offset latest
消费消息(从尾开始指定分区)
bin/kafka-console-consumer.sh --bootstrap-server 10.80.39.76:9092 --topic test_kafka_topic --offset latest --partition 0
消费消息(指定分区指定偏移量)
bin/kafka-console-consumer.sh --bootstrap-server 10.80.39.76:9092 --topic test_kafka_topic --partition 0 --offset 100
指定group分组从头开始消费消息
kafka-console-consumer.sh --bootstrap-server 10.80.39.76:9092 --topic test -group test_group --from-beginning
查看消费者group列表
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
查看group详情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test_group --describe
删除Group 中 Topic
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test_group --topic test --delete
删除group
/usr/local/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test_group --delete
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类