1,查看kafka topic列表,使用--list參數
》bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --list __consumer_offsets lx_test_topic test
2,查看kafka特定topic的詳情,使用--topic與--describe參數
》bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic lx_test_topic --describe Topic:lx_test_topic PartitionCount:1 ReplicationFactor:1 Configs: Topic: lx_test_topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
列出了lx_test_topic的parition數量、replica因子以及每個partition的leader、replica信息
3、Kafka 刪除topic的命令是:
./bin/kafka-topics --delete --zookeeper 【zookeeper server】 --topic 【topic name】
如果kafaka啟動時加載的配置文件中server.properties沒有配置delete.topic.enable=true,那么此時的刪除並不是真正的刪除,而是把topic標記為:marked for deletion
你可以通過命令:./bin/kafka-topics --zookeeper 【zookeeper server】 --list 來查看所有topic
此時你若想真正刪除它,可以如下操作:
(1)登錄zookeeper客戶端:命令:./bin/zookeeper-client
(2)找到topic所在的目錄:ls /brokers/topics
(3)找到要刪除的topic,執行命令:rmr /brokers/topics/【topic name】即可,此時topic被徹底刪除。
另外被標記為marked for deletion的topic你可以在zookeeper客戶端中通過命令獲得:ls /admin/delete_topics/【topic name】,
如果你刪除了此處的topic,那么marked for deletion 標記消失
zookeeper 的config中也有有關topic的信息: ls /config/topics/【topic name】暫時不知道有什么用
總結:
徹底刪除topic:
1、刪除kafka存儲目錄(server.properties文件log.dirs配置,默認為"/tmp/kafka-logs")相關topic目錄
2、如果配置了delete.topic.enable=true直接通過命令刪除,如果命令刪除不掉,直接通過zookeeper-client 刪除掉broker下的topic即可。
4,查看consumer group列表,使用--list參數
》bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --list console-consumer-86845 console-consumer-11967
5,查看特定consumer group 詳情,使用--group與--describe參數
同樣根據新/舊版本的consumer,分別指定bootstrap-server與zookeeper參數:
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server 127.0.0.1:9292 --group lx_test --describe GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG OWNER lx_test lx_test_topic 0 465 465 0 kafka-python-1.3.1_/127.0.0.1
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --group console-consumer-11967 --describe GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG OWNER Could not fetch offset from zookeeper for group console-consumer-11967 partition [lx_test_topic,0] due to missing offset data in zookeeper. console-consumer-11967 lx_test_topic 0 unknown 465 unknown console-consumer-11967_aws-lx-1513787888172-d3a91f05-0
其中依次展示group名稱、消費的topic名稱、partition id、consumer group最后一次提交的offset、最后提交的生產消息offset、消費offset與生產offset之間的差值、當前消費topic-partition的group成員id(不一定包含hostname)
參考: