kafka集群缩容

#获取kafka主题列表
/data01/server/kafka/bin/kafka-topics.sh --zookeeper offline-op-kafka-ali-01:2181 --list > topics.txt


#通过py脚本格式化一下主题列表,生成topics.json
import json
obj = {}
obj["version"] = 1
obj["topics"] = []
with open("topics.txt") as f:
    for line in f.readlines():
        topic = {"topic": line.strip()}
        obj["topics"].append(topic)
with open("topics.json", "w") as f:
    json.dump(obj, f, indent=2)


#获取当前 partition 分配方案
kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ksyun-01:2181 --topics-to-move-json-file topics.json --broker-list "1,2,3" --generate > current.json

/data01/server/kafka/bin/kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ali-01:2181 --topics-to-move-json-file topics.json --broker-list "1,2,3" --generate > current.json


#执行
kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ksyun-01:2181 --reassignment-json-file current.json --execute
kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ali-01:2181 --reassignment-json-file current.json --execute

#验证,为空代表迁移完成!
./kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ksyun-01:2181 --reassignment-json-file current.json --verify | grep -v successsfully

kafka-reassign-partitions.sh --zookeeper offline-op-kafka-ali-01:2181 --reassignment-json-file current.json --verify | grep -v successsfully


#查看isr
./kafka-topics.sh --describe --zookeeper offline-op-kafka-ksyun-01:2181 --topic server-practice-laravel-php-log


#有哪些用户组来消费
./kafka-consumer-groups.sh --bootstrap-server offline-op-kafka-ksyun-01:9092 --list


#查看用户组消费情况
./kafka-consumer-groups.sh --bootstrap-server offline-op-kafka-ksyun-01:9092 --describe --group opentsdb-logstash

 

posted @ 2022-12-19 14:17  力王7314  阅读(248)  评论(0编辑  收藏  举报