kafka命令大全

创建主题:

创建主题(4个分区,2个副本)kafka-topics.sh --create --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181 --replication-factor 2 --partitions 4 --topic test

查看集群详情:

kafka-topics.sh --describe --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181

查看集群中的topic列表:

kafka-topics.sh --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181 --list

查看topic详情:

kafka-topics.sh --describe --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181 --topic test

查看集群中的消费组列表:

kafka-consumer-groups.sh --bootstrap-server  192.168.130.37:9092,192.168.130.38:9092,192.168.130.39:9092 --list

查看消费组的消费情况:

kafka-consumer-groups.sh --bootstrap-server 192.168.130.37:9092,192.168.130.38:9092,192.168.130.39:9092 --describe --group consumer-group(消费组的名称)

生产者生产数据:

kafka-console-producer.<span>sh --broker-<span>list 192.168.130.37:9092,192.168.130.38:9092,192.168.130.39:9092<span> --topic test</span></span></span>

消费者消费数据:

kafka-console-consumer.<span>sh --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181<span> --topic test</span></span>

kafka-console-consumer.sh --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181 --from-beginning --topic myz

新消费者

kafka-console-consumer.<span>sh --bootstrap-server 192.168.130.37:9092,192.168.130.38:9092,192.168.130.39:9092<span> --topic test --<span>new-consumer --from-beginning --consumer.config config/consumer.properties</span></span></span>

kafka-simple-consumer-<span>shell.<span>sh --brist localhos<span>t:9092 --topic test --partition <span>0 --offset <span>1234 --<span>max-<span>messages <span>10</span></span></span></span></span></span></span></span>

分区/扩容

kafka-topics.<span>sh --zookeeper 192.168.130.37:2181,192.168.130.38:2181,192.168.130.39:2181<span> --alter --topic topic-name --partitions <span>2</span></span></span>