【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
相关推荐
物联网软硬件开发-轨物科技1 小时前
【轨物洞见】光伏逆变器数据:分布式电站价值回归的“第一块多米诺骨牌”
分布式
java叶新东老师2 小时前
四、搭建springCloudAlibaba2021.1版本分布式微服务-加入openFeign远程调用和sentinel流量控制
分布式·微服务·sentinel
java叶新东老师2 小时前
五、搭建springCloudAlibaba2021.1版本分布式微服务-gateway网关
分布式·微服务·gateway
黄雪超3 小时前
Kafka——消费者组消费进度监控都怎么实现?
大数据·分布式·kafka
java叶新东老师3 小时前
RabbitMq 常用命令和REST API
分布式·rabbitmq·ruby
liulilittle9 小时前
C++ TAP(基于任务的异步编程模式)
服务器·开发语言·网络·c++·分布式·任务·tap
码字的字节9 小时前
ZooKeeper在Hadoop中的协同应用:从NameNode选主到分布式锁实现
hadoop·分布式·zookeeper·分布式锁
武子康11 小时前
Java-80 深入浅出 RPC Dubbo 动态服务降级:从雪崩防护到配置中心秒级生效
java·分布式·后端·spring·微服务·rpc·dubbo
itLaity16 小时前
基于Kafka实现简单的延时队列
spring boot·分布式·kafka
qq_5298353516 小时前
Zookeeper的简单了解
分布式·zookeeper·云原生