#1. 先決條件
2. 安裝Java
sudo apt-get update sudo apt-get install openjdk-8-jdk
3. 安裝Apache Kafka
wget https://dlcdn.apache.org/kafka/2.13/kafka_2.13-3.3.1.tgz tar -xvzf kafka_2.13-3.3.1.tgz
4. 安裝ZooKeeper
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz tar -xvzf zookeeper-3.4.14.tar.gz
5. 設定Kafka
cd kafka_2.13-3.3.1 cp config/server.properties config/server.properties.orig vim config/server.properties
修改以下設定:
broker.id=0 listeners=PLAINTEXT://localhost:9092 zookeeper.connect=localhost:2181
6. 設定ZooKeeper
cd zookeeper-3.4.14 cp conf/zoo.cfg conf/zoo.cfg.orig vim conf/zoo.cfg
修改以下設定:
dataDir=/tmp/zookeeper clientPort=2181
7. 啟動ZooKeeper
cd zookeeper-3.4.14 bin/zkServer.sh start
8. 啟動Kafka##
cd kafka_2.13-3.3.1 bin/kafka-server-start.sh config/server.properties
9. 建立Topic
bin/kafka-topics.sh --create --topic my-topic --partitions 1 --replication-factor 1
10. 傳送訊息
bin/kafka-console-producer.sh --topic my-topic --message "Hello, world!"
11. 消費訊息
bin/kafka-console-consumer.sh --topic my-topic --from-beginning
12. 停止Kafka
bin/kafka-server-stop.sh
#13. 停止ZooKeeper
bin/zkServer.sh stop
以上是分享Linux下安裝Kafka的詳細教學的詳細內容。更多資訊請關注PHP中文網其他相關文章!