Kafka 常用命令

2021-09-26 23:53:24 字數 2087 閱讀 8898

1.檢視topic

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

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

2.describe結果解釋

> bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic

topic:my-replicated-topic    partitioncount:1    replicationfactor:3    configs:

topic: my-replicated-topic    partition: 0    leader: 1    replicas: 1,2,0    isr: 1,2,0

第乙個行顯示所有partitions的乙個總結,以下每一行給出乙個partition中的資訊,如果我們只有乙個partition,則只顯示一行。

leader 是在給出的所有partitons中負責讀寫的節點,每個節點都有可能成為leader

replicas 顯示給定partiton所有副本所儲存節點的節點列表,不管該節點是否是leader或者是否存活。

isr 副本都已同步的的節點集合,這個集合中的所有節點都是存活狀態,並且跟leader同步

3.新建topic

./kafka-topics.sh --create --zookeeper xx.xx.xx.xx:2181 --replication-factor 3 --partitions 5  --topic xx_xx_xx

./kafka-topics.sh --create --bootstrap-server xx.xx.xx.xx:9092 --replication-factor 3 --partitions 5  --topic xx_xx_xx

partitions 為分割槽數,單分割槽可保證資料順序。

replication為副本數,replication數不可超過節點數。

4.消費1條資料

./kafka-console-consumer.sh --zookeeper xx.xx.xx.xx:2181 --max-messages 1 --topic ******

5.從頭消費1條資料

./kafka-console-consumer.sh --zookeeper xx.xx.xx.xx:2181 --from-beginning --max-messages 1 --topic ******

6.刪除topic

./bin/kafka-topics --delete --zookeeper xx.xx.xx.xx:2181 --topic ******

./kafka-topics.sh --delete --bootstrap-server xx.xx.xx.xx:9092 --topic topic_name

需停止消費資料、推送資料。

7.檢視消費積壓情況

對應的 kafka 版本是  kafka_2.11-0.10.0.1

./kafka-consumer-groups --new-consumer --bootstrap-server xx.xx.xx.xx:9092 --group group_id --describe

8.重置offset

./kafka-consumer-groups --bootstrap-server xx.xx.xx.xx:9092 --group group_id --reset-offsets --to-offset 109688652 --topic xx_topic --execute

9.增加分割槽

./kafka-topics.sh --alter  --zookeeper xx.xx.xx.xx:2181  --topic topic_name --partitions 2

10.增加副本

./kafka-reassign-partitions.sh  --zookeeper  xx.xx.xx.xx:2181  --reassignment-json-file replication.json --execute,]

}

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 ...