How to change the number of replicas of a Kafka topic?

后端 未结 8 793
离开以前
离开以前 2020-11-30 21:31

After a Kafka topic has been created by a producer or an administrator, how would you change the number of replicas of this topic?

8条回答
  •  再見小時候
    2020-11-30 21:54

    To increase the number of replicas for a given topic you have to:

    1. Specify the extra partitions to the existing topic with below command(let us say increase from 2 to 3)

    bin/kafktopics.sh --zookeeper localhost:2181 --alter --topic topic-to-increase --partitions 3

    2. Specify the extra replicas in a custom reassignment json file

    For example, you could create increase-replication-factor.json and put this content in it:

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

    3. Use the file with the --execute option of the kafka-reassign-partitions tool

    bin/kafka-reassign-partitions --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute

    4. Verify the replication factor with the kafka-topics tool

    bin/kafka-topics --zookeeper localhost:2181 --topic topic-to-increase --describe

提交回复
热议问题