【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
相关推荐
灯澜忆梦8 小时前
【RabbitMQ #3】 | Go 客户端 + SpringAMQP
分布式·golang·rabbitmq
Q264336502313 小时前
【有源码】基于Spark的电商客户细分与盈利洞察分析系统-面向精准营销的电商客户细分模型构建与盈利能力可视化研究
大数据·hadoop·分布式·数据挖掘·数据分析·spark·毕业设计
智码看视界13 小时前
技术选型指南:Pulsar vs Kafka:消息队列选型终极对比与压测
kafka·消息队列·pulsar·消息中间件·流处理·高吞吐·架构选型
新思维软件15 小时前
基于无线传输的地衡系统:三节点 LoRa 组网与 MQTT 上云的分布式称重方案
分布式·stm32·单片机·嵌入式硬件·物联网·物联网开发
俊哥大数据15 小时前
Flink1.20.3 实时消费 Kafka 数据并解析入湖 Paimon1.4.2 全流程实战
分布式·flink·kafka·数据湖·paimon
宸津-代码粉碎机21 小时前
OpenAI 连夜迎战 Grok Bot 和 Muse:AI 智能体从 “会聊天” 到 “能办事”,现在入场还来得及吗
java·大数据·人工智能·分布式·python
程序猿乐锅1 天前
【黑马点评 | 第八篇】Redisson分布式锁
java·数据库·spring boot·redis·分布式·spring·缓存
灯澜忆梦1 天前
【RabbitMQ #7】 | 消息转换器
分布式·rabbitmq·ruby
需要8261 天前
分布式事务:Seata AT/TCC/SAGA 的取舍与踩坑
java·spring boot·分布式·spring·spring cloud
CS创新实验室1 天前
为什么三台机器就能选出一个“带头大哥“?——Raft 一致性算法,一次讲透
分布式·操作系统