赞
踩
在扩容完kafka的broker以后,现有的topic分区不会自动迁移到新增节点上。需要手动对每个topic进行重分布
示例:
查看当前topic
/home/kafka/kafka/kafka-1.1.0/bin/kafka-topics.sh --zookeeper 192.168.0.1:2181 --describe --topic gwtest01
当前topic有6个分区2个副本, 分布在1001,1002,1003 三个broker上,
然后扩容kafka,新增了一个broker,新增的节点broker_id 为 1004
先创建一个kafka_topic.json 内容为:
{"topics":[{"topic": "gwtest01"}],"version":1}
就是配置好需要处理的topic名称
生成随机重分布文件:
/home/kafka/kafka/kafka-1.1.0/bin/kafka-reassign-partitions.sh --broker-list 1001,1002,1003,1004 --zookeeper 192.168.0.1:2181 --generate --topics-to-move-json-file kafka_topic.json
其中:–broker-list 指定需要分布的broker id,这个brokerid不一定是按顺序生成的,想要查询当前集群所有的broker id , 可以进入每个broker的数据目录,cat meta.properties
–topics-to-move-json-file 指定刚刚的文件
命令执行完成,会输出现有topic分区分布,和生成的随机分布规划
手动将下面的json串复制到新文件partition_assignment.json
{"version":1,"partitions":[{"topic":"gwtest03","partition":1,"replicas":[1004,1001],"log_dirs":["any","any"]},{"topic":"gwtest03","partition":3,"replicas":[1002,1003],"log_dirs":["any","any"]},{"topic":"gwtest03","partition":0,"replicas":[1003,1004],"log_dirs":["any","any"]},{"topic":"gwtest03","partition":5,"replicas":[1004,1002],"log_dirs":["any","any"]},{"topic":"gwtest03","partition":2,"replicas":[1001,1002],"log_dirs":["any","any"]},{"topic":"gwtest03","partition":4,"replicas":[1003,1001],"log_dirs":["any","any"]}]}
执行分布:
/home/kafka/kafka/kafka-1.1.0/bin/kafka-reassign-partitions.sh --zookeeper 192.168.0.1:2181 --execute --reassignment-json-file partition_assignment.json
命令执行完再去查看topic分区状态,发现迁移完成
也可以使用以下命令查看分布的状态:
/home/kafka/kafka/kafka-1.1.0/bin/kafka-reassign-partitions.sh --zookeeper 192.168.0.1:2181 --verify --reassignment-json-file partition_assignment.json
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。