kafka shell操作

编程入门 行业动态 更新时间:2024-10-26 10:38:00

kafka shell<a href=https://www.elefans.com/category/jswz/34/1770947.html style=操作"/>

kafka shell操作

目录

    • 查看当前服务器中的所有topic
    • 创建topic
    • 查看某个Topic的详情
    • 修改分区数(注意:分区数只能增加,不能减少)
    • 删除topic
    • 生产数据
    • 消费数据

查看当前服务器中的所有topic

bin/kafka-topics.sh --bootstrap-server hadoop102:9092 --list

没有主题时,什么也不会输出

创建topic

创建一个topic,有1个分区3个副本

选项说明:

–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数

bin/kafka-topics.sh --bootstrap-server hadoop102:9092 --topic first --create  --partitions 1 --replication-factor 3 

查看某个Topic的详情

bin/kafka-topics.sh --bootstrap-server hadoop102:9092 --topic first --describe 

修改分区数(注意:分区数只能增加,不能减少)

 bin/kafka-topics.sh --bootstrap-server hadoop102:9092 --topic first --alter --partitions 3

删除topic

bin/kafka-topics.sh --bootstrap-server hadoop102:9092 --topic first --delete 

注意:需要彻底删除topic,须在server.properties中设置delete.topic.enable=true,否则只是标记删除

生产数据

bin/kafka-console-producer.sh --bootstrap-server hadoop102:9092 --topic first

消费数据

#把主题中所有的数据都读取出来(包括历史数据)
bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --topic first --from-beginning #从上一次的最大的偏移量处进行消费
bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --topic first

更多推荐

kafka shell操作

本文发布于:2023-07-28 17:48:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   kafka   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!