Kafka常用命令整理
(1)#檢視當前topic的分割槽情況
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic __consumer_offsets
(2)編寫json檔案
cat addReplicas.json
{"topics":
[{"topic":"__consumer_offsets"}],
"version": 1
}
(3)生成推薦分割槽計劃
kafka-reassign-partitions.sh --zookeeper :2181 --topics-to-move-json-file addReplicas.json --broker-list "10,20,30" --generate
Current partition replica assignment #這是當前的分割槽情況,你可以結合--describe引數檢視當前的分割槽情況
Proposed partition reassignment configuration #這是推薦分割槽計劃
(4)修改json檔案
上一步是根據命令列的指定的brokerlist生成的分割槽分配計劃json格式
將 Proposed partition reassignment configuration的配置copy儲存到一個檔案中 topic-reassignment.json並對它進行相應的修改
{"version":1,
"partitions":[
{"topic":"__consumer_offsets","partition":0,"replicas":[10,20,30]},
{"topic":"__consumer_offsets","partition":1,"replicas":[10,20,30]},
{"topic":"__consumer_offsets","partition":2,"replicas":[10,20,30]}
]
}
(5)根據上一步生成的分配計劃配置json檔案topic-reassignment.json,進行topic的重新分配
kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file topic-reassignment.json --execute
(5)檢視分配的進度
kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file topic-reassignment.json --verify
重新分配leader(預設全部)
bin/kafka-preferred-replica-election.sh --zookeeper 10.212.0.24:2181
修改topic保留時間
./kafka-topics.sh--topicmy_test_topic--zookeeper localhost:2181 --alter--configretention.ms=43200000
時間單位 ms=12h
檢視修改後的儲存時間
./kafka-configs.sh --zookeeper localhost:2181 --describe --entity-namemy_test_topic --entity-type topics