1、下载zookeeper
下载地址: http://zookeeper.apache.org/releases.html#download
2、解压zookeeper 进入conf目录 apache-zookeeper-3.9.3-bin\conf 复制"zoo_sample.cfg”文件并重命名为“zoo.cfg”
3、apache-zookeeper-3.9.3-bin目录下新建data文件和log文件
4、在zoo.cfg文件中新增dataDir和dataLogDir两个参数,标红部分为文件路径
dataDir=/persistent/home/volador/software/kafka/apache-zookeeper-3.9.3-bin/data
dataLogDir=/persistent/home/volador/software/kafka/apache-zookeeper-3.9.3-bin/log
5、启动zookeeper
进入apache-zookeeper-3.9.3-bin/bin目录下执行
./zkServer.sh start
注:Zookeeper在Linux系统上的启动命令为./zkServer.sh start,停止命令为./zkServer.sh stop,状态查看命令为./zkServer.sh status
6、下载kafka
下载地址:http://kafka.apache.org/downloads
7、解压kafka,进入kafka_2.12-3.9.0/config目录
打开server.properties编辑以下参数,标红部分为文件路径
log.dirs=/persistent/home/volador/software/kafka/kafka_2.12-3.9.0/kafka-logs
标红部分为机器IP地址
listeners=PLAINTEXT://192.168.31.42:9092
8、启动kafka
nohup bin/kafka-server-start.sh config/server.properties &
9、 新建topic
./kafka-topics.sh --create --bootstrap-server 192.168.31.42:9092 --replication-factor 1 --partitions 1 --topic kafka-test
10、查看topic
./kafka-topics.sh --list --bootstrap-server 192.168.31.42:9092
11、新建生产者,生产消息
./kafka-console-producer.sh --broker-list 192.168.31.42:9092 --topic kafka-test
12、新建消费者,消费消息
./kafka-console-consumer.sh --bootstrap-server 192.168.31.42:9092 --topic kafka-test --from-beginning