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
重要參數:
- log.retention.check.interval.ms:日志保留檢查頻率
- log.cleaner.threads:清理線程數
- num.io.threads:I/O 線程數
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