在 Debian 下使用 Kafka 创建(设置)主题,通常是通过 Kafka 自带的命令行工具完成的。下面按常见场景给你说明。
/opt/kafka 或 /usr/local/kafka)# 启动 ZooKeeper(老版本需要)
bin/zookeeper-server-start.sh config/zookeeper.properties
# 启动 Kafka
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh \
--create \
--bootstrap-server localhost:9092 \
--topic test-topic \
--partitions 3 \
--replication-factor 1
说明:
--topic:主题名--partitions:分区数--replication-factor:副本数(不能大于 broker 数量)bin/kafka-topics.sh \
--create \
--zookeeper localhost:2181 \
--topic test-topic \
--partitions 3 \
--replication-factor 1
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
查看某个主题详情:
bin/kafka-topics.sh --describe --topic test-topic --bootstrap-server localhost:9092
⚠️ 副本数不能在线修改,只能增加分区
bin/kafka-topics.sh \
--alter \
--bootstrap-server localhost:9092 \
--topic test-topic \
--partitions 5
bin/kafka-topics.sh \
--delete \
--bootstrap-server localhost:9092 \
--topic test-topic
(需 delete.topic.enable=true)
如果是 apt 安装:
kafka-topics --create \
--bootstrap-server localhost:9092 \
--topic test-topic \
--partitions 3 \
--replication-factor 1
如果你告诉我:
我可以给你更精确的命令。