kafka修改分區(qū)和副本數(shù)

kafka修改分區(qū)和副本數(shù)

查看現(xiàn)在副本分配情況

../bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe  --topic test1

Topic:test1       PartitionCount:3        ReplicationFactor:2     Configs:
        Topic: test1      Partition: 0    Leader: 2       Replicas: 2,4   Isr: 2,4
        Topic: test1      Partition: 1    Leader: 3       Replicas: 3,5   Isr: 3,5
        Topic: test1      Partition: 2    Leader: 4       Replicas: 4,1   Isr: 4,1

topic 分區(qū)擴(kuò)容

./kafka-topics.sh --zookeeper 127.0.0.1:2181 -alter --partitions 4 --topic test1

修改備份數(shù)量

這個(gè)文件自己創(chuàng)建 格式按照下面的格式就可以了

根據(jù)topic的分區(qū)情況自行修改 partitions-topic.json 文件配置

{
        "partitions":
                [
                {
                        "topic": "test1",
                        "partition": 0,
                        "replicas": [1,2]
                },
                {
                        "topic": "test1",
                        "partition": 1,
                        "replicas": [0,3]
                },
                {
                        "topic": "test1",
                        "partition": 2,
                        "replicas": [4,5]
                }
                ],
        "version":1
}

執(zhí)行副本搬遷

 ../bin/kafka-reassign-partitions.sh --zookeeper 127.0.0.1:2181 --reassignment-json-file partitions-topic.json --execute  

查看遷移情況:

../bin/kafka-reassign-partitions.sh --zookeeper 127.0.0.1:2181 --reassignment-json-file partitions-topic.json --verify

Status of partition reassignment:
Reassignment of partition [mx_prd_nginx_access,0] is still in progress
Reassignment of partition [mx_prd_nginx_access,1] completed successfully
Reassignment of partition [mx_prd_nginx_access,2] is still in progress

注釋

kafka-reassign-partitions.sh工具來(lái)重新分布分區(qū)。該工具有三種使用模式:

  1. generate模式,給定需要重新分配的Topic,自動(dòng)生成reassign plan(并不執(zhí)行)
  2. execute模式,根據(jù)指定的reassign plan重新分配Partition
  3. verify模式,驗(yàn)證重新分配Partition是否成功

我的 github 博客 https://sukbeta.github.io/kafka-Modify-Partitions-and-ReplicationFactor/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容