Kafka 基本操作之集群扩容

目录

一. 前言

二. Kafka 集群扩容

2.1. 总览

2.2. 自动将数据迁移到新机器(Automatically migrating data to new machines)

2.3. 自定义分区分配和迁移(Custom partition assignment and migration)


一. 前言

    Kafka 集群的服务发现是由 ZooKeeper 实现的,因此 Kafka 集群想添加新的 Broker 就非常容易。我们只需要为新的 Broker 设置一个唯一的 broker.id, 然后启动新增的 Kafka 就行。Kafka 集群会自动发现新增的 Broker 并同步原数据,包括当前集群有哪些 topics 以及 topics 的分区信息等。

二. Kafka 集群扩容

2.1. 总览

原文引用:Adding servers to a Kafka cluster is easy, just assign them a unique broker id and start up Kafka on your new servers. However these new servers will not automatically be assigned any data partitions, so unless partitions are moved to them they won't be doing any work until new topics are created. So usually when you add machines to your cluster you will want to migrate some existing data to these machines.

    将服务器添加到 Kafka 集群很容易,只需为它们分配一个唯一的 broker id,并在新服务器上启动 Kafka。然而,这些新服务器不会自动分配任何数据分区,因此除非将分区移动到它们,否则在创建新 Topic 之前,它们不会做任何工作。因此,通常当您将机器添加到集群中时,您会希望将一些现有数据迁移到这些机器中。

原文引用:The process of migrating data is manually initiated but fully automated. Under the covers what happens is that Kafka will add the new server as a follower of the partition it is migrating and allow it to fully replicate the existing data in that partition. When the new server has fully replicated the contents of this partition and joined the in-sync replica one of the existing replicas will delete their partition's data. 

    迁移数据的过程是手动启动的,但执行过程是完全自动化的。在这种情况下,Kafka 将添加新服务器作为它正在迁移的分区的追随者,并允许它完全复制该分区中的现有数据。当新服务器完全复制了此分区的内容并加入同步副本时,其中一个现有副本将删除其分区的数据。

原文引用:The partition reassignment tool can be used to move partitions across brokers. An ideal partition distribution would ensure even data load and partition sizes across all brokers. The partition reassignment tool does not have the capability to automatically study the data distribution in a Kafka cluster and move partitions around to attain an even load distribution. As such, the admin has to figure out which topics or partitions should be moved around.

    分区重新分配工具可用于在 Broker 之间移动分区。理想的分区分布将确保所有 Broker 的数据负载和分区大小均匀。分区重新分配工具无法自动研究 Kafka 集群中的数据分布,也无法移动分区以实现均匀的负载分布。因此,管理员必须弄清楚应该移动哪些 Topic 或分区。

原文引用:The partition reassignment tool can run in 3 mutually exclusive modes:
--generate: In this mode, given a list of topics and a list of brokers, the tool generates a candidate reassignment to move all partitions of the specified topics to the new brokers. This option merely provides a convenient way to generate a partition reassignment plan given a list of topics and target brokers.
--execute: In this mode, the tool kicks off the reassignment of partitions based on the user provided reassignment plan. (using the --reassignment-json-file option). This can either be a custom reassignment plan hand crafted by the admin or provided by using the --generate option
--verify: In this mode, the tool verifies the status of the reassignment for all partitions listed during the last --execute. The status can be either of successfully completed, failed or in progress

分区重新分配工具可以在3种互斥模式下运行:

  • --generate:在这种模式下,给定一个 Topic 列表和一个 Broker 列表,该工具生成一个候选重新分配,将指定 Topic 的所有分区移动到新的 Broker。此选项仅提供了一种方便的方法,可以在给定 Topic 和目标 Broker 列表的情况下生成分区重新分配计划。
  • --execute:在这种模式下,该工具根据用户提供的重新分配计划启动分区的重新分配。(使用 --reassignment-json-file 选项)。这可以是管理员手工编制的自定义重新分配计划,也可以使用 --generate 选项提供。
  • --verify:在这种模式下,该工具会验证上次执行过程中列出的所有分区的重新分配状态。状态可以是成功完成、失败或正在进行中的。

2.2. 自动将数据迁移到新机器(Automatically migrating data to new machines)

原文引用:The partition reassignment tool can be used to move some topics off of the current set of brokers to the newly added brokers. This is typically useful while expanding an existing cluster since it is easier to move entire topics to the new set of brokers, than moving one partition at a time. When used to do this, the user should provide a list of topics that should be moved to the new set of brokers and a target list of new brokers. The tool then evenly distributes all partitions for the given list of topics across the new set of brokers. During this move, the replication factor of the topic is kept constant. Effectively the replicas for all partitions for the input list of topics are moved from the old set of brokers to the newly added brokers.

    分区重新分配工具可用于将一些 Topic 从当前 Broker 集中移到新添加的 Broker 中。这在扩展现有集群时非常有用,因为将整个 Topic 移动到新的 Broker 集比一次移动一个分区更容易。当用于执行此操作时,用户应提供移动到新 Broker 集的 Topic 列表和新 Broker 的目标列表。然后,该工具将给定 Topic 列表的所有分区均匀地分布在新的 Broker 集合中。在移动过程中,Topic 的复制因子保持不变。实际上,Topic 输入列表所有分区的副本都会从旧的 Broker 集中移动到新添加的 Broker 中。

原文引用:For instance, the following example will move all partitions for topics foo1,foo2 to the new set of brokers 5,6. At the end of this move, all partitions for topics foo1 and foo2 will only exist on brokers 5,6.

    例如,以下示例将把Topic foo1、foo2 的所有分区移动到新的 Broker 5、6集合中。移动结束后,Topic foo1 和 foo2 的所有分区将只存在于 Broker 5,6上。

注意:提示各位 Kafka 学习者,下面所有的 json 文件,都是要你自己新建的,不是自动创建的,需要你自己把生成的规则复制到你新建的 json 文件里,然后执行。

原文引用:Since the tool accepts the input list of topics as a json file, you first need to identify the topics you want to move and create the json file as follows:

    由于该工具将 Topic 的输入列表作为 json 文件接收,因此您首先需要确定要移动的 Topic,并创建 json 文件,如下所示:

> cat topics-to-move.json
  {"topics": [{"topic": "foo1"},
              {"topic": "foo2"}],
  "version":1
  }

原文引用:Once the json file is ready, use the partition reassignment tool to generate a candidate assignment:

    json 文件准备好后,使用分区重新分配工具生成候选分配:

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --topics-to-move-json-file topics-to-move.json --broker-list "5,6" --generate
  Current partition replica assignment

  {"version":1,
  "partitions":[{"topic":"foo1","partition":0,"replicas":[2,1]},
                {"topic":"foo1","partition":1,"replicas":[1,3]},
                {"topic":"foo1","partition":2,"replicas":[3,4]},
                {"topic":"foo2","partition":0,"replicas":[4,2]},
                {"topic":"foo2","partition":1,"replicas":[2,1]},
                {"topic":"foo2","partition":2,"replicas":[1,3]}]
  }

  Proposed partition reassignment configuration

  {"version":1,
  "partitions":[{"topic":"foo1","partition":0,"replicas":[6,5]},
                {"topic":"foo1","partition":1,"replicas":[5,6]},
                {"topic":"foo1","partition":2,"replicas":[6,5]},
                {"topic":"foo2","partition":0,"replicas":[5,6]},
                {"topic":"foo2","partition":1,"replicas":[6,5]},
                {"topic":"foo2","partition":2,"replicas":[5,6]}]
  }

原文引用:The tool generates a candidate assignment that will move all partitions from topics foo1,foo2 to brokers 5,6. Note, however, that at this point, the partition movement has not started, it merely tells you the current assignment and the proposed new assignment. The current assignment should be saved in case you want to rollback to it. The new assignment should be saved in a json file (e.g. expand-cluster-reassignment.json) to be input to the tool with the --execute option as follows:

    该工具生成一个候选分配,将所有分区从Topic foo1、foo2 移动到 Broker 5、6。然而,请注意,在这一点上,分区移动还没有开始,它只是告诉您当前的分配和建议的新分配。如果您想回滚到当前分配,则应保存当前分配。新分配应保存在 json 文件中(例如,expand-cluster-revalment.json),以便使用 --execute 选项输入到工具中,如下所示:

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file expand-cluster-reassignment.json --execute
  Current partition replica assignment

  {"version":1,
  "partitions":[{"topic":"foo1","partition":0,"replicas":[2,1]},
                {"topic":"foo1","partition":1,"replicas":[1,3]},
                {"topic":"foo1","partition":2,"replicas":[3,4]},
                {"topic":"foo2","partition":0,"replicas":[4,2]},
                {"topic":"foo2","partition":1,"replicas":[2,1]},
                {"topic":"foo2","partition":2,"replicas":[1,3]}]
  }

  Save this to use as the --reassignment-json-file option during rollback
  Successfully started partition reassignments for foo1-0,foo1-1,foo1-2,foo2-0,foo2-1,foo2-2

原文引用:Finally, the --verify option can be used with the tool to check the status of the partition reassignment. Note that the same expand-cluster-reassignment.json (used with the --execute option) should be used with the --verify option:

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

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file expand-cluster-reassignment.json --verify
  Status of partition reassignment:
  Reassignment of partition [foo1,0] is completed
  Reassignment of partition [foo1,1] is still in progress
  Reassignment of partition [foo1,2] is still in progress
  Reassignment of partition [foo2,0] is completed
  Reassignment of partition [foo2,1] is completed
  Reassignment of partition [foo2,2] is completed

2.3. 自定义分区分配和迁移(Custom partition assignment and migration)

原文引用:The partition reassignment tool can also be used to selectively move replicas of a partition to a specific set of brokers. When used in this manner, it is assumed that the user knows the reassignment plan and does not require the tool to generate a candidate reassignment, effectively skipping the --generate step and moving straight to the --execute step

    分区重新分配工具还可以用于选择性地将分区的副本移动到特定的 Broker 集。当以这种方式使用时,假设用户知道重新分配计划,并且不需要该工具来生成候选重新分配,从而有效地跳过 --generate 步骤,直接进入 --execute 步骤。

原文引用:For instance, the following example moves partition 0 of topic foo1 to brokers 5,6 and partition 1 of topic foo2 to brokers 2,3:

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

    例如,以下示例将 Topic foo1 的分区0移动到 Broker 5,6,并将 Topic foo2的分区1移动到 Broker 2,3:

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

> cat custom-reassignment.json
  {"version":1,"partitions":[{"topic":"foo1","partition":0,"replicas":[5,6]},{"topic":"foo2","partition":1,"replicas":[2,3]}]}

原文引用: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 custom-reassignment.json --execute
  Current partition replica assignment

  {"version":1,
  "partitions":[{"topic":"foo1","partition":0,"replicas":[1,2]},
                {"topic":"foo2","partition":1,"replicas":[3,4]}]
  }

  Save this to use as the --reassignment-json-file option during rollback
  Successfully started partition reassignments for foo1-0,foo2-1
  

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

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

> bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --reassignment-json-file custom-reassignment.json --verify
  Status of partition reassignment:
  Reassignment of partition [foo1,0] is completed
  Reassignment of partition [foo2,1] is completed

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/498150.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

快速入门Axure RP:解答4个关键问题!

软件Axure RP 是一种功能强大的设计工具,用于使用 Web、移动和桌面应用程序项目创建交互原型。Axure RP软件中的 RP代表快速原型制作,这是软件Axure RP的核心特征。用户使用Axurere RP软件可以快速地将简单的想法创建成线框图和原型。Axure 因此&#xf…

实时数仓之实时数仓架构(Hudi)

目前比较流行的实时数仓架构有两类,其中一类是以FlinkDoris为核心的实时数仓架构方案;另一类是以湖仓一体架构为核心的实时数仓架构方案。本文针对FlinkHudi湖仓一体架构进行介绍,这套架构的特点是可以基于一套数据完全实现Lambda架构。实时数…

【二叉树】Leetcode 98. 验证二叉搜索树【中等】

验证二叉搜索树 给你一个二叉树的根节点 root ,判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下: 节点的左子树只包含 小于 当前节点的数。节点的右子树只包含 大于 当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。 示例1&a…

【Python函数和类2/6】函数的参数

目录 目标 为函数设置参数 传递实参 关键字实参 关键字实参的顺序 位置实参 常见错误 缺少实参 位置实参的顺序 默认值形参 参数的优先级 默认值形参的位置 总结 目标 上篇博客中,我们在定义函数时,使用了空的括号。这表示它不需要任何信息就…

浅谈C语言编译与链接

个人主页(找往期文章包括但不限于本期文章中不懂的知识点):我要学编程(ಥ_ಥ)-CSDN博客 翻译环境和运行环境 在ANSI C(标准 C)的任何一种实现中,存在两个不同的环境。 第1种是翻译环境,在这个…

ssh 公私钥(github)

一、生成ssh公私钥 生成自定义名称的SSH公钥和私钥对,需要使用ssh-keygen命令,这是大多数Linux和Unix系统自带的标准工具。下面,简单展示如何使用ssh-keygen命令来生成具有自定义名称的SSH密钥对。 步骤 1: 打开终端 首先,打开我…

增强现实(AR)和虚拟现实(VR)营销的未来:沉浸式体验和品牌参与

--- 如何将AR和VR技术应用于营销,以提高品牌知名度、客户参与度 增强现实(AR)和虚拟现实(VR)不再只是游戏。这些技术为品牌与受众互动提供了创新的方式。营销人员可以创造更好的客户体验,并为身临其境的故…

hadoop-3.1.1分布式搭建与常用命令

一、准备工作 1.首先需要三台虚拟机: master 、 node1 、 node2 2.时间同步 ntpdate ntp.aliyun.com 3.调整时区 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 4.jdk1.8 java -version 5.修改主机名 三台分别执行 vim /etc/hostname 并将内容指定为…

电脑突然死机怎么办?

死机是电脑常见的故障问题,尤其是对于老式电脑来说,一言不合电脑画面就静止了,最后只能强制关机重启。那么你一定想知道是什么原因造成的吧,一般散热不良最容易让电脑死机,还有系统故障,比如不小心误删了系…

【实现报告】学生信息管理系统(顺序表)

目录 实验一 线性表的基本操作 一、实验目的 二、实验内容 三、实验提示 四、实验要求 五、实验代码如下: (一)顺序表的构建及初始化 (二)检查顺序表是否需要扩容 (三)根据指定学生个…

企业网站建设的方法的相关问题的解决办法的问题

现在市场上比较大的公司都建立了自己的企业网站,比如华为、小米等,在他们的企业网站中,可以充分展示自己产品的优势,介绍公司的优质服务。 这都是让顾客改变购买想法的重要因素。 现在互联网发达了,很多人在购买产品的…

详细分析axios.js:72 Uncaught (in promise) Error: 未知错误 的解决方法(图文)

目录 1. 问题所示2. 原理分析3. 解决方法1. 问题所示 调试接口的时候,打开一个网页,在终端出现如下错误: axios.js:72 Uncaught (in promise) Error: 未知错误at __webpack_exports__.default (axios.js:72:1)截图如下所示: 2. 原理分析 点击浏览器的Bug出错: // 如果…

C/C++语言学习路线: 嵌入式开发、底层软件、操作系统方向(持续更新)

初级:用好手上的锤子 1 【感性】认识 C 系编程语言开发调试过程 1.1 视频教程点到为止 1.2 炫技视频看看就行 1.3 编程游戏不玩也罢 有些游戏的主题任务就是编程,游戏和实际应用环境有一定差异(工具、操作流程),在…

进程知识点

引用的文章:操作系统——进程通信(IPC)_系统ipc-CSDN博客 面试汇总(五):操作系统常见面试总结(一):进程与线程的相关知识点 - 知乎 (zhihu.com) 二、进程的定义、组成、组成方式及特征_进程的组成部分必须包含-CSDN博…

2024年北京事业单位报名照片要求,注意格式

2024年北京事业单位报名照片要求,注意格式

【C语言】预处理常见知识详解(宏详解)

文章目录 1、预定义符号2、define2.1 define 定义常量2.2 define 定义宏 3、#和##3.1 **#**3.2 **##** 4、条件编译(开关) 1、预定义符号 在C语言中内置了一些预定义符号,可以直接使用,这些符号实在预处理期间处理的,…

工控安全双评合规:等保测评与商用密码共铸新篇章

01.双评合规概述 2017年《中华人民共和国网络安全法》开始正式施行,网络安全等级测评工作也在全国范围内按照相关法律法规和技术标准要求全面落实实施。2020年1月《中华人民共和国密码法》开始正式施行,商用密码应用安全性评估也在有序推广和逐步推进。…

信息安全之网络安全防护

先来看看计算机网络通信面临的威胁: 截获——从网络上窃听他人的通信内容中断——有意中断他人在网络上的通信篡改——故意篡改网络上传送的报文伪造——伪造信息在网络上传送 截获信息的攻击称为被动攻击,而更改信息和拒绝用户使用资源的攻击称为主动…

深入了解高压电阻器的世界,探索其操作、类型和在各种高压应用中的关键作用

高压电阻器是高压条件下的专用元件,对于管理电压和散热至关重要 它们的工作原理是欧姆定律 类型包括线绕电阻、碳复合电阻、金属氧化物膜电阻、厚膜电阻和薄膜电阻这些电阻器在电力系统、医疗设备、汽车电子和电信设备中是必不可少的。 额定电压从600V到48KV 80p…

fastadmin学习04-一键crud

FastAdmin 默认内置一个 test 表,可根据表字段名、字段类型和字段注释通过一键 CRUD 自动生成。 create table fa_test (id int unsigned auto_increment comment ID primary key,user_id int(10) default 0 null…
最新文章