一、软件版本
apache-zookeeper-3.7.0-bin.tar.gz下载地址
==操作系统:Win10 20H2==
二、依赖安装:JDK8
参考:Cassandra 3.11.10 集群搭建-Windows中JDK安装。
三、单机部署
- 解压apache-zookeeper-3.7.0-bin.tar.gz放置于任意盘中
-
设置环境变量
1)ZOOKEEPER_HOME
2)bin
3)环境变量验证
win+r 输入cmd打开控制台,任意路径下输入命令:zkServer。
-
配置zookeeper配置文件
1)zookeeper配置文件路径
D:\software\apache-zookeeper-3.7.0-bin\conf
实际运行时,zookeeper加载名为zoo.cfg的配置文件,这时仅需赋值zoo_sample.cfg文件,并重命名为zoo.cfg。
2)zookeeper配置文件内容请参考:
配置项 | 含义 |
---|---|
tickTime | ZK中的一个时间单元。ZK中所有时间都是以这个时间单元为基础,进行整数倍配置的。例如,session的最小超时时间是2*tickTime。 |
initLimit | 初始化集群时集群节点同步超时时间, 默认是10个tickTime, 也即20s |
syncLimit | 集群在运行过程中同步数据超时时间, 默认5个tickTime |
dataDir | 默认数据存储位置 |
clientPort | zookeeper服务监听端口号 |
maxClientCnxns | 连接池连接数量 |
autopurge.snapRetainCount | zookeeper是运行在内存中的, 因此与Redis类似, 他也是使用快照进行持久化. 这里的snapRetainCount是指有多少个快照就会将快照进行合并 |
autopurge.purgeInterval | 同样是快照合并的配置, 这里指的是在多长时间内, 如果有snapRetainCount个快照, 进行合并 |
参考:
3)zookeeper配置
这里仅配置了dataDir项:默认数据存储位置:dataDir=D:\software\apache-zookeeper-3.7.0-bin\data
-
启动zookeeper&验证
使用命令:zkServer 启用zookeeper
新启cmd,使用命令zkCli -server 127.0.0.1:2181
四、集群搭建:单机多进程(单IP多端口)
- 这里无需设置环境变量,可把单机时设置的环境变量删除!
- 拷贝出3个apache-zookeeper-3.7.0-bin并依次重命名
-
依次修改配置文件
1)apache-zookeeper-3.7.0-bin-0
创建默认数据存储位置文件夹,依次修改配置项:
dataDir=D:\software\zookeeper\apache-zookeeper-3.7.0-bin-0\data #此处需修改,无文件夹则需创建,保证文件路径的格式:\\
集群点:
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3#格式: server.A = B:C:D
#A:是一个数字,表示第几号服务器
#B:服务器IP地址
#C:是一个端口号,用来集群成员的信息交换,表示这个服务器与集群中的leader服务器交换信息的端口
#D:是在leader挂掉时专门用来进行选举leader所用的端口
所需修改配置项如下:
clientPort=2180
dataDir=D:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-0\\data #此处需修改,无文件
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3
复制代码
总配置文件如下:
# 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:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-0\\data #此处需修改,无文件夹则需创建,保证文件路径的格式:\\
# the port at which the clients will connect
clientPort=2180
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3
#格式: server.A = B:C:D
#A:是一个数字,表示第几号服务器
#B:服务器IP地址
#C:是一个端口号,用来集群成员的信息交换,表示这个服务器与集群中的leader服务器交换信息的端口
#D:是在leader挂掉时专门用来进行选举leader所用的端口
复制代码
2)apache-zookeeper-3.7.0-bin-1
所需修改配置项如下:
clientPort=2181
dataDir=D:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-1\\data
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3
复制代码
总配置文件如下:
# 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:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-1\\data
# 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
#
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.0=127.0.0.1:8880:7770
server.1=127.0.0.1:8881:7771
server.2=127.0.0.1:8882:7772
复制代码
3)apache-zookeeper-3.7.0-bin-2
所需修改配置项如下:
clientPort=2182
dataDir=D:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-2\\data
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3
复制代码
总配置文件如下:
# 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:\\software\\zookeeper\\apache-zookeeper-3.7.0-bin-2\\data
# 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
#
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
server.0=127.0.0.1:8880:7770 #服务1
server.1=127.0.0.1:8881:7771 #服务2
server.2=127.0.0.1:8882:7772 #服务3
复制代码
- 添加myid文件
保证每个apache-zookeeper-3.7.0-bin中的配置文件中的dataDir项的文件夹中对应有myid文件,且myid文件中存有对应的id号。
apache-zookeeper-3.7.0-bin-0为服务0,则在==dataDir=D:\software\zookeeper\apache-zookeeper-3.7.0-bin-0\data==路径下新增myid文件,并在其写入0。
apache-zookeeper-3.7.0-bin-1为服务1,则在==dataDir=D:\software\zookeeper\apache-zookeeper-3.7.0-bin-1\data==路径下新增myid文件,并在其写入1。
apache-zookeeper-3.7.0-bin-2为服务2,则在==dataDir=D:\software\zookeeper\apache-zookeeper-3.7.0-bin-2\data==路径下新增myid文件,并在其写入2。
-
依次启动服务
由于未配置环境变量,则需cmd中cd到每个zookeeper文件夹下的bin目录中执行命令zkServer。
五、集群搭建:多机
方法同==四、集群搭建:单机多进程(单IP多端口)==,但需修改配置文件中的集群配置:
server.0=192.168.2.207:8880:7770 #服务1
server.1=192.168.2.203:8880:7770 #服务2
server.2=192.168.79.128:8880:7770 #服务3
复制代码
六、参考
Kafka集群的搭建(windows版本)_何以清风-CSDN博客
window环境搭建zookeeper,kafka集群 – guan_yan_guan – 博客园 (cnblogs.com)