本篇内容主要讲解“如何利用kafka动态调整topic分区partition”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何利用Kafka动态调整topic分区partition”吧!Kafk
本篇内容主要讲解“如何利用kafka动态调整topic分区partition”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何利用Kafka动态调整topic分区partition”吧!
在使用kafka时,初期创建topic时所指定的topic属性有时会需要修改,如何动态修改kafka topic属性?kafka提供了命令行工具kafka-topics.sh.
kafka-topics.sh工具也是我们用来创建topic、查看topic详情的工具。
直接运行kafka-topics.sh可以看出,它是用来创建、删除、查看以及更新topic的
root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ./kafka-topics.shCreate, delete, describe, or change a topic.Option Description–alter Alter the number of partitions,replica assignment, and/orconfiguration for the topic.–config <String: name=value> A topic configuration override for…
注意:我的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 yQtopic1Created 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 yqtopic1Topic:yqtopic1 PartitionCount:4 ReplicationFactor:1 Configs:Topic: yqtopic1 Partition: 0 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 1 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 2 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 3 Leader: 0 Replicas: 0 Isr: 0root@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 12WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affectedAdding 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: 0Topic: yqtopic1 Partition: 1 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 2 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 3 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 4 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 5 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 6 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 7 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 8 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 9 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 10 Leader: 0 Replicas: 0 Isr: 0Topic: yqtopic1 Partition: 11 Leader: 0 Replicas: 0 Isr: 0root@ubuntu:/opt/kafka_2.11-1.1.0/bin# ls -al /tmp/kafka-logs/total 72drwxr-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-checkpointdrwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-0drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-1drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-10drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-11drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-2drwxr-xr-x 2 root root 4096 Oct 13 14:20 yqtopic1-3Drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-4drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-5drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-6drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-7drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-8drwxr-xr-x 2 root root 4096 Oct 13 14:33 yqtopic1-9root@ubuntu:/opt/kafka_2.11-1.1.0/bin#
修改后的截图如下
到此,相信大家对“如何利用Kafka动态调整topic分区partition”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: 如何利用Kafka动态调整topic分区partition
本文链接: https://www.lsjlt.com/news/347535.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0