【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
相关推荐
starzy19907 小时前
KafkaProducer 加载元数据:一条 MetadataRequest 的完整旅程
大数据·kafka
PingCAP8 小时前
善战者无赫赫之功:消费金融核心系统的数据库选型与升级路径
数据库·分布式·架构
库库的数据库笔记9 小时前
金融核心交易系统的数据库国产信创改造该如何做?
大数据·数据库·分布式·mysql·oracle·金融·数据库架构
RobinXYuan13 小时前
【Kafka 源码手记】04 客户端如何找到 Broker
kafka·源码阅读
爱吃火鸡面呀15 小时前
深入理解 Spark RDD:五大特性与实战解析
大数据·分布式·spark
Linux实战笔记16 小时前
记一次消息队列选型对比线上排查:Kafka/RabbitMQ/Pulsar 技术选型
kafka·rabbitmq·高并发·pulsar·消息队列选型
Norris Huang17 小时前
Kafka Connect 与 Flink CDC 写入 Iceberg:Upsert 的代价,以及 S3 Tables 的真正价值
分布式·flink·kafka
张彦峰ZYF17 小时前
一条消息的丢与重:Kafka 与 RabbitMQ 可靠投递的确认、位点、死信与幂等全链路
后端·kafka·消息队列·rabbitmq·isr·解耦与削峰·丢失与重复
我就是不信17 小时前
集群高并发环境下如何保证分布式唯一全局ID生成?
分布式
黄俊懿2 天前
【架构师从入门到进阶】第六章:服务集群优化——第八节:线程数公式
java·服务器·数据库·分布式·性能优化·架构·系统架构