Mac 安装和使用Kafka (本地测试)

一、安装Kafka (当前版本为:3.3.1):

brew install kafka

kafka的安装目录:/usr/local/Cellar/kafka
kafka的配置文件目录:/usr/local/etc/kafka
kafka服务的配置文件:/usr/local/etc/kafka/server.properties
zookeeper配置文件: /usr/local/etc/kafka/zookeeper.properties

二、修改配置:

# /usr/local/etc/kafka/server.properties 中的重要配置
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://localhost:9092

三、启动zookeeper(新开终端):

cd /usr/local/Cellar/kafka/3.3.1_1/

./bin/zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties

四、启动kafka(新开终端):

cd /usr/local/Cellar/kafka/3.3.1_1/

./bin/kafka-server-start /usr/local/etc/kafka/server.properties

五、操作Topic:

cd /usr/local/Cellar/kafka/3.3.1_1/

#创建topic:

./bin/kafka-topics  --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test1

#查看topic:

./bin/kafka-topics --describe --bootstrap-server localhost:9092 --topic test1

六、启动生产者(新开终端):

cd /usr/local/Cellar/kafka/3.3.1_1/

./bin/kafka-console-producer --broker-list localhost:9092 --topic test1

七、启动消费者(新开终端):

cd /usr/local/Cellar/kafka/3.3.1_1/

./bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic test1 --from-beginning

终端截图: 

Mac 安装和使用Kafka (本地测试)_第1张图片

你可能感兴趣的:(kafka,macos)