kafka关于修改副本数和分区的数的案例实战(也可用作leader节点均衡案例)

                                               作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.关于topic分区数的修改

1>.创建1分区1个的topic,名称为yinzhengjie-channel

[root@node101 ~]# kafka-topics.sh --zookeeper node102.yinzhengjie.org.cn: --create --replication-factor  -partitions  --topic yinzhengjie-channel
Created topic "yinzhengjie-channel".
[root@node101 ~]#

2>.查看topic的信息

[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel
Topic:yinzhengjie-channel PartitionCount: ReplicationFactor: Configs:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr: 103 #可以很明显的看出kafka 的分区数和副本数都是1
[root@node101 ~]#

3>.将之前创建的topic修改为3个分区

[root@node101 ~]# kafka-topics.sh --alter --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel --partitions
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!
[root@node101 ~]#

4>.再次查看topic的分区数

[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel
Topic:yinzhengjie-channel PartitionCount: ReplicationFactor: Configs:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr: #这是第一个分区,它的副本数依然是1一个,当前0号分区的副本数存放在103这个节点上。说明你的数据修改成功啦!
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
[root@node101 ~]#

二.关于topic副本数的修改

1>.编写分配脚本

[root@node101 ~]# cat addReplicas.json
{"topics":
[{"topic":"yinzhengjie-channel"}],
"version":
}
[root@node101 ~]#

2>.执行分配计划,用于生成json格式的文件

[root@node101 ~]# kafka-reassign-partitions.sh --zookeeper node102.yinzhengjie.org.cn: --topics-to-move-json-file addReplicas.json --broker-list "101,102,103" --generate
Current partition replica assignment       #这是当前的分区情况,你可以结合--describe参数查看当前的分区情况
{"version":,"partitions":[{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]}]} Proposed partition reassignment configuration     #这是推荐分区计划
{"version":,"partitions":[{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]}]}
[root@node101 ~]#
[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel      #查看当前分区的情况
Topic:yinzhengjie-channel PartitionCount: ReplicationFactor: Configs:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
[root@node101 ~]#

3>.Proposed partition reassignment configuration 后是根据命令行的指定的brokerlist生成的分区分配计划json格式。将 Proposed partition reassignment configuration的配置copy保存到一个文件中 topic-reassignment.json并对它进行相应的修改

[root@node101 ~]# cat topic-reassignment.json    #注意,我在复制下来之后,对副本数进行了修改,由之前的1个副本升级为2个副本。
{"version":,"partitions":[{"topic":"yinzhengjie-channel","partition":,"replicas":[,]},{"topic":"yinzhengjie-channel","partition":,"replicas":[,]},{"topic":"yinzhengjie-channel","partition":,"replicas":[,]}]}
[root@node101 ~]#

4>.根据上一步生成的分配计划配置json文件topic-reassignment.json,进行topic的重新分配。

[root@node101 ~]# kafka-reassign-partitions.sh --zookeeper node102.yinzhengjie.org.cn: --reassignment-json-file topic-reassignment.json --execute
Current partition replica assignment {"version":,"partitions":[{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]},{"topic":"yinzhengjie-channel","partition":,"replicas":[]}]} Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions.
[root@node101 ~]#

5>.查看分配的进度

[root@node101 ~]# kafka-reassign-partitions.sh --zookeeper node102.yinzhengjie.org.cn: --reassignment-json-file topic-reassignment.json --verify
Status of partition reassignment:
Reassignment of partition [yinzhengjie-channel,] completed successfully      #如果这里的参数是:is still in progress,说明正在进行分配,如果看到当前的提示说明分配完成。
Reassignment of partition [yinzhengjie-channel,] completed successfully
Reassignment of partition [yinzhengjie-channel,] completed successfully
[root@node101 ~]#

     温馨提示,上述的方法不仅仅可以用来修改副本数,还可以用来修改你的leader节点,下图我就是我在生产环境中用来均衡leader节点的实操截图:(是不是上面我提到的2种状态都有呢?)

6>.如果分配完成,我们再次查看

[root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel      #查看当前分区的情况,这是还没有重新分配的时候
Topic:yinzhengjie-channel PartitionCount: ReplicationFactor: Configs:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr: 103        #这里的副本数只有一个!
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
Topic: yinzhengjie-channel Partition: Leader: Replicas: Isr:
[root@node101 ~]#
root@node101 ~]# kafka-topics.sh --describe --zookeeper node102.yinzhengjie.org.cn: --topic yinzhengjie-channel
Topic:yinzhengjie-channel PartitionCount: ReplicationFactor: Configs:
Topic: yinzhengjie-channel Partition: Leader: Replicas: , Isr: ,      #副本数编程了2个!
Topic: yinzhengjie-channel Partition: Leader: Replicas: , Isr: ,
Topic: yinzhengjie-channel Partition: Leader: Replicas: , Isr: ,
[root@node101 ~]#

kafka关于修改副本数和分区的数的案例实战(也可用作leader节点均衡案例)的更多相关文章

  1. HDFS修改副本数,并生效。

    1.hadoop集群使用的ucloud的uahdoop 2.是公司集群配置小,只有两台core节点,实际就是两台的datanode. 容量占用超过了80%,需要缩减副本以空出容量. 3.查看 hado ...

  2. kafka修改topic副本数

    工作案例: 大数据开发用系统脚本自动在kafka建topic,检查后才发现副本数只有1个,存在数据丢失的风险.需要立刻把副本数改为3个. 开始干活,首先想到的是下面的命令: ${BIN_PATH}/k ...

  3. HDFS 修改默认副本数

    描述:将HDFS副本数修改为2第一步:将HDFS上已有文件副本数修改为2 hdfs dfs -setrep 2 -R -w / 第二步:修改dfs.replication值为2(页面上操作),然后重启 ...

  4. Hadoop副本数配置

    一个文件,上传到hdfs上时指定的是几个副本就是几个.修改了副本数(dfs.replications),对已经上传了的文件也不会起作用.当然可以在上传文件的同时指定创建的副本数hadoop dfs - ...

  5. 解决kafka集群由于默认的__consumer_offsets这个topic的默认的副本数为1而存在的单点故障问题

    抛出问题: __consumer_offsets这个topic是由kafka自动创建的,默认50个,但是都存在一台kafka服务器上,这是不是就存在很明显的单点故障?经测试,如果将存储consumer ...

  6. hadoop修改MR的提交的代码程序的副本数

    hadoop修改MR的提交的代码程序的副本数 Under-Replicated Blocks的数量很多,有7万多个.hadoop fsck -blocks 检查发现有很多replica missing ...

  7. elastic操作-索引重命名,索引副本数修改

    目前我们使用的elastic版本为2.3.5 当前版本没有直接的curl操作可以更改索引的名称,索引的副本数. 有直接更改索引副本数的api. curl -XPUT "192.168.1.1 ...

  8. hadoop(hbase)副本数修改

    一.需求场景 随着业务数据的快速增长,物理磁盘剩余空间告警,需要将数据备份从3份修改为1份,从而快速腾出可用磁盘容量. 二.解决方案 1. 修改hdfs的副本数 Hbase 的数据是存储在 hdfs ...

  9. 【大数据系列】使用api修改hadoop的副本数和块大小

    package com.slp.hdfs; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.h ...

随机推荐

  1. java — 静态绑定和动态绑定

    绑定:一个方法的调用与方法所在的类关联起来.java中的绑定分为静态绑定和动态绑定,又被称作前期绑定和后期绑定. 静态绑定:(final.static.private)在程序执行前已经被绑定,也就是说 ...

  2. [转] Linux有问必答:如何修复“sshd error: could not load host key”

    编译自:http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html作者: GOLinux 本文地址:https://linux.cn/ ...

  3. AAPT2 error: check logs for details 问题的终究修复

    AAPT2 error: check logs for details Process 'command '***\build-tools\27.0.3\aapt.exe'' finished wit ...

  4. String系列-----String

    jdk源码学习之String,手动实现一个String package com.amazing.jdk.string_2017_12_31; import java.io.Serializable; ...

  5. [转帖] infiniband的协议速度

  6. MES架构

    FlexWeaver作为速威公司全新一代MES的技术平台,提供MES所需的全系列平台服务,针对工业大数据提供分布式计算环境.统一数据库引擎.大数据及云计算支撑等等. ● 同时适应企业内网服务器及云部署 ...

  7. 使用ssh tunnel 来做代理或跳板

    接前文 http://www.cnblogs.com/piperck/p/6188984.html  使用ssh config配置文件来管理ssh连接 前文说了如何配置自己的ssh config 来方 ...

  8. 为Bootstrap模态对话框添加拖拽移动功能

    请自行下载使用到的Bootstrap库及jQuery库 <!DOCTYPE html> <html> <head lang="en"> < ...

  9. CSS兼容性详解

    前面的话 对于前端工程师来说,不想面对又不得不面对的一个问题就是兼容性.在几年之前,处理兼容性,一般地就是处理IE低版本浏览器的兼容性.而近几年,随着移动端的发展,工程师也需要注意手机兼容性了.本文将 ...

  10. String在内存中如何存储(Java)

    JDK1.8中JVM把String常量池移入了堆中,同时取消了“永久代”,改用元空间代替(Metaspace)java中对String对象特殊对待,所以在heap区域分成了两块,一块是字符串常量池(S ...