kafka操作命令

  • kafka启动
bin/kafka-server-start.sh -daemon config/server.properties
  • 创建topic
bin/kafka-topics.sh -zookeeper localhost:2181 --create --partitions 1 --replication-factor 1 --topic test

--partitions指定分区数,--replication-factor表示副本数

  • 查看topic列表
bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-topics.sh --list --bootstrap-server localhost:9092

-- 查看集群描述

bin/kafka-topics.sh --describe --zookeeper localhost:2181
  • 删除topic
./bin/kafka-topics --delete --zookeeper localhost:2181 --topic test
  • 生产消息
bin/kafka-producer-perf-test.sh --topic test --throughput -1 --record-size 10 --num-records 500000 --producer-props bootstrap.servers=localhost:9092
  • 消费消息
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
  • 获取topic消息数
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -1
bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic test --time -2

--time -1表示要获取topic所有分区当前的最大位移, --time -2表示获取当前最早位移。两个命令输出相减便可得到所有分区当前的消息总数。在没有删除过消息的情况下,第二个命令的结果是0。

  • 查询消费组列表
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
  • 查询某个消费组的消费详情
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my-group
  • 压力测试
bin/kafka-producer-perf-test.sh --topic test --num-records 100 --record-size 1 --throughput 100 --producer-props bootstrap.servers=localhost:9092
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容