1.安裝jdk:
sudo apt-get install openjdk-8-jdk
2.獲取kafka安裝包:
wget http://mirror.bit.edu.cn/apache/kafka/2.3.1/kafka_2.11-2.3.1.tgz
3.解壓安裝包:
tar -zxvf kafka_2.11-2.3.1.tgz
4.重命名:
mv kafka_2.11-2.3.1 kafka
5.設置環境變量:
vim /etc/profile export KAFKA_HOME=/opt/kafka export PATH=$PATH:$KAFKA_HOME/bin
6.使環境變量生效:
source /etc/profile
7.先啟動ZooKeeper服務:
bin/zookeeper-server-start.sh config/zookeeper.properties
8.啟動kafka服務:
bin/kafka-server-start.sh config/server.properties
9.創建一個名為"topTest"的topic:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topTest
10.查看所包含的topic:
bin/kafka-topics.sh --list --zookeeper localhost:2181
11.打開Producer(生產者)服務
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topTest
12.打開Customer(消費者)服務
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topTest--from-beginning
展示結果: