Kafka常用命令

2021-10-13 12:46:18 字數 2748 閱讀 3120

# 建立topic並指定分割槽和副本

./bin/kafka-topics.sh --create --zookeeper localhost:2181 --topic topic_name --partitions 2 --replication-factor 2

# 檢視topic列表

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

# 檢視某個topic的詳情

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

# 刪除名字為first的topic

./bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic topic_name

# 啟動生產者

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

# 啟動消費者 kfk0.9之前

./bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic topic_name

# 啟動消費者 kfk0.9開始

./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic topic_name

注意: --from-beginning 代表從頭消費資料.

# 消費指定topic指定partition中的資料,顯示資料的key和value

./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_name --property print.key=true --partition 0 --from-beginning

# 檢視消費者組

./bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --list 或者

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

# 檢視某消費者組詳細資訊

./bin/kafka-consumer-groups.sh --describe --zookeeper localhost:2181 --group consumer_group_name 或者

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

注意:

current-offset表示消費者當前消費到該分割槽的偏移量。

log-end-offset表示當前分割槽最後的偏移量。

lag表示消費者「落後」的消費進度,通過該字段來判斷是否有訊息積壓。

# 檢視某topic某分割槽的最大偏移量。預設生產者的分割槽分配策略是輪詢。

./bin/kafka-run-class.sh kafka.tools.getoffsetshell --topic topic_name --time -1 --broker-list localhost:9092 --partitions 0

注意,如果不指定--partitions引數,將展示所有分割槽的偏移量。

# 檢查topic isr是否完整

./bin/kafka-topics.sh --describe --zookeeper localhost:2181 |

less

# 檢查缺失isr的topic

./bin/kafka-topics.sh --describe --zookeeper localhost:2181 --under-replicated-partitions

# 檢查是否有資料堆積

./bin/kafka-consumer-offset-checker.sh --zookeeper localhost:2181 --consumer_group_name consumer_group_name --topic topic_name

# 檢視當前消費者組的offset

./bin/kafka-consumer-offset-checker.sh -zookeeper localhost:2181 --group consumer_group_name --topic topic_name

# 增加topic分割槽數

./bin --zookeeper localhost:2181 --alter --topic topic_name --partition 50

# 列出消費者組的詳細資訊

./bin/kafka-run-class.sh kafka.tools.consumeroffsetchecker --zookeeper localhost:2181 --group cousumer_group_name --topic topic_name

# 檢視磁碟分布不均衡 (將kfk的資料存放目錄設定為data*,方便查詢)

du -sh /data*/kafka/log/

# 對topic排序

du /data01/kafka/log/* |

sort -k1,1n

kafka常用命令

kafka常用操作命令 l檢視當前伺服器中的所有topic bin kafka topics.sh list zookeeper hadoop02 2181 l建立topic kafka topics.sh create zookeeper hadoop02 2181 replication fac...

kafka常用命令

啟動集群 nohup bin kafka server start.sh config server.properties 建立topic kafka topics topictt replication factor3 partitions3 create zookeeper hadoop1 21...

Kafka 常用命令

kafka console producer broker list 127.0.0.1 9092 topic mytopic kafka console consumer bootstrap server 127.0.0.1 9092 topic mytopic 建立主題,replication ...