zookeeper 从入门到放弃(02)

之前有探究如何启动多个zookeeper,但如果不形成集群的话,意义不大,那么zookeeper 集群如何搭建呢?

create zookeeper server folder

复制多个 zookeepr folder

我这里拷贝了3个,但实际上为了简化过程我只使用了2个

Alt text

set config

server1 config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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=../zkData
dataLogDir=../zkData/log
# 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
reconfigEnabled=true
#server.1=127.0.0.1:2081:2780:2783:participant;2791
server.1=127.0.0.1:2887:3887
server.2=127.0.0.1:2888:3888
#server.3=127.0.0.1:2889:3889
admin.serverPort=8081

server1 config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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=../zkData
dataLogDir=../zkData/log
# 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
reconfigEnabled=true
#server.1=127.0.0.1:2081:2780:2783:participant;2791
server.1=127.0.0.1:2887:3887
server.2=127.0.0.1:2888:3888
#server.3=127.0.0.1:2889:3889
admin.serverPort=8082

run servers

zkServer 分别启动两个 server

test

ok,没有啥问题

Alt text

Alt text

有意思的是,当我关掉一台 server 时,分别连接 2 个 server 的 client 都出现了异常

Alt text

Alt text

Alt text

Alt text

那么集群的高可用性、健壮性是如何体现的呢?

当我启动3台server时,如果我关闭其中1台,那么,对应的3个client,只有连接关闭那台server的client受到了影响,这是因为 zk server 具有fast fail特性,当挂掉的 server 数量不超过 server 总量的 1/2 时,不影响其提供服务

参考资料: win10环境下搭建zookeeper伪集群

|