前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kafka动态调整topic分区partition

Kafka动态调整topic分区partition

作者头像
全栈程序员站长
发布2022-11-02 09:54:27
1.6K0
发布2022-11-02 09:54:27
举报
文章被收录于专栏:全栈程序员必看

在使用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.cn/181079.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档