经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » Apache Kafka » 查看文章
Kafka运维命令大全
来源:cnblogs  作者:独孤风  时间:2019/9/16 10:43:29  对本文有异议

1、集群管理

前台启动broker

  1. bin/kafka-server-start.sh <path>/server.properties

Ctrl + C 关闭

后台启动broker

  1. bin/kafka-server-start.sh -daemon <path>/server.properties

关闭broker

  1. bin/kafka-server-stop.sh

2、Topic管理

创建topic

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

删除topic

  1. bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic topicname

查询topic列表

  1. bin/kafka-topics.sh --zookeeper localhost:2181 --list

查询topic详情

  1. bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic topicname

修改topic

  1. bin/kafka-topics.sh --alter --zookeeper localhost:2181 --partitions 6 --topic topicname

3、Consumer-Groups管理

查询消费者组

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

查询消费者组详情

  1. bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group groupname

重设消费者组位移

  1. 最早处
  2. bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-earliest --execute
  3. 最新处
  4. bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-latest --execute
  5. 某个位置
  6. bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-offset 2000 --execute
  7. 调整到某个时间之后得最早位移
  8. bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group groupname --reset-offsets --all-topics --to-datetime 2019-09-15T00:00:00.000

删除消费者组

  1. bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --delete --group groupname

4、脚本工具

producer脚本

  1. bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topicname
  2. 参数含义:
  3. --compression-codec lz4 压缩类型
  4. --request-required-acks all acks的值
  5. --timeout 3000 linger.ms的值
  6. --message-send-max-retries 10 retries的值
  7. --max-partition-memory-bytes batch.size

consumer脚本

  1. bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
  2. 指定groupid
  3. bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
  4. --consumer-property group.id=old-consumer-group
  5. 指定分区
  6. bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicname --from-beginning
  7. --partition 0

kafka-run-class脚本

  1. kafka-run-class.sh kafka.tools.ConsoleConsumer 就是 kafka-console-consumer.sh
  2. kafka-run-class.sh kafka.tools.ConsoleProducer 就是 kafka-console-producer.sh

获取topic当前消息数

  1. kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic topicname --time -1

--time -1表示最大位移 --time -2表示最早位移

查询_consumer_offsets

  1. bin/kafka-simple-consumer-shell.sh --topic _consumer_offsets --partition 12 --broker-list localhost:9092 --formatter "kafka.coorfinator.GroupMetadataManager\$OffsetsMessageFormatter"

5、MirrorMaker

跨机房灾备工具

  1. bin/kafka-mirror-maker.sh --consumer.config consumer.properties --producer.config producer.properties --whitelist topicA|topicB

更多实时计算,Flink,Kafka等相关技术博文,欢迎关注实时流式计算

file

原文链接:http://www.cnblogs.com/tree1123/p/11525610.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号