1.安裝kakfka
1.從官網下載Kafka安裝包,解壓安裝,或直接使用命令下載。
wget https://archive.apache.org/dist/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz
2.解壓
tar -xzvf kafka_2.11-0.11.0.0.tgz
2.修改配置文件
vim config/server.properties
broker.id=1
delete.topic.enable=true
log.dirs=/usr/local/kafka/logs
listeners=PLAINTEXT://localhost:9092
修改zookeeper.properties
dataDir路徑
修改zookeeper連接地址
3.啟動並測試
1.一定要先啟動zookeeper服務
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
-daemon 是阻塞進程
2.啟動單機kafka服務
bin/kafka-server-start.sh config/server.properties
3.創建topic進行測試
bin/kafka-topic.sh --create --zookeeper localhost:2128 --replication–factor 1 --partitions 1 --topic test
4.查看topic列表
bin/kafka-topic.sh --list --zookeeper localhost:9092 --topic test
輸出test
5.生產者消息測試
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
6.消費者消息測試
bin/kafka-console-consumer.sh --zookeeper localhost:2128 --toptic test --from-beginning