Kafka 基本操作之节点退役,增加副本,数据迁移期间限制带宽使用

本文主要是介绍Kafka 基本操作之节点退役,增加副本,数据迁移期间限制带宽使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

一. 前言

二. 节点退役(Decommissioning brokers)

三. 增加副本(Increasing replication factor)

四. 数据迁移期间限制带宽使用(Limiting Bandwidth Usage during Data Migration)


一. 前言

    Kafka 节点退役是指将一个节点永久地从集群中移除的过程。节点退役通常发生在节点故障、硬件损坏或集群扩容等情况下。节点退役的原理同样基于 Kafka 的分布式设计和复制机制。当一个节点需要退役时,需要将该节点上的所有分区的 Leader 副本迁移到其他节点上,并将该节点上的所有副本从集群中移除。

二. 节点退役(Decommissioning brokers)

原文引用:The partition reassignment tool does not have the ability to automatically generate a reassignment plan for decommissioning brokers yet. As such, the admin has to come up with a reassignment plan to move the replica for all partitions hosted on the broker to be decommissioned, to the rest of the brokers. This can be relatively tedious as the reassignment needs to ensure that all the replicas are not moved from the decommissioned broker to only one other broker. To make this process effortless, we plan to add tooling support for decommissioning brokers in the future.

    分区重新分配工具还不能自动为退役的 Broker 生成重新分配计划。因此,管理员必须制定一个重新分配计划,将 Broker 上托管的所有分区的副本移到其他 Broker 上,以使其退役。这可能会比较繁琐,因为重新分配需要确保所有副本不会从退役的 Broker 移动到仅一个其他 Broker。为了使这一过程变得轻松,我们计划在未来为退役 Broker 添加工具支持。

三. 增加副本(Increasing replication factor)

原文引用:Increasing the replication factor of an existing partition is easy. Just specify the extra replicas in the custom reassignment json file and use it with the --execute option to increase the replication factor of the specified partitions.

    增加现有分区的复制因子很容易。只需在自定义重新分配 json 文件中指定额外的副本,并将其与 --execute 选项一起使用,即可增加指定分区的复制因子。

原文引用:For instance, the following example increases the replication factor of partition 0 of topic foo from 1 to 3. Before increasing the replication factor, the partition's only replica existed on broker 5. As part of increasing the replication factor, we will add more replicas on brokers 6 and 7.

The first step is to hand craft the custom reassignment plan in a json file:

    例如,以下示例将 Topic foo 的分区0的复制因子从1增加到3。在增加复制因子之前,分区的唯一副本存在于 Broker 5上。作为增加复制因子的一部分,我们将在 Broker 6和7上添加更多副本。

    第一步是在 json 文件中手工制作自定义重新分配计划:

> cat increase-replication-factor.json{"version":1,"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}

原文引用:Then, use the json file with the --execute option to start the reassignment process:

    然后,使用带有 --execute 选项的 json 文件来启动重新分配过程:

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file increase-replication-factor.json --executeCurrent partition replica assignment{"version":1,"partitions":[{"topic":"foo","partition":0,"replicas":[5]}]}Save this to use as the --reassignment-json-file option during rollbackSuccessfully started partition reassignment for foo-0

原文引用:The --verify option can be used with the tool to check the status of the partition reassignment. Note that the same increase-replication-factor.json (used with the --execute option) should be used with the --verify option:

    --verify 选项可以与该工具一起使用,以检查分区重新分配的状态。请注意,相同的 increase-replication-factor.json(与 --execute 选项一起使用)应与 --verify 选项一起使用:

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file increase-replication-factor.json --verifyStatus of partition reassignment:Reassignment of partition [foo,0] is completed

原文引用:You can also verify the increase in replication factor with the kafka-topics tool:

    您还可以使用 Kafka-topics 工具验证复制因子的增加:

> bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic foo --describeTopic:foo	PartitionCount:1	ReplicationFactor:3	Configs:Topic: foo	Partition: 0	Leader: 5	Replicas: 5,6,7	Isr: 5,6,7

四. 数据迁移期间限制带宽使用(Limiting Bandwidth Usage during Data Migration)

原文引用:Kafka lets you apply a throttle to replication traffic, setting an upper bound on the bandwidth used to move replicas from machine to machine. This is useful when rebalancing a cluster, bootstrapping a new broker or adding or removing brokers, as it limits the impact these data-intensive operations will have on users.

    Kafka 允许您对复制流量进行限制,限制了将副本从一台机器移动到另一台机器的带宽上限。这在重新平衡集群、引导新 Broker、添加或删除 Broker 时非常有用,因为它限制了这些数据密集型操作对用户的影响。

原文引用:There are two interfaces that can be used to engage a throttle. The simplest, and safest, is to apply a throttle when invoking the kafka-reassign-partitions.sh, but kafka-configs.sh can also be used to view and alter the throttle values directly.

So for example, if you were to execute a rebalance, with the below command, it would move partitions at no more than 50MB/s.

    有两个接口可用于实现限制。最简单、最安全的方法是在调用 kafka-reallocate-partitions.sh 时应用限制,但 kafka-configs.sh 也可以用于直接查看和修改限制值。

    例如,如果使用以下命令执行重新平衡,它将以不超过 50MB/s 的速度移动分区。

$ bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --execute --reassignment-json-file bigger-cluster.json --throttle 50000000

原文引用:When you execute this script you will see the throttle engage:

    当您执行此脚本时,您将看到这个限制:

The inter-broker throttle limit was set to 50000000 B/sSuccessfully started partition reassignment for foo1-0

原文引用:Should you wish to alter the throttle, during a rebalance, say to increase the throughput so it completes quicker, you can do this by re-running the execute command with the --additional option passing the same reassignment-json-file:

    如果您希望在重新平衡过程中修改限制,比如说增加吞吐量,使其更快地完成,您可以通过使用 --additional 选项重新运行 execute 命令来实现这一点,该选项传递相同的 reassignment-json-file 文件:

$ bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092  --additional --execute --reassignment-json-file bigger-cluster.json --throttle 700000000The inter-broker throttle limit was set to 700000000 B/s

原文引用:Once the rebalance completes the administrator can check the status of the rebalance using the --verify option. If the rebalance has completed, the throttle will be removed via the --verify command. It is important that administrators remove the throttle in a timely manner once rebalancing completes by running the command with the --verify option. Failure to do so could cause regular replication traffic to be throttled.

When the --verify option is executed, and the reassignment has completed, the script will confirm that the throttle was removed:

    重新平衡完成后,管理员可以使用 --verify 选项检查重新平衡的状态。如果重新平衡已经完成,将通过 --verify 命令移除限制。重要的是,管理员在重新平衡完成后,通过运行带有 --verify 选项的命令,及时删除限制。否则,可能会导致常规复制流量被抑制。

    当 --verify 选项被执行,并且重新分配已经完成时,脚本将确认限制已被删除:

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092  --verify --reassignment-json-file bigger-cluster.jsonStatus of partition reassignment:Reassignment of partition [my-topic,1] is completedReassignment of partition [my-topic,0] is completedClearing broker-level throttles on brokers 1,2,3Clearing topic-level throttles on topic my-topic

原文引用:The administrator can also validate the assigned configs using the kafka-configs.sh. There are two pairs of throttle configuration used to manage the throttling process. First pair refers to the throttle value itself. This is configured, at a broker level, using the dynamic properties:

    管理员还可以使用 kafka-configs.sh 验证分配的配置。有两对限制配置用于管理节流过程。第一对是指限制值本身。这是在 Broker 级别使用动态属性配置的:

leader.replication.throttled.rate
follower.replication.throttled.rate

原文引用:Then there is the configuration pair of enumerated sets of throttled replicas:

    然后是限流副本的枚举集合配置对:

leader.replication.throttled.replicas
follower.replication.throttled.replicas

原文引用:Which are configured per topic.

All four config values are automatically assigned by kafka-reassign-partitions.sh (discussed below).

To view the throttle limit configuration:

按每个 Topic 配置。

所有4个配置值都由 kafka-remove-partitions.sh 自动分配(如下所述)。

要查看限流配置:

> bin/kafka-configs.sh --describe --bootstrap-server localhost:9092 --entity-type brokersConfigs for brokers '2' are leader.replication.throttled.rate=700000000,follower.replication.throttled.rate=700000000Configs for brokers '1' are leader.replication.throttled.rate=700000000,follower.replication.throttled.rate=700000000

原文引用:This shows the throttle applied to both leader and follower side of the replication protocol. By default both sides are assigned the same throttled throughput value.

To view the list of throttled replicas:

    这显示了应用于复制协议的 Leader 和 Follower 的限制。默认情况下,为双方分配相同的限流吞吐量值。

    要查看限流副本的列表,请执行以下操作:

> bin/kafka-configs.sh --describe --bootstrap-server localhost:9092 --entity-type topicsConfigs for topic 'my-topic' are leader.replication.throttled.replicas=1:102,0:101,follower.replication.throttled.replicas=1:101,0:102

原文引用:Here we see the leader throttle is applied to partition 1 on broker 102 and partition 0 on broker 101. Likewise the follower throttle is applied to partition 1 on broker 101 and partition 0 on broker 102.

    在这里,我们看到 Leader 限流被应用于 Broker 102上的分区1和 Broker 101上的分区0。类似地,Follower 限流被应用于 Broker 101上的分区1和 Broker 102上的分区0。

原文引用:By default kafka-reassign-partitions.sh will apply the leader throttle to all replicas that exist before the rebalance, any one of which might be leader. It will apply the follower throttle to all move destinations. So if there is a partition with replicas on brokers 101,102, being reassigned to 102,103, a leader throttle, for that partition, would be applied to 101,102 and a follower throttle would be applied to 103 only.

    默认情况下,kafka-reallocate-partitions.sh 将对重新平衡之前存在的所有副本应用 Leader 限流,其中任何一个副本都可能是 Leader。它将对所有移动目的地应用 Follower 限制。因此,如果代理101,102上有一个具有副本的分区被重新分配给102,103,则该分区的 Leader 限流值将应用于101,102,而 Follower 限流值将仅应用于103。

原文引用:If required, you can also use the --alter switch on kafka-configs.sh to alter the throttle configurations manually.

    如果需要,还可以使用 kafka-configs.sh 上的 --alter 开关手动更改限流配置。

节流复制的安全使用(Safe usage of throttled replication)

原文引用:

Some care should be taken when using throttled replication. In particular:

(1) Throttle Removal:
The throttle should be removed in a timely manner once reassignment completes (by running kafka-reassign-partitions.sh --verify).

(2) Ensuring Progress:

If the throttle is set too low, in comparison to the incoming write rate, it is possible for replication to not make progress. This occurs when:

使用限流复制时应格外小心。特别是:

(1) 限制移除:
重新分配完成后,应及时移除限制(通过运行 kafka-remove-partitions.sh --verify 移除)。
(2) 确保进度:
如果与传入写入速率相比,限制值设置得太低,则复制可能无法进行。这种情况发生在:

max(BytesInPerSec) > throttle

原文引用:Where BytesInPerSec is the metric that monitors the write throughput of producers into each broker.

The administrator can monitor whether replication is making progress, during the rebalance, using the metric:

其中,BytesInPerSec 是监视生产者对每个 Broker 写入吞吐量的度量。

在重新平衡期间,管理员可以使用以下度量来监视复制是否正在进行:

kafka.server:type=FetcherLagMetrics,name=ConsumerLag,clientId=([-.\w]+),topic=([-.\w]+),partition=([0-9]+)

原文引用:The lag should constantly decrease during replication. If the metric does not decrease the administrator should increase the throttle throughput as described above.

    在复制过程中,滞后应不断减少。如果 lag 度量没有减少,则管理员应如上所述增加限流吞吐量。

这篇关于Kafka 基本操作之节点退役,增加副本,数据迁移期间限制带宽使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/869599

相关文章

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Java 中的 @SneakyThrows 注解使用方法(简化异常处理的利与弊)

《Java中的@SneakyThrows注解使用方法(简化异常处理的利与弊)》为了简化异常处理,Lombok提供了一个强大的注解@SneakyThrows,本文将详细介绍@SneakyThro... 目录1. @SneakyThrows 简介 1.1 什么是 Lombok?2. @SneakyThrows

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

使用Python和Pyecharts创建交互式地图

《使用Python和Pyecharts创建交互式地图》在数据可视化领域,创建交互式地图是一种强大的方式,可以使受众能够以引人入胜且信息丰富的方式探索地理数据,下面我们看看如何使用Python和Pyec... 目录简介Pyecharts 简介创建上海地图代码说明运行结果总结简介在数据可视化领域,创建交互式地

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

Java Stream流使用案例深入详解

《JavaStream流使用案例深入详解》:本文主要介绍JavaStream流使用案例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录前言1. Lambda1.1 语法1.2 没参数只有一条语句或者多条语句1.3 一个参数只有一条语句或者多