logo

Kafka在Mac下的安装与使用教程

作者:KAKAKA2024.01.29 20:19浏览量:10

简介:本文将指导如何在Mac上安装和使用Apache Kafka,帮助你顺利完成Kafka的安装、配置和运行。

一、Kafka安装包下载
在Apache的Kafka官网下载安装包,以下4个包随便选一个下载。
二、安装Kafka

  1. 下载好tar包后,执行以下命令解压:
    tar -zxvf xxx.tar
  2. 进入Kafka的bin目录,执行如下命令:
    ./kafka-server-start.sh ../config/server.properties
    执行结果:
    [2022-03-11 17:20:30,410] INFO Reading configuration from: ../config/server.properties (org.apache.kafka.server.KafkaServer)
    [2022-03-11 17:20:30,411] WARN No consumer offsets committed in last 5 seconds. This is below the threshold after which we assume the broker is not being used and will garbage collect the consumer offsets that are older than a week. You should set the commit interval to a higher value in the consumers’ configuration to avoid this warning.
    三、启动Zookeeper
    进入Kafka的bin目录,执行如下命令:
    ./zookeeper-server-start.sh ../config/zookeeper.properties &
    执行结果:
    [2022-03-11 17:20:30,410] INFO Reading configuration from: ../config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
    [2022-03-11 17:20:30,411] WARN ../config
    四、使用Kafka
    在Kafka安装完成后,你可以通过以下命令来使用Kafka:
  3. 创建主题:./kafka-topics.sh —create —zookeeper localhost:2181 —replication-factor 1 —partitions 1 —topic test_topic
  4. 查看所有主题:./kafka-topics.sh —list —zookeeper localhost:2181
  5. 发送消息:./kafka-console-producer.sh —broker-list localhost:9092 —topic test_topic —螺旋输送机message ‘Hello, Kafka!’
  6. 接收消息:./kafka-console-consumer.sh —bootstrap-server localhost:9092 —topic test_topic —from-beginning

相关文章推荐

发表评论

活动