当前位置:   article > 正文

Kafka入门笔记(二) --kafka常用命令_kafka启动kafka命令

kafka启动kafka命令

建议对kafka还不了解的小伙伴先看此文章:Kafka入门笔记(一) --kafka概述+kafka集群搭建


一、kafka启停命令

1、启动命令:

bin/kafka-server-start.sh -daemon config/server.propertieds
  • 1

-daemon: 守护进程


2、停止命令:

bin/kafka-server-stop.sh
  • 1

二、Topic常用命令

1、查询当前服务器中所有topic:

bin/kafka-topics.sh --zookeeper localhost:2181 --list
  • 1

2、创建topic:

bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 1 --topic first
  • 1
  • --topic 定义topic名
  • --replication-factor 定义副本数
  • --partitions 定义分区数

3、查看某个topic的详情:

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic first
  • 1

4、删除topic:

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic first
  • 1

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


5、修改topic分区:

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic first --partitions 6
  • 1
  • --partitions 分区数

三、消息相关命令

1、发送消息:

生产者在 first topic 发送消息:

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic first
  • 1

2、消费消息:

消费 first topic中的消息:

bin/kafka-console-consumer.sh  --bootstrap-server localhost:9092 --topic first
  • 1

从头开始消费 first topic 中的消息:

bin/kafka-console-consumer.sh  --bootstrap-server localhost:9092 --from-beginning --topic first
  • 1
  • --from-beginning:会把主题中以往所有的数据都读出来

3、查看消费者组列表:

/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
  • 1

4、指定消费者组进行消费:

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic first --consumer-property group.id=CONSUMER_GROUP_ID
  • 1

5、查看kafka中某一个消费者组的消费情况:

bin/kafka-consumer-groups.sh --describe --bootstrap-server localhost:9092 --group CONSUMER_GROUP_ID
  • 1

6、查看topic消费进度:

bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group CONSUMER_GROUP_ID
  • 1
  • 必须参数为--group, 不指定--topic,默认为所有topic

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/682237
推荐阅读
相关标签
  

闽ICP备14008679号