Kafka常用操作命令

5.4、Kafka常用操作命令

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

bin/kafka-topics.sh --list --zookeeper  zk01:2181

  • 创建topic

bin/kafka-topics.sh --create --zookeeper zk01:2181 --replication-factor 1 --partitions 1 --topic test

  • 删除topic

sh bin/kafka-topics.sh --delete --zookeeper zk01:2181 --topic test

需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。

  • 通过shell命令发送消息(生产者)

kafka-console-producer.sh --broker-list kafka01:9092 --topic itheima

  • 通过shell消费消息(消费者)

sh bin/kafka-console-consumer.sh --zookeeper zk01:2181 --from-beginning --topic test1

  • 查看消费位置

sh kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper zk01:2181 --group testGroup

  • 查看某个Topic的详情

sh kafka-topics.sh --topic test --describe --zookeeper zk01:2181

 

 

新增配置

bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic my-topic --partitions 1 --replication-factor 1 --config max.message.bytes=64000 --config flush.messages=1

 

修改配置

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic my-topic --config max.message.bytes=128000

 

删除配置:

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic my-topic --deleteConfig max.message.bytes

 

原文地址:https://www.cnblogs.com/heitaok/p/5531740.html