kafka常用命令--太常用了

##################################################

       常用的差不多就这些,我是现记录

##################################################

1、topic列表

[root@t1-25-19 bin]# ./kafka-topics.sh --list --zookeeper localhost:2181/kfk_mq
__consumer_offsets
bd_frs
crs_events

2、创建topic

[root@t1-25-19 bin]# ./kafka-topics.sh --create --zookeeper localhost:2181/kfk_mq --replication-factor 3 --partitions 3 --topic demo
Created topic "demo".

3、修改topic

[root@t1-25-19 bin]# ./kafka-topics.sh --alter --topic demo --zookeeper localhost:2181/kfk_mq --partitions 4
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!

4、删除topic

[root@t1-25-19 bin]# ./kafka-topics.sh --delete --zookeeper localhost:2181/kfk_mq --topic demo
Topic demo is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.

5、查看topic信息

[root@t1-25-19 bin]# ./kafka-topics.sh --zookeeper localhost:2181/kfk_mq --describe --topic demo
Topic:demo	PartitionCount:3	ReplicationFactor:3	Configs:
	Topic: demo	Partition: 0	Leader: 1002	Replicas: 1002,1001,1003	Isr: 1002,1001,1003
	Topic: demo	Partition: 1	Leader: 1003	Replicas: 1003,1002,1001	Isr: 1003,1002,1001
	Topic: demo	Partition: 2	Leader: 1001	Replicas: 1001,1003,1002	Isr: 1001,1003,1002

5、消费topic

[root@t1-25-19 bin]# ./kafka-console-consumer.sh  --zookeeper localhost:2181/kfk_mq  --topic demo --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
{metadata.broker.list=t1-25-19.bigdata:6667,t1-25-21.bigdata:6667,t1-25-20.bigdata:6667, request.timeout.ms=30000, client.id=console-consumer-25274, security.protocol=PLAINTEXT}

6、生产消息

    123是输入内容,此时打开消费就能收到消息了

[root@t1-25-19 bin]# ./kafka-console-producer.sh --broker-list t1-25-19.bigdata:6667 --topic demo
123

7、消费指定偏移量消息

./kafka-console-consumer.sh  --bootstrap-server 172.16.2.63:6667  --topic test --partition 0 --offset 2654 --max-messages 1 --property  print.timestamp=true
  • offset偏移量
  • max-message展示的最大数据

8、查询当前topic某分区中数据的偏移量信息

./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 172.16.2.63:6667 --topic crs_events --time -1 --partitions 0

注: time为-1时表示最大值,time为-2时表示最小值

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛小布

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值