kafka-consumer-groups 命令行工具使用手册,Kafka管理必备

kafka-consumer-groups 命令行工具使用手册

该手册原文出自 $KAFKA_HOME\bin\windows\kafka-consumer-groups.bat --help 命令的输出结果,并由 Redisant 提供翻译和测试用例。

--all-groups

Apply to all consumer groups.

指定所有的消费者组。 和 --describe, --delete, --reset-offsets, --delete-offsets 配合使用

--all-topics

Consider all topics assigned to a group in the reset-offsets process.

指定所有的消费者组。 和 --reset-offsets 配合使用

--bootstrap-server

REQUIRED: The server(s) to connect to.

必填项,Kafka服务器的地址和端口。

--by-duration

Reset offsets to offset by duration from current timestamp. Format: 'PnDTnHnMnS'

--command-config

Property file containing configs to be passed to Admin Client and Consumer.

--delete

Pass in groups to delete topic partition offsets and ownership information over the entire consumer group. For instance --group g1 --group g2

删除整个消费者组(包括已保存的偏移量信息和所有权信息),在执行该操作之前,必须关闭所有的消费者。

  • 删除所有的消费者组
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups CountryCounter --delete
Deletion of requested consumer groups ('CountryCounter', 'OrderCounter') was successful.
  • 删除指定的消费者组
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --delete
Deletion of requested consumer groups ('CountryCounter') was successful.

--delete-offsets

Delete offsets of consumer group. Supports one consumer group at the time, and multiple topics.

删除消费者组的偏移量。例如:

PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --delete-offsets --group CountryCounter --topic t1

--describe

Describe consumer group and list offset lag (number of messages not yet processed) related to given group.

列出消费者组里所有主题的信息和每个分区的偏移量。例如:

  • 查看指定的消费者组:
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                          HOST            CLIENT-ID
CountryCounter  user_card       0          214             214             0               chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
CountryCounter  t1              0          189             189             0               chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
  • 查看所有的消费者组:
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                          HOST            CLIENT-ID
CountryCounter  user_card       0          214             214             0               chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client
CountryCounter  t1              0          189             189             0               chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client

GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                   HOST            CLIENT-ID
OrderCounter    t1              0          189             189             0               client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2
OrderCounter    t2              0          1257            1257            0               client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2

--group

The consumer group we wish to act on.

配合其他命令执行消费者组

--help

Print usage information.

打印帮助手册

--list

List all consumer groups.

列出所有的消费者组。例如:

PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --list
OrderCounter
CountryCounter

--members

Describe members of the group. This option may be used with '--describe' and '--bootstrap-server' options only. Example: --bootstrap-server localhost:9092 --describe --group group1 --members

查看消费者组里有哪些成员,该选项只能和 --describe--bootstrap-server 一起使用。例如:

  • 查看指定的消费者组里有哪些成员
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe --members

GROUP           CONSUMER-ID                                          HOST            CLIENT-ID       #PARTITIONS
CountryCounter  chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client 2
  • 查看所有的消费者组里有哪些成员
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe --members

GROUP           CONSUMER-ID                                          HOST            CLIENT-ID       #PARTITIONS
CountryCounter  chenjing_client-42cc37c6-695f-4c47-b844-764a3d2169d3 /111.18.132.232 chenjing_client 2

GROUP           CONSUMER-ID                                   HOST            CLIENT-ID       #PARTITIONS
OrderCounter    client_2-26992db5-d5ab-4252-a219-995bdbe37388 /111.18.132.232 client_2        2

--reset-offsets

Reset offsets of consumer group. Supports one consumer group at the time, and instances should be inactive.

Has 2 execution options: --dry-run (the default) to plan which offsets to reset, and --execute to update the offsets. Additionally, the --export option is used to export the results to a CSV format.

You must choose one of the following reset specifications: --to-datetime, --by-duration, --to-earliest, --to-latest, --shift-by, --from-file, --to-current, --to-offset.

To define the scope use --all-topics or --topic. One scope must be specified unless you use '--from-file'.

重置消费者组的偏移量。如果执行消费者组,一次只能指定一个消费组(需要提前关闭相关的消费者和生产者)。有两个执行参数:--dry-run(默认值)用于打印计划要重置的偏移量,以及 --execute 以更新偏移量。此外,--export 选项用于将结果导出为 CSV 格式。 必须选择以下重置类型之一(关于这些重置类型的更多参考请查看 官方文档):--to-datetime, --by-duration, --to-earliest, --to-latest, --shift-by, --from-file, --to-current, --to-offset

例如(以下所有命令均使用 --dry-run 参数打印执行计划,如果执行计划符合你的期望,请把 --dry-run 替换为 --execute 以真正更新偏移量):

  • 重置指定消费组的所有Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --group CountryCounter --dry-run --all-topics

GROUP                          TOPIC                          PARTITION  NEW-OFFSET
CountryCounter                 user_card                      1          0
CountryCounter                 user_card                      0          521
CountryCounter                 user_card                      2          0
CountryCounter                 t1                             0          0
  • 重置指定消费组的指定Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --group CountryCounter --dry-run --topic t1


GROUP                          TOPIC                          PARTITION  NEW-OFFSET
CountryCounter                 t1                             0          0
  • 重置所有消费组的所有Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --all-groups --dry-run --all-topics

GROUP                          TOPIC                          PARTITION  NEW-OFFSET
OrderCounter                   t2                             2          0
OrderCounter                   t1                             0          0
OrderCounter                   t2                             1          0
OrderCounter                   t2                             0          0
CountryCounter                 user_card                      1          0
CountryCounter                 user_card                      0          521
CountryCounter                 user_card                      2          0
CountryCounter                 t1                             0          0
  • 重置所有消费组中指定Topic的偏移量
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --reset-offsets --to-earliest --all-groups --dry-run --topic t1

GROUP                          TOPIC                          PARTITION  NEW-OFFSET
OrderCounter                   t1                             0          0
CountryCounter                 t1                             0          0

--shift-by <Long: number-of-offsets>

Reset offsets shifting current offset by 'n', where 'n' can be positive or negative.

--state [String]

When specified with '--describe', includes the state of the group. Example: --bootstrap-server localhost:9092 --describe --group group1 --state

--describe 配合使用,列出消费者组的状态。例如:

  • 列出指定消费者组的状态
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --group CountryCounter --describe --state

GROUP                     COORDINATOR (ID)          ASSIGNMENT-STRATEGY  STATE           #MEMBERS
CountryCounter            192.168.31.253:9092 (0)   range                Stable          1
  • 列出所有消费者组的状态
PS C:\Users\chenjing\kafka_2.12-3.3.1> .\bin\windows\kafka-consumer-groups.bat --bootstrap-server 192.168.31.253:9092 --all-groups --describe --state

GROUP                     COORDINATOR (ID)          ASSIGNMENT-STRATEGY  STATE           #MEMBERS
CountryCounter            192.168.31.253:9092 (0)   range                Stable          1

GROUP                     COORDINATOR (ID)          ASSIGNMENT-STRATEGY  STATE           #MEMBERS
OrderCounter              192.168.31.253:9092 (0)   range                Stable          1

--timeout <Long: timeout (ms)>

The timeout that can be set for some use cases. For example, it can be used when describing the group to specify the maximum amount of time in milliseconds to wait before the group stabilizes (when the group is just created, or is going through some changes). (default: 5000)

可以为某些用例设置的超时。例如,在显示消费者组的详情时,可以使用它来指定在组稳定之前等待的最长时间(以毫秒为单位)(当组刚刚创建或正在经历一些更改时),默认值:5000

--topic

The topic whose consumer group information should be deleted or topic whose should be included in the reset offset process. In reset-offsets case, partitions can be specified using this format: topic1:0,1,2, where 0,1,2 are the partition to be included in the process. Reset-offsets also supports multiple topic inputs.

配合其他命令指定主题名

--verbose

Provide additional information, if any, when describing the group. This option may be used with '--offsets'/'--members'/'--state' and '--bootstrap-server' options only.

Example: --bootstrap-server localhost:9092 --describe --group group1 --members --verbose

在描述组时提供其他信息(如果有的话)。此选项只能与 --offsets --members --state --bootstrap-server 选项一起使用。

--version

Display Kafka version.

打印Kafka版本号

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 225,928评论 6 523
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 97,032评论 3 410
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 173,382评论 0 370
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 61,580评论 1 304
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 70,558评论 6 403
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 54,018评论 1 316
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 42,261评论 3 432
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 41,328评论 0 281
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 47,858评论 1 328
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 39,843评论 3 351
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 41,954评论 1 358
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 37,565评论 5 352
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 43,251评论 3 342
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 33,677评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 34,834评论 1 278
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 50,558评论 3 383
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 47,033评论 2 368

推荐阅读更多精彩内容