Apache 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

转载于:https://my.oschina.net/u/437232/blog/3070312

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值