0%

kafkactl

与Kafka交互的命令行工具


背景

平常使用kafka的命令行感觉不是很方便,每次都要找地址和打很长的命令。

调研发现kafkactl可以满足需求。简单明了,解压就可以用,不用装JDK

介绍

kafkactl 是一个与Apache Kafka交互的命令行工具

github地址:https://github.com/deviceinsight/kafkactl

安装

在releases下载最新的二进制包解压即可用

在用户的家目录下创建配置文件 .config/kafkactl/config.yml

在配置文件里配置好要kafka集群地址信息

1
2
3
4
5
6
7
8
9
10
11
contexts:
default:
brokers:
- localhost:9092
remote-cluster:
brokers:
- remote-cluster001:9092
- remote-cluster002:9092
- remote-cluster003:9092

current-context: default

使用

直接输入kafkactl可以查看帮助,感兴趣的可以看下视频学习 https://asciinema.org/a/vmxrTA0h8CAXPnJnSFk5uHKzr

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ kafkactl
A command-line interface the simplifies interaction with Kafka.

Usage:
kafkactl [command]

Available Commands:
alter alter topics, partitions
attach run kafkactl pod in kubernetes and attach to it
completion
config show and edit configurations
consume consume messages from a topic
create create topics, consumerGroups, acls
delete delete topics, acls
describe describe topics, consumerGroups
get get info about topics, consumerGroups, acls
help Help about any command
produce produce messages to a topic
reset reset consumerGroupsOffset
version print the version of kafkactl

Flags:
-C, --config-file string config file. one of: [$HOME/.config/kafkactl $HOME/.kafkactl $SNAP_REAL_HOME/.config/kafkactl $SNAP_DATA/kafkactl /etc/kafkactl]
-h, --help help for kafkactl
-V, --verbose verbose output

Use "kafkactl [command] --help" for more information about a command.
选择要访问的集群
1
2
3
4
5
6
7
8
$ kafkactl config get-contexts
ACTIVE NAME
remote-cluster
* default

$ kafkactl config use-context remote-cluster
$ kafkactl config current-context
remote-cluster
获取主题和消费者组
1
2
kafkactl get topics
kafkactl get consumer-groups
查看主题和消费者组详情
1
2
kafkactl describe topic xxx
kafkactl describe consumer-group xxx

总结

挺好用的工具,不需要安装jdk,解压就可以使用。

输出所有消费组的功能挺好的,在集群裁撤时可以一下子查出所有的对应关系


参考链接