Kafka 3.1.X Partition、副本的增加或迁移

前言

原本topic只有一个分区,并且只有一个副本,现在想扩展到3个副本。
虽然有使用cmak对kafka集群进行管理,也可以在cmak上进行操作,但是个人更喜欢官网提供的方式。所以记录下来,免得以后忘记。
此操作可用来做partition的迁移、增加,副本的迁移与增加

环境

OS:Centos 7

Kafka Version:3.1.X

Java Version:OpenJdk 11

Kafka集群:三台,172.16.1.1:9092、172.16.1.2:9092、172.16.1.3:9092

操作

1、编写好Partition与副本想要迁移或增加到哪里的Json文件,这里把文件命名为【increase-replication-factor.json】

{
  "version": 1,
  "partitions": [
    {
      "topic": "test-topic",
      "partition": 0,
      "replicas": [0,1,2]
    }
  ]
}

2、进入到kafka所在的目录,执行以下语句 ,目前是有三台服务器做一个kafka集群的,并且使用的是linux系统。

bin/kafka-reassign-partitions.sh --bootstrap-server 172.16.1.1:9092,172.16.1.2:9092,172.16.1.3:9092 --reassignment-json-file increase-replication-factor.json --execute

执行完后,正常来说会出现以下输出

  Current partition replica assignment

  {"version":1,
  "partitions":[{"topic":"test-topic","partition":0,"replicas":[0]}]}

  Save this to use as the --reassignment-json-file option during rollback
  Successfully started reassignment of partitions
  {"version":1,
  "partitions":[{"topic":"test-topic","partition":0,"replicas":[0,1,2]}]}

上面也提示了,你可以把上面显示的,原来的配置参数给存起来,方便回滚。

3、检查是否执行成功,就是把步骤2语句后面的【--execute】改成【--verify】。

bin/kafka-reassign-partitions.sh --bootstrap-server 172.16.1.1:9092,172.16.1.2:9092,172.16.1.3:9092 --reassignment-json-file increase-replication-factor.json --verify

如果没问题就会有以下输出

  Status of partition reassignment:
  Reassignment of partition [test-topic,0] completed successfully

 当然,你可以直接查看topic明细来确认是否成功,使用以下语句

bin/kafka-topics.sh --bootstrap-server 172.16.1.1:9092,172.16.1.2:9092,172.16.1.3:9092 --topic test-topic --describe

结尾

以上就是全部的操作步骤,如果还需要更加详细的说明,请直接上官网。

Kafka3.1.X官方文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值