【Kafka基础】监控与维护:动态配置管理,灵活调整集群行为

1 基础配置操作

1.1 修改主题保留时间

复制代码
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --alter \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type topics \
    --entity-name yourtopic \
    --add-config retention.ms=86400000

参数说明

  • retention.ms=86400000:设置消息保留时间为 1 天(单位毫秒)

1.2 删除主题配置项

复制代码
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --alter \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type topics \
    --entity-name yourtopic \
    --delete-config retention.ms

1 高级配置管理命令

2.1 批量修改多个主题配置

复制代码
for topic in topic1 topic2 topic3; do
    /export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --alter \
        --bootstrap-server 192.168.10.33:9092 \
        --entity-type topics \
        --entity-name $topic \
        --add-config retention.ms=172800000
done

2.2 查看所有被覆盖的配置

复制代码
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --describe \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type topics \
    | grep -v "Configs for topic" \
    | grep -v "^$"

2.3 动态调整broker配置

复制代码
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --alter \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type brokers \
    --entity-name 1 \
    --add-config log.retention.check.interval.ms=300000

重要参数

2.4 导出当前所有主题配置

复制代码
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --describe-all \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type topics \
    > kafka_topic_configs_backup_$(date +%Y%m%d).txt

3 配置管理黄金法则

3.1 优先级策略

  • 主题级配置 > 客户端配置 > broker 默认配置
  • 重要业务主题单独配置,普通主题使用默认值

3.2 变更控制

复制代码
# 变更前检查
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-configs.sh --describe \
    --bootstrap-server 192.168.10.33:9092 \
    --entity-type topics \
    --entity-name target-topic

# 变更后验证
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-topics.sh --describe \
    --bootstrap-server 192.168.10.33:9092 \
    --topic target-topic \
    --report-detailed

3.3 监控指标

复制代码
# 配置变更后监控以下指标
# 消息堆积变化
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-consumer-groups.sh --describe \
    --bootstrap-server 192.168.10.33:9092 \
    --group your-group

# 磁盘使用变化
/export/home/kafka_zk/kafka_2.13-2.7.1/bin/kafka-log-dirs.sh --describe \
    --bootstrap-server 192.168.10.33:9092 \
    --topic-list target-topic
相关推荐
极梦网络无忧6 小时前
小白机器人假想:分布式关节控制——机器人运动的未来模式?
分布式·机器人
Cloud Traveler10 小时前
【KWDB 创作者计划】KWDB 2.2.0多模融合架构与分布式时序引擎
数据库·分布式·架构
一大串羊肉串16 小时前
【从零开始学习RabbitMQ | 第一篇】从异步通信到交换机
分布式·学习·rabbitmq
电脑玩家粉色男孩1 天前
4、RabbitMQ的七种工作模式介绍
分布式·中间件·rabbitmq
浪前1 天前
【项目篇之统一内存操作】仿照RabbitMQ模拟实现消息队列
java·分布式·rabbitmq·ruby
努力也学不会java1 天前
【RabbitMQ】 RabbitMQ快速上手
分布式·后端·中间件·rabbitmq·ruby
不是谁只是我2 天前
VMware-centOS7安装redis分布式集群
数据库·redis·分布式
搞不懂语言的程序员2 天前
Kafka的Rebalance机制可能引发什么问题?如何优化?怎么减少不必要的Rebalance
分布式·kafka·linq
蒂法就是我2 天前
Kafka 的服务端的物理存储架构是什么?零拷贝,mmap,sendfile、DMA gather又是什么?
分布式·架构·kafka
计算机毕设定制辅导-无忧学长2 天前
ActiveMQ 与其他 MQ 的对比分析:Kafka/RocketMQ 的选型参考(一)
kafka·rocketmq·activemq