美文网首页工作生活
kafka 常用命令

kafka 常用命令

作者: shc_fighter | 来源:发表于2019-07-01 19:49 被阅读0次

启动zookeeper:
./zookeeper-server-start.sh -daemon ../config/zookeeper.properties
启动kafka server:
./kafka-server-start.sh -daemon ../config/server.properties


image.png

新建topic:
./kafka-topics.sh --create --topic topic_test --replication-factor 3 --partitions 3 --zookeeper localhost:2181


image.png

启动kafka server:
[图片上传中...(image.png-cb22c8-1563602345967-0)]

查询topic列表:
./kafka-topics.sh --list --zookeeper localhost:2181


image.png

查询topic信息:
./kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic_test


image.png

向topic生产数据:
./kafka-console-producer.sh --broker-list localhost:9092 --topic topic_test


image.png

消费topic数据:
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_test --from-beginning


image.png

增加topic分区数:
./kafka-topics.sh --zookeeper localhost:2181 --alter --topic topic_test --partitions 6


image.png

删除topic:
./kafka-topics.sh --delete --zookeeper 127.0.0.1:2181 --topic topic_test_1


image.png

注:如果server.properties中没有把delete.topic.enable设为true,那么此时的删除并不是真正的删除,而是把topic标记为:marked for deletion

查看消费offset情况:
./kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group test


image.png

展示的几个参数:
TOPIC: 该消费者组消费的是哪些topic, 本例是只创建了一个topic, test, 所以只消费了test。
PARTITION: 表示该消费者消费的是哪些分区, 本例创建topic时只有一个分区, 所以输出只有一行, 分区号为0。
CURRENT-OFFSET: 表示消费者组最新消费的位移值, 此值在消费过程中是变化的。
LOG-END-OFFSET: 表示topic所有分区当前的日志终端位移值, 因为我们生产了11185243万数据, 所以此处是11185243万。
LAG: 表示滞后进度, 此值为LOG-END-OFFSET 与 CURRENT-OFFSET的差值, 代表的是滞后情况, 此值越大表示滞后严重, 本例最终LAG为0 说明没有消费滞后。

相关文章

网友评论

    本文标题:kafka 常用命令

    本文链接:https://www.haomeiwen.com/subject/ckincctx.html