1.下载zookeer,注意下载编译后的二进制的包
下载地址:https://zookeeper.apache.org/releases.html
2.windos下安装
- 解压到自己定义的目录,我的存放在:E:\工具\zookeeper2181
- 在E:\工具\zookeeper2181目录下新建data和log文件夹
3.进入conf文件夹,复制zoo_sample.cfg文件并重命名为zoo.cfg,更改zoo.cfg配置,创建的文件夹data和log的路径。注意:这里配置绝对路径用双斜杠,如果路径中有中文,中文要转成unicode,不然会报找不到myid文件
# 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=E:\\\u5de5\u5177\\zookeeper2181\\data
dataLogDir=E:\\\u5de5\u5177\\zookeeper2181\\logs
# 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.1=127.0.0.1:3001:4001
server.2=127.0.0.1:3002:4002
server.3=127.0.0.1:3003:4003
4.在配置的dataDir目录下新建一个名称为myid的文件,文件的内容是zoo.cfg中server后的数字。需要保持集群之间的serverId是唯一的。注意:myid文件是没有后缀名的。
5.配置好后复制两份Zookeeper,修改配置文件zoo.cfg的端口,data,log的文件地址,对应zookeeper2182和zookeeper2183的zoo.cfg内容如下:
zookeeper2182的zoo.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=E:\\\u5de5\u5177\\zookeeper2182\\data
dataLogDir=E:\\\u5de5\u5177\\zookeeper2182\\logs
# 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.1=127.0.0.1:3001:4001
server.2=127.0.0.1:3002:4002
server.3=127.0.0.1:3003:4003
zookeeper2183的zoo.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=E:\\\u5de5\u5177\\zookeeper2183\\data
dataLogDir=E:\\\u5de5\u5177\\zookeeper2183\\logs
# the port at which the clients will connect
clientPort=2183
# 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.1=127.0.0.1:3001:4001
server.2=127.0.0.1:3002:4002
server.3=127.0.0.1:3003:4003
到此伪集群配置完成,分别到每个目录下面bin目录下运行zkServer.cmd