Linux Kafka配置后可按以下步骤测试:
基础功能测试
bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1bin/kafka-topics.sh --list --bootstrap-server localhost:9092echo "Hello Kafka" | bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092服务状态验证
jps(需看到Kafka进程)netstat -tulnp | grep 9092(确认9092端口被监听)性能测试(可选)
bin/kafka-producer-perf-test.sh --topic perf-test --num-records 1000000 --record-size 1024 --throughput 5000 --producer-props bootstrap.servers=localhost:9092bin/kafka-consumer-perf-test.sh --topic perf-test --messages 1000000 --bootstrap-server localhost:9092集群环境测试(若为集群部署)
bin/kafka-topics.sh --describe --topic test-topic --bootstrap-server <任意节点IP>:9092说明:若使用KRaft模式(无ZooKeeper),需将--zookeeper参数替换为--bootstrap-server。