在 Debian(或任意 Linux)上运行的 Kafka,扩分区(增加 topic 的分区数)操作本身是 Kafka 层面的操作,和 Debian 系统关系不大。下面按常见场景一步步说明。
systemctl status kafka
# 或
ps -ef | grep kafka
localhost:9092
kafka-topics.sh --bootstrap-server localhost:9092 --list
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--describe \
--topic your_topic_name
示例输出:
Topic: your_topic_name PartitionCount: 3 ReplicationFactor: 1
--alter 增加分区kafka-topics.sh \
--bootstrap-server localhost:9092 \
--alter \
--topic your_topic_name \
--partitions 6
⚠️ Kafka 只能增加分区,不能减少分区
kafka-topics.sh \
--bootstrap-server localhost:9092 \
--describe \
--topic your_topic_name
看到 PartitionCount: 6 即成功。
key 做 hash 路由如果希望 已有数据也均衡:
kafka-reassign-partitions.sh示例(仅思路):
kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092 \
--generate \
--topics-to-move-json-file topics.json \
--broker-list 0,1,2
⚠️ 生产环境务必谨慎,建议在低峰期操作。
| 项目 | 常见路径 |
|---|---|
| Kafka 安装 | /opt/kafka |
| 脚本 | /opt/kafka/bin |
| 配置 | /opt/kafka/config/server.properties |
如不在 PATH:
cd /opt/kafka/bin
./kafka-topics.sh ...
Debian 上 Kafka 扩分区 = 用
kafka-topics.sh --alter --partitions增加分区数,无需重启服务。
如果你愿意,可以告诉我:
我可以给你更精确的建议。