参考链接: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

  1. #!/bin/bash
  2. case $1 in
  3. start)
  4. 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 &
  5. ;;
  6. stop)
  7. /opt/kafka_2.11-2.1.0/bin/zookeeper-server-stop.sh
  8. ;;
  9. *)
  10. echo "Please view this script"
  11. ;;
  12. esac

kafka

  1. #!/bin/bash
  2. case $1 in
  3. start)
  4. 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 &
  5. ;;
  6. stop)
  7. /opt/kafka_2.11-2.1.0/bin/kafka-server-stop.sh /opt/kafka_2.11-2.1.0/config/server.properties
  8. ;;
  9. *)
  10. echo "Please view this script"
  11. ;;
  12. 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