arterhuo / blog

1 stars 1 forks source link

Kafka 均衡分区 #11

Open huoarter opened 5 years ago

huoarter commented 5 years ago
to-move.topics.txt 存放要均衡的topics
#!/usr/bin/env python
import json
temp={"topics":
[],
"version":1
}

with open("to-move.topics.txt", 'rb') as f:
    for line in f:
        topic = line.strip()
        temp['topics'].append({"topic": topic})

print json.dumps(temp,indent=4)
通过topics-to-move.json生成要分配到机器的topicjson
#kafka-reassign-partitions -zookeeper prd-infra-005:2181/kafka/ka --topics-to-move-json-file topics-to-move.json --broker-list "1,2,3,4,5,6,7,8,9" --generate
kafka-reassign-partitions -zookeeper prd-infra-005:2181/kafka/ka --topics-to-move-json-file topics-to-move.json --broker-list "21,22,23,24,25,26,27,28,29" --generate
kafka-reassign-partitions  --zookeeper prd-infra-005:2181/kafka/ka --reassignment-json-file balance_topics.json --execute  --throttle 10000000
#kafka-reassign-partitions  --zookeeper prd-infra-005:2181/kafka/ka --reassignment-json-file balance_topics.json --verify

for i in $(<to-move.topics.txt);
do
echo $i
#kafka-configs --zookeeper prd-infra-005:2181/kafka/ka  --alter --entity-type topics --entity-name $i  --add-config retention.ms=28800000
#kafka-configs --zookeeper prd-infra-005:2181/kafka/ka  --alter --entity-type topics --entity-name $i  --add-config cleanup.policy=delete
kafka-configs --zookeeper prd-infra-005:2181/kafka/ka  --alter --entity-type topics --entity-name $i --delete-config retention.ms,cleanup.policy
done