1、返回topic列表

./kafka-topics.sh --list --zookeeper localhost:2181

kafka Raft模式:

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

2、创建topic

./kafka-topics.sh --zookeeper localhost:2181 --create --topic kafka_test --partitions 60 --replication-factor 3

kafka Raft模式:

./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 3 --partitions 10 --topic test

3、查看指定topic信息

./kafka-topics.sh --zookeeper localhost:2181 --describe --topic kafka_test

kafka Raft模式:

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

4、添加生产者权限

./kafka-acls.sh --add --allow-principal User:k11111111 --authorizer-properties zookeeper.connect=localhost:2181 --topic=kafka_test --producer

5、添加消费者权限

./kafka-acls.sh --add --allow-principal User:k11111111 --authorizer-properties zookeeper.connect=localhost:2181 --topic=kafka_test --consumer --group=*

6、查看topic权限

./kafka-acls.sh --list --authorizer-properties zookeeper.connect=localhost:2181 --topic=kafka_test

7、命令行生产者

./kafka-console-producer.sh --broker-list localhost:9092  --topic kafka_test

8、命令行消费者

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic kafka_test --group testK

9、修改配置,保留时间为6个小时

bin/kafka-configs.sh --zookeeper localhost:2181  --entity-type topics --entity-name log_ab_v4_0 --alter --add-config retention.ms=21600000

10、查看配置

bin/kafka-configs.sh --zookeeper localhost:2181 --entity-type topics --entity-name stream-train-data-long-v8 --describe

11、查看group列表

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

12、查看consumer消费情况:

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

13、虚拟生产者(--throughput为每秒消息数)

./kafka-verifiable-producer.sh --topic test --broker-list localhost:9092 --throughput 50

虚拟生产者2

./kafka-producer-perf-test.sh --producer-props bootstrap.servers=localhost:9092 --topic river-test-01 --print-metrics --num-records 100 --throughput 10 --record-size 1024

14、虚拟消费者

./kafka-consumer-perf-test.sh --show-detailed-stats --topic river-test-01 --broker-list localhost:9092 --messages 1000000 --group test_consumer_g10 --from-latest --timeout 60000

15、删除消费者组

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

16、删除某个topic 1小时之前的数据

find /data/kafka/topic-XXX-* -mmin +60 | grep -v epoch-checkpoint | xargs -I {} rm -rf {}

17、修改topic配置,如发送消息大小改为3M:

./kafka-topics.sh --zookeeper XXX:2181  --alter --topic river-test-01_copy  --config replica.fetch.max.bytes=3145728

但需要配合生产者和消费者的改动,详见 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐