Kafka常用命令

一、topic 相关命令

1.1 创建topic

创建topic ,包含3个partitions,每个partitions 有3个副本
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test --partitions 3 --replication-factor 3

创建topic ,手动分配副本
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test2 --replica-assignment 0:1,1:2,0:2

创建topic ,同时指定配置参数,max.message.bytes=10485760,flush.messages=100
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic test --config max.message.bytes=10485760 --config flush.messages=100

1.2 topic列表

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

1.3 topic详情

bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic test

1.4 修改topic

bin/kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic test --partitions 3

1.5 删除topic

bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic test

 

二、producer相关命令

启动生产者,常规启动
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test

启动生产者,发送消失时带key,以”:”为key、value的分隔符
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test --property parse.key=true --property key.separator=:

 

三、consumer相关命令

从末尾开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

从头开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

从指定offset开始拉取消息
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --partition 0 --offset 10

最多拉取10条
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --max-messages 10

打印key
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --property print.key=true

指定消费组
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --group g1

 

四、groups相关命令

4.1 消费组列表

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

4.2 消费组详情

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group g1

4.3 删除消费组

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group g1

 

五、config相关命令

6.1 查看配置

bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --describe

6.2 增加配置

bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --alter --add-config max.message.bytes=10485760,flush.messages=100

6.3 删除配置

bin/kafka-configs.sh --bootstrap-server localhost:9092 --entity-type topics --entity-name test --alter --delete-config max.message.bytes,flush.messages

 

六、吞吐量测试相关命令

6.1 生产者吞吐量测试

bin/kafka-producer-perf-test.sh bootstrap.servers=localhost:9092 --topic test --num-records 1000000 --record-size 200 --throughput -1 --producer-props acks=-1

6.2 消费者吞吐量测试

bin/kafka-consumer-perf-test.sh --bootstrap-server localhost:9092 --topic test --messages 1000000

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值