利用Kafka动态调整topic分区partition

 更新时间:2022年12月29日 10:02  点击:280 作者:russle

Kafka动态调整topic分区partition

在使用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://blog.csdn.net/russle/article/details/83038506

[!--infotagslink--]

相关文章

  • .NET Core下使用Kafka的方法步骤

    这篇文章主要介绍了.NET Core下使用Kafka的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22
  • 深入了解如何基于Python读写Kafka

    这篇文章主要介绍了深入了解如何基于Python读写Kafka,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-05-06
  • 详解partition by和group by对比

    这篇文章主要介绍了详解partition by和group by对比,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • 阿里云主机Windows 2008服务器硬盘分区和格式化图文教程

    这篇文章主要介绍了阿里云主机Windows 2008服务器硬盘分区和格式化图文教程,本文对每一个步骤都配有图文解说,一看就会呀,需要的朋友可以参考下...2016-01-27
  • mysql分区功能详解,以及实例分析

    下面小编就为大家带来一篇mysql分区功能详解,以及实例分析。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2017-04-03
  • MySQL中表分区技术详细解析

    数据库分区是一种物理数据库设计技术。虽然分区技术可以实现很多效果,但其主要目的是为了在特定的SQL操作中减少数据读写的总量以缩减sql语句的响应时间,同时对于应用来说分区完全是透明的。...2016-06-24
  • Mysql临时表及分区表区别详解

    这篇文章主要介绍了Mysql临时表及分区表区别详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-10
  • mysql中如何判断是否支持分区

    mysql可以通过下面语句判断是否支持分区:SHOW VARIABLES LIKE '%partition%';如果输出:have_partitioning YES表示支持分区。或者通过:SHOW PLUGINS; 显示所有插件,如果有partition ACTIVE STORAGE ENGINE GPL 插件则表...2015-10-21
  • 详解MySQL分区表

    这篇文章主要介绍了MySQL分区表的相关资料,帮助大家更好的理解和学习mysql,感兴趣的朋友可以了解下...2020-08-11
  • 什么是分表和分区 MySql数据库分区和分表方法

    这篇文章主要为大家详细介绍了MySql数据库分区和分表方法,告诉大家什么是分表和分区,mysql分表和分区有什么联系,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-02-19
  • 解决kafka消息堆积及分区不均匀的问题

    这篇文章主要介绍了解决kafka消息堆积及分区不均匀的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-12
  • SpringBoot+Nacos+Kafka微服务流编排的简单实现

    本文主要介绍了SpringBoot+Nacos+Kafka微服务流编排的简单实现,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-20
  • MySQL 5.5 range分区增加删除处理的方法示例

    这篇文章主要给大家介绍了关于MySQL 5.5 range分区增加删除处理的相关资料,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。...2017-06-12
  • .Net Core 集成 Kafka的步骤

    这篇文章主要介绍了.Net Core 集成 Kafka的实现步骤,帮助大家更好的理解和学习使用.net技术,感兴趣的朋友可以了解下...2021-09-22
  • MySql分表、分库、分片和分区知识深入详解

    这篇文章主要介绍了MySql分表、分库、分片和分区知识深入详解,如果有并发场景和数据量较大的场景的可以看一下文章,对你会有或多或少的帮助...2021-03-20
  • MySQL数据库分区功能的使用教程

    这篇文章主要介绍了MySQL数据库分区功能的使用教程,文中特别讲解了MySQL分表和分区的区别以及联系,需要的朋友可以参考下...2016-05-09
  • python 实现mysql自动增删分区的方法

    这篇文章主要介绍了python 实现mysql自动增删分区的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-04-01
  • java自己手动控制kafka的offset操作

    这篇文章主要介绍了java自己手动控制kafka的offset操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-20
  • PostgreSQL 创建表分区

    在pg里表分区是通过表继承来实现的,一般都是建立一个主表,里面是空,然后每个分区都去继承它。...2020-07-11
  • C#判断指定分区是否是ntfs格式的方法

    这篇文章主要介绍了C#判断指定分区是否是ntfs格式的方法,涉及C#中DriveFormat属性的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25