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ū)。該工具有三種使用模式:
- generate模式,給定需要重新分配的Topic,自動(dòng)生成reassign plan(并不執(zhí)行)
- execute模式,根據(jù)指定的reassign plan重新分配Partition
- verify模式,驗(yàn)證重新分配Partition是否成功
我的 github 博客 https://sukbeta.github.io/kafka-Modify-Partitions-and-ReplicationFactor/