博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kafka0.10
阅读量:7038 次
发布时间:2019-06-28

本文共 4455 字,大约阅读时间需要 14 分钟。

整理kafka相关的常用命令

创建主题(4个分区,2个副本)
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 4 --topic test
查询集群描述
bin/kafka-topics.sh --describe --zookeeper

生产者

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

消费者

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test

新生产者(支持0.9版本+)

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties

新消费者(支持0.9版本+)

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --new-consumer --from-beginning --consumer.config config/consumer.properties

新消费者列表查询(支持0.9版本+)

bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list

显示某个消费组的消费详情(仅支持offset存储在zookeeper上的)

bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect localhost:2181 --group test

显示某个消费组的消费详情(支持0.9版本+)

bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group

平衡leader

bin/kafka-preferred-replica-election.sh --zookeeper zk_host:port/chroot

kafka自带压测命令

bin/kafka-producer-perf-test.sh --topic test --num-records 100 --record-size 1 --throughput 100 --producer-props bootstrap.servers=localhost:9092

kafka检查消费者位置

http://orchome.com/35

kafka检查消费者位置

Sometimes it's useful to see the position of your consumers. We have a tool that will show the position of all consumers in a consumer group as well as how far behind the end of the log they are. To run this tool on a consumer group named my-group consuming a topic named my-topic would look like this:
有时候需要去查看你的消费者的位置。我们有一个显示【消费者组中】所有消费者的位置的工具。显示日志其落后多远。消费者组名为my-group,消费者topic名为my-topic,如下:
> bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect localhost:2181 --group testGroup           Topic                          Pid Offset          logSize         Lag             Ownermy-group        my-topic                       0   0               0               0               test_jkreps-mn-1394154511599-60744496-0my-group        my-topic                       1   0               0               0               test_jkreps-mn-1394154521217-1a0be913-0

NOTE: Since 0.9.0.0, the kafka.tools.ConsumerOffsetChecker tool has been deprecated. You should use the kafka.admin.ConsumerGroupCommand (or the bin/kafka-consumer-groups.sh script) to manage consumer groups, including consumers created with the new consumer API.

注意
:在0.9.0.0,kafka.tools.ConsumerOffsetChecker已经不支持了。你应该使用kafka.admin.ConsumerGroupCommand(或bin/kafka-consumer-groups.sh脚本)来管理消费者组,包括用新消费者API创建的消费者。
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --describe --group test-consumer-group

Managing Consumer Groups

管理消费者组
With the ConsumerGroupCommand tool, we can list, describe, or delete consumer groups. Note that deletion is only available when the group metadata is stored in ZooKeeper. When using the new consumer API (where the broker handles coordination of partition handling and rebalance), the group is deleted when the last committed offset for that group expires. For example, to list all consumer groups across all topics:
用ConsumerGroupCommand工具,我们可以使用list,describe,或delete消费者组(注意,删除只有在分组元数据存储在zookeeper的才可用)。当使用新消费者API(broker协调处理分区和重新平衡),当该组的最后一个提交的偏移到期时,该组被删除。 例如,要列出所有主题中的所有用户组:
> bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --list  test-consumer-group

 

 

To view offsets as in the previous example with the ConsumerOffsetChecker, we "describe" the consumer group like this:

要使用ConsumerOffsetChecker查看上一个示例中消费者组的偏移量,我们按如下所示“describe”消费者组:

> bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 --describe --group test-consumer-group  GROUP                          TOPIC                          PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             OWNER  test-consumer-group            test-foo                       0          1               3               2               consumer-1_/127.0.0.1

 

 

If you are using the old high-level consumer and storing the group metadata in ZooKeeper (i.e. offsets.storage=zookeeper), pass --zookeeper instead of bootstrap-server:
如果你使用老的高级消费者并存储分组元数据在zookeeper(即。offsets.storage=zookeeper)通过--zookeeper,而不是bootstrap-server:
> bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --list ./kafka-consumer-offset-checker.sh 这个命令也是过时的

作者:半兽人

链接:http://orchome.com/454
来源:OrcHome
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

PS:学了kafka0.8 和kafka0.10 结果用新版的时候把命令搞混了

你可能感兴趣的文章
android组件通讯 Intent-Action属性
查看>>
C++ Builder 初学问与答 (九)
查看>>
关闭linux的SElinux的方法
查看>>
【Hibernate框架开发之五】Hibernate对象的三种状态&Session常用方法
查看>>
LINUX ROUTE配置小记
查看>>
如何在 Shell 脚本中执行语法检查调试模式
查看>>
SCVMM2012R2 服务模版系列(四)创建一个开箱即用的Web应用程序服务模版
查看>>
Visual Studio 2010 Ultimate敏捷功能特性(下)
查看>>
为 Neutron 准备物理基础设施(I) - 每天5分钟玩转 OpenStack(75)
查看>>
Android 中文API (91) —— GestureDetector
查看>>
CSS对字体单位的总结
查看>>
统计函数——汇总统计时间类数据
查看>>
精进不休 .NET 4.0 (6) - ADO.NET Data Services 1.5 新特性
查看>>
android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V...
查看>>
熄灯问题
查看>>
引用类型参数,ref按引用传值
查看>>
基于Widnows Server 2003 SP2的系统需要新的系统准备工具
查看>>
C++ 制作 json 数据 并 传送给服务端(Server) 的 php
查看>>
如何从VS2003升级到VS2008
查看>>
Kernel内核的裁剪及移植(三)
查看>>