温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Kafka有哪些常用命令

发布时间:2021-07-05 17:46:13 来源:亿速云 阅读:125 作者:chen 栏目:大数据

本篇内容主要讲解“Kafka有哪些常用命令”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Kafka有哪些常用命令”吧!

1、开启zookeeper(在安装目录下使用命令)

Linux:bin/zkServer.sh start

windows:bin\zkServer.cmd

2、启动kafka(安装目录下使用命令)

Linux:bin/kafka-server-start.sh start config/server.properties

windows:bin\windows\kafka-server-start.bat config\server.properties

3、查看topic名称列表

Linux:bin/kafka-topics.sh -list --zookeeper 172.16.0.99:2181,172.16.0.218:2181

windows:bin\windows\kafka-topics.bat -list --zookeeper 172.16.0.99:2181,172.16.0.218:2181

4、查看topic详情

Linux:bin/kafka-topics.sh -zookeeper localhost:2181 --topic test --describe

windows:bin\windows\kafka-topics.bat --zookeeper localhost:2181 --topic test --describe

5、删除topic

Linux:bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic "test"

windows:bin\windows\kafka-topics.bat --zookeeper localhost:2181 --delete --topic "test"

注意:集群中一台机器删除了topic,其他机器同步删除相同topic

6、创建topic

Linux:bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

windows:bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

注意:

replication-factor:副本个数,一般为小于等于Broker个数。

partitions:分区个数。如果副本个数为1,分区为4,则4个分区会均匀的分布在各个Broker上。如果Broker为2,副本为2,分区为4,则每个Broker上面都有4个分区。

7、创建Consumer

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

windows:bin\windows\kafka-console-consumer.bat --zookeeper localhost:2181 --topic test --form-beginning

注意:form beginning表示从头拉取。

8、创建Producer

Linux:bin/kafka-console-producer.sh --broker-list 172.16.0.99:9020,172.16.0.218:9020 --topic test

windows:bin\windows\kafka-console-producer.bat --broker-list 172.16.0.99:9092,172.16.0.218:9080 --topic test

注意:此处是kafka的端口,而且在集群里如果此处填localhost,会报一个连接错误,猜想应该是消息没有到达集群,因此此处将集群的ip都填上。

9、查询topic所有分区的offset值

Linux:bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 10.162.160.115:9092 --topic s1mmetest --time -1

10、查询kafka集群当前topic所有分区中的消息数目

Linux:bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 132.232.78.175:9092 --topic s1mmetest --time -2

参考:https://www.2cto.com/kf/201804/739331.html

到此,相信大家对“Kafka有哪些常用命令”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI