当前位置: 首页 > news >正文

Kafka日常运维命令总结

一、集群管理
  1. 前台启动Broker

    bin/kafka-server-start.sh <path>/server.properties
    
    • 关闭方式:Ctrl + C
  2. 后台启动Broker

    bin/kafka-server-start.sh -daemon <path>/server.properties
    
  3. 关闭Broker

    bin/kafka-server-stop.sh
    

二、Topic管理
操作命令
创建Topicbin/kafka-topics.sh --create --bootstrap-server localhost:9092 --partitions 3 --replication-factor 3 --topic <topicname>
删除Topicbin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic <topicname>
查询Topic列表bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
查询Topic详情bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topicname>
增加分区数bin/kafka-topics.sh --alter --bootstrap-server localhost:9092 --partitions 6 --topic <topicname>

注意:新版本推荐使用--bootstrap-server替代--zookeeper


三、Consumer Groups管理
操作命令
查询消费组列表bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
查询消费组详情bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group <groupname>
删除消费组bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group <groupname>
  1. 重设消费位移
    # 重置到最早位移
    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group <groupname> --reset-offsets --to-earliest --execute# 重置到最新位移
    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group <groupname> --reset-offsets --to-latest --execute# 重置到指定位移
    bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group <groupname> --reset-offsets --to-offset 2000 --execute
    

四、常用运维工具
  1. 生产者控制台

    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic <topicname>
    
    • 高级参数:
      --compression-codec lz4(压缩)
      --request-required-acks all(ACK机制)
      --message-send-max-retries 10(重试次数)
  2. 消费者控制台

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <topicname> --group <groupname> --from-beginning
    
  3. 性能测试工具

    # 生产者性能测试
    bin/kafka-producer-perf-test.sh --topic <topic> --num-records 1000000 --record-size 1000# 消费者性能测试
    bin/kafka-consumer-perf-test.sh --topic <topic> --messages 1000000
    
  4. 获取Topic消息数

    # 最新位移(总消息数)
    bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic <topic> --time -1# 最早位移
    bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic <topic> --time -2
    

五、分区管理
  1. Preferred Leader选举

    bin/kafka-leader-election.sh --bootstrap-server localhost:9092 --election-type preferred --topic <topic> --partition 0
    
  2. 分区重分配

    # 生成迁移计划
    bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --generate --topics-to-move-json-file plan.json# 执行迁移
    bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --execute --reassignment-json-file reassign.json# 验证进度
    bin/kafka-reassign-partitions.sh --bootstrap-server localhost:9092 --verify --reassignment-json-file reassign.json
    

六、高级运维
  1. 查看日志段元数据

    bin/kafka-dump-log.sh --files 000000000000.log --print-data-log
    
  2. 跨集群复制(MirrorMaker)

    bin/kafka-mirror-maker.sh --consumer.config consumer.conf --producer.config producer.conf --whitelist ".*"
    
  3. 查看__consumer_offsets

    bin/kafka-console-consumer.sh --topic __consumer_offsets --formatter "kafka.coordinator.group.GroupMetadataManager\$OffsetsMessageFormatter"
    

关键注意事项:

  1. 版本兼容性

    • ≥ Kafka 2.2.x 推荐使用 --bootstrap-server 替代 --zookeeper
    • 删除Topic需确保 delete.topic.enable=true
  2. 生产环境建议

    • 分区重分配避免高峰时段操作
    • 重设位移前先停止消费者组
    • MirrorMaker需监控复制延迟
  3. 常用诊断技巧

    # 检查消息积压(Lag)
    bin/kafka-consumer-groups.sh --describe --group <group> | awk '{print $6}'# 检查Controller状态
    bin/kafka-metadata-quorum.sh --status
    

完整文档参考:Apache Kafka Operations

http://www.lryc.cn/news/578547.html

相关文章:

  • 数据的表示
  • 基于 Vue + RuoYi 架构设计的商城Web/小程序实训课程
  • 苹果AR/VR头显路线图曝光,微美全息推进AI/AR智能眼镜新品开启视觉体验篇章
  • 61、【OS】【Nuttx】【构建】向量表
  • 每日一练:找到初始输入字符串 I
  • 新版本 Spring Data Jpa + QueryDSL 使用教程
  • Zephyr RTOS 信号量 (Semaphore)
  • GitHub已破4.5w star,从“零样本”到“少样本”TTS,5秒克隆声音,冲击传统录音棚!
  • MySQL 8.4 备份与恢复完全指南
  • JVM调优实战 Day 14 :大数据处理中的JVM调优
  • 文心一言开源版测评:能力、易用性与价值的全面解析
  • 磁盘的访问算法有哪些?
  • HTTPS安全传输时采用的顶级阳谋
  • [密码学实战]国密TLCP协议报文解析代码实现(三十)
  • [C#] WPF - 自定义样式(Slider篇)
  • 腾讯 iOA 零信任产品:安全远程访问的革新者
  • 数据结构day4——栈
  • 回转体水下航行器简单运动控制的奥秘:PID 控制和水动力方程的运用
  • 信息安全相关算法
  • 蓝牙音频传输协议深度解析:A2DP、HFP、AVRCP 对比与面试核心考点
  • 【机器学习2】正则化regularizaiton(降低模型过拟合)
  • 【cv视觉】标注工具的使用和数据集的创建
  • 2.SQL语句执行慢,如何分析
  • 07CSRF 漏洞保护
  • 事件监听器 + 回调处理器的事件循环系统
  • OpenCV CUDA模块设备层-----二值化阈值操作函数thresh_binary_func()
  • 设计模式精讲 Day 21:策略模式(Strategy Pattern)
  • 【STM32】 STM32低功耗模式详解:睡眠模式与唤醒机制【待测试】
  • 单元测试详解
  • 记录一个 Linux中脚本无法执行的问题