Kafka修改分区、副本数量

一、概述

无需重启服务

二、修改分区

  • 方式一:直接用软件重新分区

    Kafka Manager:

  • 方式二:命令行分区

    –zookeeper已经过时,使用–bootstrap-server

    # 查看分区
    bin/kafka-topics.sh --describe --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --topic mc-topic
    
    # 修改分区
    bin/kafka-topics.sh --alter --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --topic mc-topic --partitions 3
    

三、修改副本

1.指定Topic
vi reassign_topic.json
{"topics":
  [{"topic":"__consumer_offsets"}],
  "version": 1
}
2.生成分配计划

–generate : 生成分配计划,不执行

bin/kafka-reassign-partitions.sh --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --topics-to-move-json-file reassign_topic.json --broker-list "0,1,2" --generate
# 输出:
Current partition replica assignment # 当前分区配置
{"version":1,"partitions":[{"topic":"__consumer_offsets","partition":0,"replicas":[1,2,0]}]}
...
Proposed partition reassignment configuration # 建议分区配置
{"version":1,"partitions":[{"topic":"__consumer_offsets","partition":0,"replicas":[0,2,1]}]}
...
3.修改分配计划

复制建议配置,去掉,"log_dirs":["any","any","any"]

vi replcas.json

内容:

{"version":1,"partitions":[{"topic":"__consumer_offsets","partition":0,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":1,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":2,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":3,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":4,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":5,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":6,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":7,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":8,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":9,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":10,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":11,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":12,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":13,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":14,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":15,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":16,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":17,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":18,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":19,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":20,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":21,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":22,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":23,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":24,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":25,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":26,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":27,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":28,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":29,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":30,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":31,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":32,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":33,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":34,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":35,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":36,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":37,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":38,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":39,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":40,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":41,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":42,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":43,"replicas":[0,2,1]},{"topic":"__consumer_offsets","partition":44,"replicas":[1,0,2]},{"topic":"__consumer_offsets","partition":45,"replicas":[2,0,1]},{"topic":"__consumer_offsets","partition":46,"replicas":[0,1,2]},{"topic":"__consumer_offsets","partition":47,"replicas":[1,2,0]},{"topic":"__consumer_offsets","partition":48,"replicas":[2,1,0]},{"topic":"__consumer_offsets","partition":49,"replicas":[0,2,1]}]}
4.执行分配计划
bin/kafka-reassign-partitions.sh --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --reassignment-json-file replcas.json --execute
# Successfully started partition reassignments for __consumer_offsets-0,...
5.查看分配进度
bin/kafka-reassign-partitions.sh --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --reassignment-json-file replcas.json --verify
6.查看新的副本
bin/kafka-topics.sh --bootstrap-server 172.25.18.45:9092,172.25.18.45:9093,172.25.18.45:9094 --topic __consumer_offsets --describe
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码上富贵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值