您好,登錄后才能下訂單哦!
本篇內容主要講解“如何利用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.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 …
注意:我的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#
修改后的截圖如下
到此,相信大家對“如何利用Kafka動態調整topic分區partition”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。