• Kafka: Windows环境-单机部署和伪集群、集群部署


    1. kafka 单机版部署

    1.1 zookeeper 安装

    (1)下载安装包

    官网:Apache ZooKeeper

    我用的是 apache-zookeeper-3.7.1-bin.tar.gz

    注意:zookeeper的安装路径不要有中文,建议也不要有空格,比如Program Files这样的路径

    下载完成后,解压到本地无中文路径名的目录下,比如: D:/kafka

    (2)修改配置文件

    在zookeeper的conf目录下复制一份zoo_sample.cfg文件,并重命名为zoo.cfg:

    修改zoo.cfg文件里面的路径(data,logs为新建目录)

    1. # 存放内存数据库快照的目录
    2. dataDir=D:/kafka/zookeeper/stand-alone/zookeeper/data
    3. # 存放事务日志目录
    4. dataLogDir=D:/kafka/zookeeper/stand-alone/zookeeper/logs
    5. # AdminServer端口
    6. admin.serverPort=7070
    7. # clientport端口
    8. clientPort=2181

    重点避坑:在windows环境中,文件路径必须是 "\" 或者 "//" ,“/” 是无法识别的。 zookeeper服务启动时会启动一个AdminServer的服务,端口会占用8080,如果你有启动别的项目占了8080端口就会报错无法启动。所以在这添加配置 admin.serverPort=7070 来将启动端口修改(7070随便填的,不冲突就行)。单机集群,必须每个节点的admin.serverPort都不同。

    (3)参数说明:

    参数说明:
     
    tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
     
    initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒
     
    syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒
     
    dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
     
    clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。

    (4)创建data 、logs目录

    (5)启动服务

    进入bin目录下,进入bin目录下,双击zkServer.cmd

     如果出现闪退,检查jdk的环境变量是否安装正确.路径中不要有中文。

    (6)验证是否安装成功

    在bin目录下双击zkCli.cmd,打开客户端(此时的服务端zkServer的dos窗口不要关闭),出现"欢迎"字样,说明安装成功!

    1.2 kafka 安装

    (1)下载安装包

    kafka官网下载安装包,并解压。我使用的是kafka_2.13-2.8.0.tgz。解压到本地目录下,这里是:D:\kafka。

    (2)修改配置文件

    kafka需要修改server.propertiespei文件的参数:

    1. #节点id,单机用默认的0,集群每个节点都不一样
    2. broker.id=0
    3. #日志文件路径
    4. log.dirs=D:/kafka/kafka/stand-alone/kafka/kafka-logs
    5. #kafka运行端口,默认9092,单机可以不配置
    6. #listeners=PLAINTEXT://:9092
    7. #表示本地运行(默认的可以不改)
    8. zookeeper.connect=localhost:2181

    (3)启动kafka服务器

    进入Kafka安装目录,新建cmd窗口:

    cd D:\kafka\kafka\stand-alone\kafka

    输入命令

    .\bin\windows\kafka-server-start.bat .\config\server.properties

    或者填写绝对路径

    D:\kafka\kafka\stand-alone\kafka\bin\windows\kafka-server-start.bat D:\kafka\kafka\stand-alone\kafka\config\server.properties

    注意:不要关了这个窗口,启用Kafka前请确保ZooKeeper实例已经准备好并开始运行

    1.3 测试

    (1)创建主题

    新建cmd窗口,进入kafka的windows目录下

    cd D:\kafka\kafka\stand-alone\kafka\bin\windows

    输入以下命令,创建一个叫topic001的主题

    .\kafka-topics.bat --create --topic test1 --bootstrap-server 127.0.0.1:9092

    (2)查看状态

     .\kafka-topics.bat --describe --topic test1 --bootstrap-server 127.0.0.1:9092

     (3)停止kafka

    .\kafka-server-stop.bat

    2. kafka伪集群

    2.1 zookeeper集群搭建

    (1)创建多节点配置

    在单节点的基础上,复制一份,zookeeper集群最少三个节点。三个节点的端口不能相同,分别使用2181、2182、2183。

    创建三个节点用的配置文件 zoo.cfg复制多份,分别命名为 zoo-1.cfg、zoo-2.cfg、zoo-3.cfg。

    (2)创建多节点的data目录和myid文件、logs目录

    data2181、data2182、data2183的myid分别为1、2、3。

    (3)三个节点的配置内容:

    zoo-1.cfg

    1. # The number of milliseconds of each tick
    2. tickTime=2000
    3. # The number of ticks that the initial
    4. # synchronization phase can take
    5. initLimit=10
    6. # The number of ticks that can pass between
    7. # sending a request and getting an acknowledgement
    8. syncLimit=5
    9. # the directory where the snapshot is stored.
    10. # do not use /tmp for storage, /tmp here is just
    11. # example sakes.
    12. dataDir=D:/kafka/zookeeper/colony/zookeeper/data2181
    13. dataLogDir=D:/kafka/zookeeper/colony/zookeeper/logs1
    14. # the port at which the clients will connect
    15. clientPort=2181
    16. # the maximum number of client connections.
    17. # increase this if you need to handle more clients
    18. #maxClientCnxns=60
    19. admin.serverPort=8080
    20. #
    21. # Be sure to read the maintenance section of the
    22. # administrator guide before turning on autopurge.
    23. #
    24. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    25. #
    26. # The number of snapshots to retain in dataDir
    27. #autopurge.snapRetainCount=3
    28. # Purge task interval in hours
    29. # Set to "0" to disable auto purge feature
    30. #autopurge.purgeInterval=1
    31. # 集群配置
    32. server.1=127.0.0.1:2888:3888
    33. server.2=127.0.0.1:2889:3889
    34. server.3=127.0.0.1:2890:3890
    35. ## Metrics Providers
    36. #
    37. # https://prometheus.io Metrics Exporter
    38. #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
    39. #metricsProvider.httpPort=7000
    40. #metricsProvider.exportJvmInfo=true

     zoo-2.cfg

    1. # The number of milliseconds of each tick
    2. tickTime=2000
    3. # The number of ticks that the initial
    4. # synchronization phase can take
    5. initLimit=10
    6. # The number of ticks that can pass between
    7. # sending a request and getting an acknowledgement
    8. syncLimit=5
    9. # the directory where the snapshot is stored.
    10. # do not use /tmp for storage, /tmp here is just
    11. # example sakes.
    12. dataDir=D:/kafka/zookeeper/colony/zookeeper/data2182
    13. dataLogDir=D:/kafka/zookeeper/colony/zookeeper/logs2
    14. # the port at which the clients will connect
    15. clientPort=2182
    16. # the maximum number of client connections.
    17. # increase this if you need to handle more clients
    18. #maxClientCnxns=60
    19. admin.serverPort=8081
    20. #
    21. # Be sure to read the maintenance section of the
    22. # administrator guide before turning on autopurge.
    23. #
    24. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    25. #
    26. # The number of snapshots to retain in dataDir
    27. #autopurge.snapRetainCount=3
    28. # Purge task interval in ho
  • 相关阅读:
    向上向下走(递归回溯)
    【云原生】阿里云 RocketMQ介绍
    D. 2+ doors
    【算法萌新闯力扣】:旋转字符串
    Web自动化测试:测试用例断言!
    ATFX汇市:亚特兰大联储主席博斯蒂克表示,“美联储应该停止加息!”
    深度学习之 8 深度模型优化与正则化
    【人工智能与深度学习】解码语言模型
    解决VMware虚拟机更新17.5.0版本后,启动虚拟机导致电脑重启的问题。(建议收藏)
    01、RabbitMQ入门
  • 原文地址:https://blog.csdn.net/weixin_42405670/article/details/128111808