kafka-新增topic副本数

一. 简述:

在 Kafka 中增加主题(Topic)的副本数可以提高数据的可靠性和容错能力。在创建topic时,如果设置的不合理,或者创建后有新的需求变动,就需要调整了。

二. 方法:

可通过官方的指令:kafka-reassign-partitions.sh

  1. 通过kafka-topics.sh 脚本查看topic信息。

    #./kafka-topics.sh --describe --bootstrap-server kafka-server:9092 --topic xxxx_heart_ping

    Topic: xxxx_heart_ping PartitionCount: 12 ReplicationFactor: 3 Configs: min.insync.replicas=2,message.format.version=2.6-IV0,unclean.leader.election.enable=true
    Topic: xxxx_heart_ping Partition: 0 Leader: 4 Replicas: 4,8 Isr: 4,8
    Topic: xxxx_heart_ping Partition: 1 Leader: 8 Replicas: 8,6 Isr: 8,6
    Topic: xxxx_heart_ping Partition: 2 Leader: 6 Replicas: 6,9 Isr: 9,6

  2. 不动原有的副本配置,新增一个第三副本(json文件方式):

    #cat increase-replication-factor.json
    {"version":1,
    "partitions":[
    {"topic":"xxxx_heart_ping","partition":0,"replicas":[4,8,5]},
    {"topic":"xxxx_heart_ping","partition":1,"replicas":[8,6,7]},
    {"topic":"xxxx_heart_ping","partition":2,"replicas":[6,9,4]},
    ]}

  3. 通过kafka-reassign-partitions.sh 重新分配数据:

    /kafka-reassign-partitions.sh --bootstrap-server kafka-server:9092 --reassignment-json-file increase-replication-factor.json --execute

  4. 可通过--verify查看分配进度:

    /kafka-reassign-partitions.sh --bootstrap-server kafka-server:9092 --reassignment-json-file increase-replication-factor.json --verify


深耕运维行业多年,擅长linux、容器云原生、运维自动化等方面。

承接各类运维环境部署、方案设计/实施、服务代运维工作,欢迎沟通交流!

(V: xiaoxiangbj2013 ) !

相关推荐
Thomas.Sir3 天前
第21课:PyTorch|GPU多卡训练与分布式训练基础【让多卡并行成为你的加速引擎】
人工智能·pytorch·分布式
Cicada1283 天前
库存消息消费的正确性设计——从幂等窗口到批量流水线
分布式·系统架构
Nano叶落3 天前
Kafka 消费积压排查入门:Docker 搭环境亲手制造一次 ‘消息堵死‘,10 分钟看懂 Lag
kafka
Francek Chen4 天前
【大数据处理与分析】数据仓库Hive:04 数据仓库Hive概述
大数据·数据仓库·hive·hadoop·分布式
Gl�ria4 天前
Hadoop/YARN 集群缩容:下线DN节点
大数据·hadoop·分布式
吉甫作诵4 天前
Kafka 集群安装与运维实战:消费组排查、Offset 重置与副本重分配
大数据·运维·分布式·kafka·消息队列
imDwAaY4 天前
消息队列四大核心问题:顺序性、幂等性、可靠性与一致性
学习·kafka·rabbitmq
wno7044 天前
Spring Boot整合Kafka
spring boot·kafka
是Dream呀5 天前
Harness 工程:让 Agent 真正把任务做完
人工智能·分布式·缓存·agent