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中文网其他相关文章!