9

本地运行 Kafka 与 Zookeeper

 3 years ago
source link: https://suiyia.github.io/2019/10/13/%E6%9C%AC%E5%9C%B0%E8%BF%90%E8%A1%8C-Kafka-%E4%B8%8E-Zookeeper/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本地运行 Kafka 与 Zookeeper

本地运行 kafka,运行生产消费实例。

Kafka 是一个分布式发布-订阅消息系统。
Zookeeper 是一个高性能分布式应用协调服务。
他们之间的关系 参考

  1. 安装 Zookeeper
  • 参考配置地址

  • 注意 环境变量 配置,配置文件重命名

  • 启动方式:Windows 平台直接点击 zkServer.cmd,Linux 平台 ./zkServer.sh start

  • Zookeeper 可视化(可选):安装 zk ui,先用 maven 打包,再修改配置文件,再启动

    #vim config.cfg
    serverPort=9090 #指定端口
    zkServer=localhost:2181
    sessionTimeout=300000

    java -jar target/zkui-2.0-SNAPSHOT-jar-with-dependencies.jar &
  1. 安装 Kafka
  • 下载地址,下载二进制文件,即 Binary downloads
  • config/server.properties 配置,参考
    listeners=PLAINTEXT://:9092
    advertised.listeners=PLAINTEXT://192.168.2.104:9092 # 对应 kafka 运行的机器的 ip 地址
    zookeeper.connect=localhost:2181

启动 Kafka,Windows 进入 C:\canal\kafka_2.11-2.0.1\bin\windows 目录下

kafka-server-start.bat ../../config/server.properties

新建 topic 为 testDemo 的 Producer,bin\windows 目录下,在该窗口输入任意字符

kafka-console-producer.bat --broker-list localhost:9092 --topic testDemo
> 123

新建 Consumer,接收 topic 为 testDemo 的消息,bin\windows 目录下

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic testDemo

查看这个 kafka 服务下所有的 topic

kafka-topics.bat --list --zookeeper 127.0.0.1:2181
  • consumer zookeeper is not a recognized option

    办法:版本问题,使用 –bootstrap-server 代替 –zookeeper-server


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK