Kafka动态调整topic分区partition

Kafka动态调整topic分区partition我们在使用kafka时,初期创建时所指定topic属性需要修改,如何动态修改kafka属性?kafka提供了命令行工具—kafka-topics.sh.kafka-topics.sh工具介绍kafka-topics.sh工具也是我们用来创建topic、查看topic详情的工具。直接运行kafka-topics.sh可以产出它是用来创建、删除、查看以及更新topicroot@ubuntu……

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

在使用kafka时,初期创建topic时所指定的topic属性有时会需要修改,如何动态修改kafka topic属性?kafka提供了命令行工具—kafka-topics.sh.

  • kafka-topics.sh工具介绍

kafka-topics.sh工具也是我们用来创建topic、查看topic详情的工具。
直接运行kafka-topics.sh可以看出,它是用来创建、删除、查看以及更新topic的
root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.sh
Create, delete, describe, or change a topic.
Option Description


–alter Alter the number of partitions,
replica assignment, and/or
configuration for the topic.
–config <String: name=value> A topic configuration override for

  • 更新或者修改topic
    注意:我的kafka版本是1.1.0, 并且我只有一个broker。
    1, 首先我们创建一个topic,然后查看详情
    root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.sh –create –zookeeper 192.168.119.131:2181 –replication-factor 1 –partitions 4 –topic yqtopic1
    Created topic “yqtopic1”.
    root@ubuntu:/opt/kafka_2.11-1.1.0/bin#

root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.sh –describe –zookeeper 192.168.119.131:2181 –topic yqtopic1
Topic:yqtopic1 PartitionCount:4 ReplicationFactor:1 Configs:
Topic: yqtopic1 Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 2 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 3 Leader: 0 Replicas: 0 Isr: 0
root@ubuntu:/opt/kafka_2.11-1.1.0/bin#
在这里插入图片描述

2,修改刚创建的topic,并查看修改的情况
将分区数有4修改为12
root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.sh –alter –zookeeper 192.168.119.131:2181 –topic yqtopic1 –partitions 12
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@ubuntu:/opt/kafka_2.11-1.1.0/bin#

root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.sh –describe –zookeeper 192.168.119.131:2181 –topic yqtopic1 Topic:yqtopic1 PartitionCount:12 ReplicationFactor:1 Configs:
Topic: yqtopic1 Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 2 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 3 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 4 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 5 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 6 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 7 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 8 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 9 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 10 Leader: 0 Replicas: 0 Isr: 0
Topic: yqtopic1 Partition: 11 Leader: 0 Replicas: 0 Isr: 0
root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ls -al /tmp/kafka-logs/
total 72
drwxr-xr-x 14 root root 4096 Oct 13 14:34 .
drwxrwxrwt 17 root root 4096 Oct 13 14:34 …
-rw-r–r– 1 root root 0 Oct 13 14:10 cleaner-offset-checkpoint
-rw-r–r– 1 root root 0 Oct 13 14:10 .lock
-rw-r–r– 1 root root 4 Oct 13 14:33 log-start-offset-checkpoint
-rw-r–r– 1 root root 54 Oct 13 14:10 meta.properties
-rw-r–r– 1 root root 163 Oct 13 14:33 recovery-point-offset-checkpoint
-rw-r–r– 1 root root 163 Oct 13 14:34 replication-offset-checkpoint
drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-0
drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-1
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-10
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-11
drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-2
drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-3
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-4
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-5
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-6
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-7
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-8
drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-9
root@ubuntu:/opt/kafka_2.11-1.1.0/bin#

修改后的截图如下
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181079.html原文链接:https://javaforall.net

(0)
上一篇 2022年10月17日 上午9:46
下一篇 2022年10月17日 上午10:00


相关推荐

  • vm虚拟机怎么启动_虚拟机macos运行显卡驱动

    vm虚拟机怎么启动_虚拟机macos运行显卡驱动VM上完美运行macos作者:方辰昱时间:十月三号效果图简要步骤下载安装VM下载镜像文件链接,darwin.iso,unlocker,beamoff。合集下载链接:https://pan.baidu.com/s/1jeHA-ksEKT1iK5Ld7GmS9Q提取码:27tjunlock对VM进行操作使其对macos支持安装安装macos磁盘工具建立新的…

    2022年10月1日
    7
  • 如何使用Python读取大文件

    如何使用Python读取大文件

    2021年11月26日
    52
  • virsh 关机_kvm虚拟机的virsh命令日常管理和配置

    virsh 关机_kvm虚拟机的virsh命令日常管理和配置virsh命令显示列表显示正在运行的[root@oldboy/etc/libvirt/qemu]#virshlistIdNameState—————————————————-5centos7running显示…

    2022年8月11日
    12
  • 在pycharm安装torch包

    在pycharm安装torch包1 直接在 pycharm 中进行安装 file gt Setting 选择安装 显示报错 2 在官网 https pytorch org get started locally 下载包进行本地安装也不可以 3 在官网上面获取到安装指令 成功下载完成 适配于我电脑的指令为 pip3installt 适用的 torch 包为 torch 1 11 0 cp38 cp38 win amd64 whl

    2026年3月20日
    2
  • smartctl用法心得

    smartctl用法心得SMART简介S.M.A.R.T.,全称为“Self-MonitoringAnalysisandReportingTechnology”,即“自我监测、分析及报告技术”。是一种自动的硬盘状态检测与预警系统和规范。通过在硬盘硬件内的检测指令对硬盘的硬件如磁头、盘片、马达、电路的运行情况进行监控、记录并与厂商所设定的预设安全值进行比较,若监控情况将或已超出预设安全值的安全范围,就可以通过主机的监控硬件或软件自动向用户作出警告并进行轻微的自动修复,以提前保障硬盘数据的安全。除一些出厂时间极早的硬盘外,现

    2022年10月8日
    5
  • 牛顿法与Hessian矩阵

    牛顿法与Hessian矩阵牛顿法主要有两方面的应用 1 求方程的根 2 求解最优化方法 一 为什么要用牛顿法求方程的根 nbsp nbsp nbsp nbsp 问题很多 牛顿法是什么 目前还没有讲清楚 没关系 先直观理解为牛顿法是一种迭代求解方法 Newton 童鞋定义的方法 nbsp nbsp nbsp nbsp 假设 f x 0 为待求解方程 利用传统方法求解 牛顿法求解方程的公式 f x0 x nbsp f x0

    2026年3月19日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号