在 Debian 系统上创建 Kafka 主题(topic),前提是你已经安装并启动了 Kafka(以及 ZooKeeper 或 KRaft)。下面按常见场景给你说明。
确保以下服务已启动:
# 启动 ZooKeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
# 启动 Kafka
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/kraft/server.properties
cd /opt/kafka # 或你的安装路径
bin/kafka-topics.sh \
--create \
--zookeeper localhost:2181 \
--topic test-topic \
--partitions 3 \
--replication-factor 1
说明:
test-topic:主题名partitions 3:分区数replication-factor 1:副本数(单机只能为 1)bin/kafka-topics.sh \
--create \
--bootstrap-server localhost:9092 \
--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 --delete --topic test-topic --bootstrap-server localhost:9092
replication factor larger than available brokers原因:副本数 > 当前 broker 数量
解决:
--replication-factor 1
JAVA解决:
sudo apt install default-jdk
java -version
如果你是用 apt 或手动安装,可以告诉我,我可以帮你写:
kafka.servicezookeeper.service如果你是指:
可以告诉我,我给你对应示例。