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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux.zip文件怎么解压,linux怎么解压zip文件[通俗易懂]

    linux.zip文件怎么解压,linux怎么解压zip文件[通俗易懂]ZIP是最广泛使用的归档文件格式,支持无损数据压缩。ZIP文件是包含一个或多个压缩文件或目录的数据容器在此文中将向您展示如何使用unzip命令通过命令行解压缩Linux系统中的文件Unzip命令,可帮助您列出,测试和提取压缩的ZIP归档安装unzip默认情况下,大多数Linux发行版中都没有安装Unzip,但您可以使用发行版的软件包管理器安装它。在Ubuntu和Debian上安装unzipsudo…

    2022年5月11日
    40
  • java中高级面试题总结(全面)_java面试题大全

    java中高级面试题总结(全面)_java面试题大全jvm结构原理,GC工作原理Jvm结构:Jvm主要包括四个部分:1、类加载器(ClassLoad)在JVM启动时或者在类运行时将需要的class加载到JVM中。类加载时间与过程:类从被加载到虚拟机内存开始,在到卸载出内存为止,正式生命周期包括了:加载,验证,准备,解析,初始化,使用和卸载7个阶段。其中验证、准备、解析这个三个步…

    2022年8月20日
    5
  • 令人炸毛儿的MySQL隐式转换 – 无形之刃,最为致命

    令人炸毛儿的MySQL隐式转换 – 无形之刃,最为致命我相信90%以上的同学们在平时开发时,或多或少都被隐式转换(CONVERT_IMPLICIT)坑过,甚至测出bug前你都浑然不知。你还别不信,“无形之刃,最为致命!”

    2022年10月11日
    0
  • Gerrit使用教程详解[通俗易懂]

    Gerrit使用教程详解[通俗易懂]个人觉得这几篇博客介绍挺详细的,收藏转发分享:1、gerrit使用教程(一)https://www.cnblogs.com/111testing/archive/2018/08/09/9450530.html2、git上传本地代码到远程仓库https://www.cnblogs.com/111testing/p/7663229.html3、gitlog查看提交历史https:/…

    2022年10月23日
    0
  • 再次研究消息队列记的笔记——activemq

    再次研究消息队列记的笔记——activemq

    2021年7月12日
    74
  • 教你win10系统显卡驱动安装失败的解决方法【系统天地】

    教你win10系统显卡驱动安装失败的解决方法【系统天地】我们日常在对电脑的使用过程中,经常都会遇到这样或那样的问题。比如说win10系统显卡驱动安装失败该怎么办呢?别着急,还有小编在呢?接下来小编就来告诉大家win10电脑系统显卡驱动安装失败怎么解决。详细教你win10系统显卡驱动安装失败怎么办:方法一,删除之前的显卡驱动文件重新安装1,首先,右键点击“此电脑”,菜单栏选择“管理”。2,进入计算机管理界面后,点击“设备管理器”,然后在界面右侧展开“显示适配器”选项,并右键点击显卡驱动程序,菜单栏选择“属性”下一步。3,点击“卸载设备”。4,显卡驱动程

    2022年5月22日
    33

发表回复

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

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