在 Debian 上测试 Kafka,通常分为 安装后基础功能测试、命令行测试 和 程序/压力测试 几种方式。下面给你一套从零到可用的完整测试思路(基于 Debian 11/12,Kafka 3.x)。
Kafka 依赖 JVM:
sudo apt update
sudo apt install -y openjdk-17-jdk
java -version
wget https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
tar -xzf kafka_2.13-3.7.0.tgz
cd kafka_2.13-3.7.0
Kafka 3.x 推荐 KRaft,但测试可用 ZK:
bin/zookeeper-server-start.sh config/zookeeper.properties
新开终端:
bin/kafka-server-start.sh config/server.properties
✅ Kafka 默认监听:
localhost:9092bin/kafka-topics.sh \
--create \
--topic test-topic \
--bootstrap-server localhost:9092 \
--partitions 1 \
--replication-factor 1
查看 Topic:
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
bin/kafka-console-producer.sh \
--topic test-topic \
--bootstrap-server localhost:9092
输入:
hello kafka
debian test
另开终端:
bin/kafka-console-consumer.sh \
--topic test-topic \
--bootstrap-server localhost:9092 \
--from-beginning
✅ 能看到消息说明 Kafka 正常工作。
bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--describe \
--group test-group
生产者压测:
bin/kafka-producer-perf-test.sh \
--topic test-topic \
--num-records 100000 \
--record-size 1024 \
--throughput -1 \
--producer-props bootstrap.servers=localhost:9092
消费者压测:
bin/kafka-consumer-perf-test.sh \
--topic test-topic \
--bootstrap-server localhost:9092 \
--messages 100000
pip install kafka-python
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
producer.send('test-topic', b'hello from python')
producer.flush()
listeners 配置sudo ufw allow 9092
看日志:
tail -f logs/server.log
✅ 启动 Kafka
✅ 创建 Topic
✅ 生产消息
✅ 消费消息
✅ 性能/程序测试
如果你是 Debian + Docker / systemd / KRaft 模式,可以告诉我,我可以给你对应方案。