(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
bin/kafka-preferred-replica-election.sh --zookeeper 10.212.0.24:2181
修改topic保留时间
./kafka-topics.sh --topic my_test_topic --zookeeper localhost:2181 --alter --config retention.ms=43200000
时间单位 ms=12h
查看修改后的保存时间
./kafka-configs.sh --zookeeper localhost:2181 --describe --entity-name my_test_topic --entity-type topics