1. 官网下载jar包,解压即用
2. 进入解压包路径,开启zk和kafka,zk是来监管kafka的一些元数据和存储情况的
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
3.kafka消息是按照topic来收发的,所以,要先创建topic。topic可以有多个分区,每个分区的数据都可以制定其副本个数据,防止丢失恢复。这些在创建topic的时候,都需要制定。
bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1
2.1.查看topic
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
4.kafka的生产者和消费者的脚本,先开启消费者,然后从生产端输入数据,消费端可以实时接收到,命令中包含了topic的基本信息以及所在主机位置
bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic