Kafka Production Inspect

在生产环境中如果 Kafka 出现了问题,需要对其进行调查,幸运的是 Kafka 安装时自带了一些命令行工具,但这些工具使用起来比较繁琐,为避免每次都查询,记录如下。

检查 Topic#

使用 bin/kafka-topics.sh 命令可用检查 topic 的信息。

如果目标 kafka 使用用户名和密码认证,则需要创建一个文件,有时服务器中可能没有vi,这里使用 cat 来创建多行文件:

bash-5.0# cat <<EOF > /tmp/client.config
> security.protocol=SASL_PLAINTEXT
> sasl.mechanism=PLAIN
> sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="<YOUR_USERNAME>" password="<YOUR_PASSWORD>";
> EOF

然后使用下面命令列出所有的topic

bin/kafka-topics.sh --bootstrap-server localhost:9092 --command-config /tmp/client.properties --list

创建topic

bin/kafka-topics.sh --bootstrap-server localhost:9092 --command-config /tmp/client.properties --create --topic test_logging

查看topic详情

bin/kafka-topics.sh --bootstrap-server localhost:9092 --command-config /tmp/client.properties --describe --topic test_logging
comments powered by Disqus