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 ) !

相关推荐
初次攀爬者16 小时前
Kafka + KRaft模式架构基础介绍
后端·kafka
初次攀爬者17 小时前
Kafka + ZooKeeper架构基础介绍
后端·zookeeper·kafka
初次攀爬者17 小时前
Kafka 基础介绍
spring boot·kafka·消息队列
DemonAvenger5 天前
Kafka性能调优:从参数配置到硬件选择的全方位指南
性能优化·kafka·消息队列
初次攀爬者5 天前
ZooKeeper 实现分布式锁的两种方式
分布式·后端·zookeeper
yumgpkpm6 天前
AI视频生成:Wan 2.2(阿里通义万相)在华为昇腾下的部署?
人工智能·hadoop·elasticsearch·zookeeper·flink·kafka·cloudera
予枫的编程笔记6 天前
【Kafka高级篇】避开Kafka原生重试坑,Java业务端自建DLQ体系,让消息不丢失、不积压
java·kafka·死信队列·消息中间件·消息重试·dlq·java业务开发
倚肆6 天前
在 Windows Docker 中安装 Kafka 并映射 Windows 端口
docker·kafka
断手当码农6 天前
Redis 实现分布式锁的三种方式
数据库·redis·分布式