kafka-topics.sh指令碼介紹

kafka-topics。sh

透過指令碼進行主題的管理,包括:建立主題、檢視主題、修改主題、刪除主題等操作。內部是靠

kafka。admin。TopicCommand

接收引數執行。

[xuhaixing@xhx151 ~]$ kafka-topics。sh ——helpThis tool helps to create, delete, describe, or change a topic。Option Description ———— ——————- ——alter Alter the number of partitions, replica assignment, and/or configuration for the topic。 ——at-min-isr-partitions if set when describing topics, only show partitions whose isr count is equal to the configured minimum。 Not supported with the ——zookeeper option。 ——bootstrap-server to。 In case of providing this, a direct Zookeeper connection won‘t be required。 ——command-config passed to Admin Client。 This is used only with ——bootstrap-server option for describing and altering broker configs。 ——config A topic configuration override for the topic being created or altered。 The following is a list of valid configurations: cleanup。policy compression。type delete。retention。ms file。delete。delay。ms flush。messages flush。ms follower。replication。throttled。 replicas index。interval。bytes leader。replication。throttled。replicas max。compaction。lag。ms max。message。bytes message。downconversion。enable message。format。version message。timestamp。difference。max。ms message。timestamp。type min。cleanable。dirty。ratio min。compaction。lag。ms min。insync。replicas preallocate retention。bytes retention。ms segment。bytes segment。index。bytes segment。jitter。ms segment。ms unclean。leader。election。enable See the Kafka documentation for full details on the topic configs。 It is supported only in combination with —— create if ——bootstrap-server option is used (the kafka-configs CLI supports altering topic configs with a ——bootstrap-server option)。 ——create Create a new topic。 ——delete Delete a topic ——delete-config A topic configuration override to be removed for an existing topic (see the list of configurations under the ——config option)。 Not supported with the ——bootstrap-server option。 ——describe List details for the given topics。 ——disable-rack-aware Disable rack aware replica assignment ——exclude-internal exclude internal topics when running list or describe command。 The internal topics will be listed by default ——force Suppress console prompts ——help Print usage information。 ——if-exists if set when altering or deleting or describing topics, the action will only execute if the topic exists。 ——if-not-exists if set when creating topics, the action will only execute if the topic does not already exist。 ——list List all available topics。 ——partitions The number of partitions for the topic being created or altered (WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected)。 If not supplied for create, defaults to the cluster default。 ——replica-assignment ——replication-factor partition in the topic being created。 If not supplied, defaults to the cluster default。 ——topic The topic to create, alter, describe or delete。 It also accepts a regular expression, except for ——create option。 Put topic name in double quotes and use the ’\‘ prefix to escape regular expression symbols; e。 g。 “test\。topic”。 ——topics-with-overrides if set when describing topics, only show topics that have overridden configs ——unavailable-partitions if set when describing topics, only show partitions whose leader is not available ——under-min-isr-partitions if set when describing topics, only show partitions whose isr count is less than the configured minimum。 Not supported with the ——zookeeper option。 ——under-replicated-partitions if set when describing topics, only show under replicated partitions ——version Display Kafka version。 ——zookeeper DEPRECATED, The connection string for the zookeeper connection in the form host:port。 Multiple hosts can be given to allow fail-over。

kafka-topics。sh指令碼中的引數

引數名稱

釋義

alter

用於修改主題

config 鍵值對

建立或修改主題時,用於設定主題級別的引數

create

建立主題

delete

刪除主題

delete-config 配置名稱

刪除主題級別被覆蓋的配置

describe

檢視主題的詳細資訊

disable-rack-aware

建立主題時不考慮機架資訊

help

列印幫助資訊

if-exists

修改或刪除主題時使用,只有當主題存在時才會執行動作

if-not-exists

建立主題時使用,只有主題不存在時才會執行動作

list

列出所有可用的主題

partitons 分割槽數

建立主題或增加分割槽時指定的分割槽數

replica-assignment 分配方案

手工指定分割槽副本分配方案

replication-factor 副本數

建立主題時指定副本因子

topic 主題名稱

指定主題名稱

topics-with-overrides

使用describe檢視主題資訊時,只展示包含覆蓋配置的主題

unavailable-partitions

使用describe檢視主題資訊時,只展示包含沒有leader副本的分割槽

under-replicated-partitions

使用describe檢視主題資訊時,只展示包含失效副本的分割槽

zookeeper

指定連線的zk的地址,已經過時,可以改成 ——bootstrap-server

1。 常用命令

檢視所有topic

kafka-topics。sh ——zookeeper 192。168。94。151:2181/kafka ——listkafka-topics。sh ——bootstrap-server 192。168。94。151:9092 ——list

建立topic

kafka-topics。sh ——zookeeper 192。168。94。151:2181/kafka ——create ——topic test-topic ——replication-factor 2 ——partitions 3kafka-topics。sh ——bootstrap-server 192。168。94。151:9092 ——create ——topic test-topic-2 ——replication-factor 2 ——partitions 3 ——config retention。ms=36000000000 ——config max。message。bytes=64000

檢視topic配置資訊

kafka-topics。sh ——zookeeper 192。168。94。151:2181/kafka ——describe ——topic test-topic

擴大分割槽

kafka-topics。sh ——zookeeper 192。168。94。151:2181/kafka ——alter ——topic test-topic ——partitions 6

修改topic配置

kafka-topics。sh ——bootstrap-server 192。168。94。151:9092 -topic test-topic ——alter ——config retention。ms=259200000

kafka topic config引數

1。 cleanup。policy

過期或達到日誌上限的清理策略(delete-刪除;compact-壓縮)預設值為delete

2。 compression。type

指定給該topic最終的壓縮型別(uncompressed;snappy;lz4;gzip;producer)預設值為producer

3。 delete。retention。ms

壓縮日誌保留的最長時間,也是消費端訊息的最長時間。單位為毫秒(預設值:86400000)

4。 file。delete。delay。ms

從檔案系統中刪除前所等待的時間(預設值:60000)

5。 flush。messages

在訊息刷到磁碟前,日誌分割槽收集的訊息數(預設值:Long。MAX_VALUE)

6。 flush。ms

訊息刷到磁碟前,儲存在記憶體中的最長時間,單位ms(預設值:Long。MAX_VALUE)

7。 index。interval。bytes

當執行fetch操作後,需要一定的空間來掃描最近的offset大小。設定越大,掃描速度更快但更耗記憶體,一般情況下不用設定此引數。(預設值:4096)

8。 max。message。bytes

log中能夠容納訊息的最大位元組數(預設值:1000012)

9。 min。cleanable。dirty。ratio

日誌清理的頻率控制,越大清理更高效(預設值:0。5)

10。 retention。bytes

topic每個分割槽的最大檔案大小。(預設值:-1沒有限制)

11。 retention。ms

日誌檔案保留的ms。資料儲存的最大時間超過這個時間會根據cleanup。policy策略處理資料。

12。 segment。bytes

topic的檔案是以segment檔案儲存的,該引數控制每個segment檔案的大小(預設值:1073741824)

13。 segment。index。bytes

對於segment日誌的索引檔案大小限制(預設值:10M)