赞
踩
(1)下载安装包
我用的是 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为新建目录)
- # 存放内存数据库快照的目录
- dataDir=D:/kafka/zookeeper/stand-alone/zookeeper/data
- # 存放事务日志目录
- dataLogDir=D:/kafka/zookeeper/stand-alone/zookeeper/logs
- # AdminServer端口
- admin.serverPort=7070
- # clientport端口
- 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)下载安装包
在kafka官网下载安装包,并解压。我使用的是kafka_2.13-2.8.0.tgz。解压到本地目录下,这里是:D:\kafka。
(2)修改配置文件
kafka需要修改server.propertiespei文件的参数:
- #节点id,单机用默认的0,集群每个节点都不一样
- broker.id=0
- #日志文件路径
- log.dirs=D:/kafka/kafka/stand-alone/kafka/kafka-logs
- #kafka运行端口,默认9092,单机可以不配置
- #listeners=PLAINTEXT://:9092
- #表示本地运行(默认的可以不改)
- 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)创建主题
新建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
(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
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=D:/kafka/zookeeper/colony/zookeeper/data2181
-
- dataLogDir=D:/kafka/zookeeper/colony/zookeeper/logs1
- # the port at which the clients will connect
- clientPort=2181
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
-
- admin.serverPort=8080
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in hours
- # Set to "0" to disable auto purge feature
- #autopurge.purgeInterval=1
- # 集群配置
- server.1=127.0.0.1:2888:3888
- server.2=127.0.0.1:2889:3889
- server.3=127.0.0.1:2890:3890
-
- ## Metrics Providers
- #
- # https://prometheus.io Metrics Exporter
- #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
- #metricsProvider.httpPort=7000
- #metricsProvider.exportJvmInfo=true
-

zoo-2.cfg
- # The number of milliseconds of each tick
- tickTime=2000
- # The number of ticks that the initial
- # synchronization phase can take
- initLimit=10
- # The number of ticks that can pass between
- # sending a request and getting an acknowledgement
- syncLimit=5
- # the directory where the snapshot is stored.
- # do not use /tmp for storage, /tmp here is just
- # example sakes.
- dataDir=D:/kafka/zookeeper/colony/zookeeper/data2182
-
- dataLogDir=D:/kafka/zookeeper/colony/zookeeper/logs2
- # the port at which the clients will connect
- clientPort=2182
- # the maximum number of client connections.
- # increase this if you need to handle more clients
- #maxClientCnxns=60
-
- admin.serverPort=8081
- #
- # Be sure to read the maintenance section of the
- # administrator guide before turning on autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in dataDir
- #autopurge.snapRetainCount=3
- # Purge task interval in ho

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。