实验环境:
1. centos7.6最小化安装
2. jdk1.8
3. zookeeper-3.4.14
安装步骤
大致类似上一篇文章:zookeeper安装一:单机安装
区别:
1. 在上一个单机安装装的技术上增加两台机器
分别是192.168.255.130,192.168.255.131,192.168.255.132
2. 它们的配置文件zoo.cfg在最末尾都加上
server.1=192.168.255.130:2888:3888
server.2=192.168.255.131:2888:3888
server.3=192.168.255.132:2888:3888
3. 在各自机器的dataDir目录下新建文件myid
192.168.22.130的myid文件内容为1
192.168.22.131的myid文件内容为2
192.168.22.132的myid文件内容为3
4. 依次启动130,131,132
[root@localhost bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /soft/zookeeper-3.4.14/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
每个机器启动后的输出文件都是这样的
5. 在任意台机器上去连这个集群
[root@localhost bin]# ./zkCli.sh -server 192.168.255.130:2181,192.168.255.131:2181,192.168.255.132:2181
可以看到以下输出:
…
Welcome to ZooKeeper!
JLine support is enabled
2019-05-21 23:55:27,032 [myid:] - INFO [main-SendThread(192.168.255.131:2181):ClientCnxn
S
e
n
d
T
h
r
e
a
d
@
1025
]
−
O
p
e
n
i
n
g
s
o
c
k
e
t
c
o
n
n
e
c
t
i
o
n
t
o
s
e
r
v
e
r
192.168.255.131
/
192.168.255.131
:
2181.
W
i
l
l
n
o
t
a
t
t
e
m
p
t
t
o
a
u
t
h
e
n
t
i
c
a
t
e
u
s
i
n
g
S
A
S
L
(
u
n
k
n
o
w
n
e
r
r
o
r
)
2019
−
05
−
2123
:
55
:
27
,
390
[
m
y
i
d
:
]
−
I
N
F
O
[
m
a
i
n
−
S
e
n
d
T
h
r
e
a
d
(
192.168.255.131
:
2181
)
:
C
l
i
e
n
t
C
n
x
n
SendThread@1025] - Opening socket connection to server 192.168.255.131/192.168.255.131:2181. Will not attempt to authenticate using SASL (unknown error) 2019-05-21 23:55:27,390 [myid:] - INFO [main-SendThread(192.168.255.131:2181):ClientCnxn
SendThread@1025]−Openingsocketconnectiontoserver192.168.255.131/192.168.255.131:2181.WillnotattempttoauthenticateusingSASL(unknownerror)2019−05−2123:55:27,390[myid:]−INFO[main−SendThread(192.168.255.131:2181):ClientCnxnSendThread@879] - Socket connection established to 192.168.255.131/192.168.255.131:2181, initiating session
2019-05-21 23:55:27,490 [myid:] - INFO [main-SendThread(192.168.255.131:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 192.168.255.131/192.168.255.131:2181, sessionid = 0x2000049a1090000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 192.168.255.131:2181,192.168.255.130:2181,192.168.255.132:2181(CONNECTED) 0] ls /
[zookeeper, zkdemo]
说明连接到了192.168.255.131
这个机器上了。注意连接到那台机器上是随机的。
关闭的时候可以依次关闭单个机器,这个没有试验。