【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
相关推荐
程序猿阿伟4 小时前
《解锁分布式软总线:构建智能设备统一管理平台》
分布式
程序猿阿伟4 小时前
《从底层逻辑剖析:分布式软总线与传统计算机硬件总线的深度对话》
分布式
工业甲酰苯胺4 小时前
zk基础—zk实现分布式功能
分布式
hi星尘6 小时前
深入理解Apache Kafka
分布式·kafka·apache
IT成长日记6 小时前
【Kafka基础】监控与维护:分区健康检查,确保数据高可用
分布式·kafka·健康检查·监控与维护
敏君宝爸9 小时前
kafka 配置SASL认证
分布式·kafka
斯普信云原生组9 小时前
kafka消费延迟
分布式·kafka
见未见过的风景9 小时前
使用 Redis + Redisson 分布式锁来生成全局唯一、线程安全的带日期前缀的流水号的完整实现。
数据库·redis·分布式
杰克逊的日记11 小时前
kafka的topic扩容分区会对topic任务有什么影响么
分布式·kafka
渲染101专业云渲染11 小时前
Lumion 与 Enscape 怎么选?附川翔云电脑适配指南
服务器·分布式·电脑·blender·houdini