kafka优选副本切换办法

南墨2年前技术文章609

      1. 以topic test为例,假设test的分布为以下状态。

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

2.  假设现在broker-1节点出现问题,希望parititon-0的优先副本发生切换,即由Replicas: 1,2变为

Replicas: 2,1,于此同时,leader由1切换到2。

首先编写迁移文件move.json,内容如下:

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

其中,文件的意义是:修改调换partition 0 的replicas的顺序为[2,1]

3.  执行迁移脚本

sh kafka-reassign-partitions.sh --zookeeper zookeeper_IP:24002/kafka --reassignment-json-file move.json --execute

执行完成后的结果为:

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 1 Replicas: 2,1 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

此时,partition-0的副本顺序变为了Replicas: 2,1

构建副本切换文件

创建excution.json,内容为:

{"partitions":[{"topic": "test", "partition": 0}]}

执行副本切换脚本

kafka-preferred-replica-election.sh --zookeeper zookeeper_IP:24002/kafka --path-to-json-file excution.json

执行后结果如下:

Topic:test PartitionCount:3 ReplicationFactor:2 Configs:

Topic: test Partition: 0 Leader: 2 Replicas: 2,1 Isr: 1,2

Topic: test Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3

Topic: test Partition: 2 Leader: 3 Replicas: 3,1 Isr: 1,3

此时,leader已切换broker-2


kafka-preferred-replica-election.sh 可以不加后面的副本切换脚本而直接执行,例如:

kafka-preferred-replica-election.sh --zookeeper zookeeper_IP:2181/kafka,这样会将真个集群的leader全部调整到优选副本


相关文章

Linux网络扫描和嗅探工具—Nmap

1、简介Nmap,也就是Network Mapper,是Linux下的网络扫描和嗅探工具包。它由Fyodor编写并维护。由于Nmap品质卓越,使用灵活,它已经是渗透测试人员必备的工具。其基本功能有三个...

Hadoop配置LZO压缩

Hadoop配置LZO压缩

hadoop-lzo编译Hadoop支持LZO0. 环境准备maven(下载安装,配置环境变量,修改sitting.xml加阿里云镜像)gcc-c++zlib-develautoconfautomak...

MySQL 在线开启 GTID

MySQL 在线开启 GTID

描述生产环境上也会遇到需要开启 GTID ,有什么风险?如何在线开启?本篇 SOP 将介绍。GTID 限制由于基于 GTID 复制依赖于事务,所有开启 GTID 时,有些 MySQL 特性不支持:事务...

某系统被入侵挖矿排查案例

某系统被入侵挖矿排查案例

1、当时的出现的情况是:执行 top、w、netstat命令的时候,会出现卡住的情况,无法正常使用2、我们上传新的top命令之后,只是看到CPU使用率比较高,但是看不到占用CPU的异常进程3、我们通过...

手动模拟 CNI 网络中 host-gw 模式互通

手动模拟 CNI 网络中 host-gw 模式互通

在Kubernetes中,CNI的作用就是让两台Node节点之间的Pod能够互相通信,其中有封包的方式,也有路由转发的方式,host-gw就是路由转发的方式。host-gw 模式介绍host-gw模式...

ldap安装部署

ldap安装部署

一、关闭selinux和防火墙sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/c...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。