You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kafka Broker磁盘已满,如何从集群移除该Broker并重置其存储?

处理存储已满的Kafka Broker(移除、清理并重置)

1. 迁移目标Broker上的所有分区副本

首先必须将该Broker承载的所有分区副本迁移至其他可用Broker,避免数据丢失或分区不可用:

  • 生成迁移计划:
    创建topics.json文件,列出所有包含目标Broker副本的主题:
    {"topics": [{"topic": "user_topic"}, {"topic": "order_topic"}], "version": 1}
    
    执行命令生成迁移计划:
    kafka-reassign-partitions.sh --bootstrap-server kafka-broker-1:9092 --topics-to-move-json-file topics.json --broker-list "2,3" --generate
    
    (替换kafka-broker-1:9092为集群任意可用Broker地址,"2,3"为其他可用Broker的ID列表)
  • 执行迁移:
    将生成的迁移计划保存到reassign-plan.json,执行迁移:
    kafka-reassign-partitions.sh --bootstrap-server kafka-broker-1:9092 --reassignment-json-file reassign-plan.json --execute
    
  • 验证迁移完成:
    kafka-reassign-partitions.sh --bootstrap-server kafka-broker-1:9092 --reassignment-json-file reassign-plan.json --verify
    
    等待所有分区返回Successfully reassigned partitions即可。

2. 安全停止目标Broker

迁移完成后,停止目标Broker进程,避免数据不一致:

  • Linux环境:
    kafka-server-stop.sh
    
  • Windows环境:
    运行kafka-server-stop.bat或通过服务管理器停止Kafka服务。

3. 从集群元数据中移除目标Broker ID

确保Broker已停止后,清理集群中的Broker注册信息:

  • 若使用ZooKeeper管理集群:
    进入ZooKeeper客户端:
    zkCli.sh
    
    删除目标Broker的节点:
    deleteall /brokers/ids/<目标Broker ID>
    
  • 若使用KRaft模式:
    运行元数据shell工具移除Broker ID:
    kafka-metadata-shell.sh --snapshot <元数据快照路径>
    
    在shell中执行删除命令:
    delete /brokers/ids/<目标Broker ID>
    

4. 清理本地存储并重置Broker

  • 删除本地所有Kafka数据:
    找到server.properties中配置的log.dirs路径,执行清理:
    rm -rf /path/to/kafka/logs/*
    
  • 重置Broker(若需重新加入集群):
    修改server.properties中的broker.id为未使用的新ID,或开启broker.id.generation.enable=true让集群自动分配ID;同时确保listeners等配置符合集群要求。
  • 若无需复用该Broker,可直接卸载Kafka或清理相关运行环境。

内容的提问来源于stack exchange,提问作者user2138149

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:32:40