参考链接:https://blog.csdn.net/weixin_39984161/article/details/91971731
kafka
下载地址:
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.6.0/kafka_2.12-2.6.0.tgz
ZooKeeper
下载地址:
https://downloads.apache.org/zookeeper/zookeeper-3.5.8/
启动关闭脚本:
zookeeper
#!/bin/bash
case $1 in
start)
nohup /opt/kafka_2.11-2.1.0/bin/zookeeper-server-start.sh /opt/kafka_2.11-2.1.0/config/zookeeper.properties > zookeeper.out &
;;
stop)
/opt/kafka_2.11-2.1.0/bin/zookeeper-server-stop.sh
;;
*)
echo "Please view this script"
;;
esac
kafka
#!/bin/bash
case $1 in
start)
nohup /opt/kafka_2.11-2.1.0/bin/kafka-server-start.sh /opt/kafka_2.11-2.1.0/config/server.properties > kafka.out &
;;
stop)
/opt/kafka_2.11-2.1.0/bin/kafka-server-stop.sh /opt/kafka_2.11-2.1.0/config/server.properties
;;
*)
echo "Please view this script"
;;
esac
查看主题
kafka-topics —list —zookeeper ip:2181
生产和消费测试
创建一个 topic
./kafka-topics.sh —create —zookeeper localhost:2181 —replication-factor 1 —partitions 1 —topic hellotest
删除 topic
./kafka-topics.sh —delete —zookeeper localhost:2181 —topic hellotest
测试生产和消费
生产者:
/opt/kafka_2.11-2.1.0/bin/kafka-console-producer.sh —broker-list localhost:9092 —topic test
消费者:
/opt/kafka_2.11-2.1.0/bin/kafka-console-consumer.sh —bootstrap-server localhost:9092 —topic test —from-beginning