kafka ---- 相关命令行详解1

一、kafka-cluster.sh

kafka-cluster.sh cluster-id 获取 cluster-id

[zhjl@yyzc-zhjlpi01 bin]$ sh kafka-cluster.sh cluster-id  --bootstrap-server $BOOTSTRAP
Cluster ID: qbPSC2UUSWS7fHAawkQXBg

ZK命令

[zk: localhost:2181(CONNECTED) 4] get  /cluster/id
{"version":"1","id":"qbPSC2UUSWS7fHAawkQXBg"}

2、sh kafka-cluster.sh unregister 取消注册一个broker

[zhjl@yyzc-zhjlpi01 bin]$ sh kafka-cluster.sh  unregister  --help
usage: kafka-cluster unregister [-h] [--bootstrap-server BOOTSTRAP_SERVER] [--config CONFIG] [--id ID]

optional arguments:
-h, --help             show this help message and exit
--bootstrap-server BOOTSTRAP_SERVER, -b BOOTSTRAP_SERVER
A list of host/port pairs to use for establishing the connection to the kafka cluster.
--config CONFIG, -c CONFIG
A property file containing configs to passed to AdminClient.
--id ID, -i ID         The ID of the broker to unregister.
[zhjl@yyzc-zhjlpi01 bin]$

二、kafka-get-offsets.sh

1、 kafka-get-offsets.sh --bootstrap-server $BOOTSTRAP --topic-partitions topic-A:1 获取该partition的最新的offset

[zhjl@yyzc-zhjlpi01 bin]$ sh  kafka-get-offsets.sh   --bootstrap-server $BOOTSTRAP  --topic-partitions topic-A:1
topic-A:1:58
[zhjl@yyzc-zhjlpi01 bin]$
[zhjl@yyzc-zhjlpi01 bin]$  sh kafka-dump-log.sh  --files /tmp/kafka-logs/topic-A-1/00000000000000000000.log --print-data-log |tail
baseOffset: 57 lastOffset: 57 count: 1 baseSequence: 0 lastSequence: 0 producerId: 1114 producerEpoch: 0 partitionLeaderEpoch: 1 isTransactional: false isControl: false deleteHorizonMs: OptionalLong.empty position: 13148 CreateTime: 1713262669533 size: 281 magic: 2 compresscodec: none crc: 3675322261 isvalid: true
| offset: 57 CreateTime: 1713262669533 keySize: -1 valueSize: 211 sequence: 0 headerKeys: [] payload: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA97
[zhjl@yyzc-zhjlpi01 bin]$

三、 kafka-log-dirs.sh

1、help

This tool helps to query log directory usage on the specified brokers.
Option                                  Description
------                                  -----------
--bootstrap-server <String: The server  REQUIRED: the server(s) to use for
(s) to use for bootstrapping>           bootstrapping
--broker-list <String: Broker list>     The list of brokers to be queried in
the form "0,1,2". All brokers in the
cluster will be queried if no broker
list is specified
--command-config <String: Admin client  Property file containing configs to be
property file>                          passed to Admin Client.
--describe                              Describe the specified log directories
on the specified brokers.
--help                                  Print usage information.
--topic-list <String: Topic list>       The list of topics to be queried in
the form "topic1,topic2,topic3". All
topics will be queried if no topic
list is specified (default: )
--version                               Display Kafka version.

2、 sh kafka-log-dirs.sh --bootstrap-server $BOOTSTRAP --describe 获取日志路径,大小等信息

[zhjl@yyzc-zhjlpi01 bin]$ sh  kafka-log-dirs.sh   --bootstrap-server $BOOTSTRAP --describe
Querying brokers for log directories information
Received log directory information from brokers 1,2,6
{"version":1,"brokers":[{"broker":2,"logDirs":[{"logDir":"/tmp/kafka-logs","error":null,"partitions":[{"partition":"topic-A-2","size":5279,"offsetLag":0,"isFuture":false},{"partition":"topic-A-1","size":13429,"offsetLag":0,"isFuture":false},{"partition":"topic-A-0","size":14198,"offsetLag":0,"isFuture":false}]}]},{"broker":1,"logDirs":[{"logDir":"/tmp/kafka-logs","error":null,"partitions":[{"partition":"topic-A-2","size":5279,"offsetLag":0,"isFuture":false},{"partition":"topic-A-1","size":13429,"offsetLag":0,"isFuture":false},{"partition":"topic-A-0","size":14198,"offsetLag":0,"isFuture":false}]}]},{"broker":6,"logDirs":[{"logDir":"/tmp/kafka-logs","error":null,"partitions":[{"partition":"topic-A-2","size":5279,"offsetLag":0,"isFuture":false},{"partition":"topic-A-1","size":13429,"offsetLag":0,"isFuture":false},{"partition":"topic-A-0","size":14198,"offsetLag":0,"isFuture":false}]}]}]}
[zhjl@yyzc-zhjlpi01 bin]$

3、sh kafka-storage.sh format -c …/config/server.properties -t qbPSC2UUSWS7fHAawkQXBg (KRaft模式)

[zhjl@yyzc-zhjlpi01 bin]$ sh kafka-storage.sh format  -c ../config/server.properties -t qbPSC2UUSWS7fHAawkQXBg
The kafka configuration file appears to be for a legacy cluster. Formatting is only supported for clusters in KRaft mode.
[zhjl@yyzc-zhjlpi01 bin]$
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值