如何从0开始搭建一个3节点的ZooKeeper仲裁集群

时间戳:2021-04-08 22:00:46

  1. 场景:客户端与ZK集群交互图
    客户端与ZK集群交互图
    本文,将规划一个3节点的ZK集群。

  2. 软件安装
    本文使用了spack包管理器一键式安装zookeeper软件,命令为

spack install zookeeper

安装好的zookeeper目录结构如下
在这里插入图片描述
3. 配置文件
本集群3节点,需3个配置文件
在这里插入图片描述
如上图所示,分别定义了server.1, server.2, server.3三台服务器。

服务器从 $dataDir/myid 文件中得到自己的ID,在启动集群之前,先将各自的myid文件准备好
在这里插入图片描述
4. 启动集群
启动命令是

zkServer.sh start </path/to/zoo.cfg>

我将集群启动命令写在脚本里,如下图
在这里插入图片描述
执行./start_zk_quorums.sh脚本,将集群启动起来

  1. 检查集群的状态
    在这里插入图片描述

  2. 客户端连接

/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/zkCli.sh \
-server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
 
Connecting to 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
2021-04-08 21:55:59,402 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
2021-04-08 21:55:59,407 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=192.168.1.5
2021-04-08 21:55:59,407 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_281
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../build/classes:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../build/lib/*.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/slf4j-log4j12-1.6.1.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/slf4j-api-1.6.1.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/netty-3.10.5.Final.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/log4j-1.2.16.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/jline-0.9.94.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/audience-annotations-0.5.0.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../zookeeper-3.4.11.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../src/java/lib/*.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../conf:
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/Users/ben/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/var/folders/9d/x216k2yd6kjbqt67_svwpy940000gn/T/
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Mac OS X
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=x86_64
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=10.16
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=ben
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/Users/ben
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/Users/ben/zkPractice
2021-04-08 21:55:59,412 [myid:] - INFO  [main:ZooKeeper@441] - Initiating client connection, connectString=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@27fa135a
Welcome to ZooKeeper!
2021-04-08 21:55:59,437 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1035] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-04-08 21:55:59,450 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@877] - Socket connection established to 127.0.0.1/127.0.0.1:2182, initiating session
2021-04-08 21:55:59,458 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2182, sessionid = 0x200026b38b80001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 0] ls
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 1] ls /
[zookeeper]
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 2]
  1. 小结

ZooKeeper为分布式应用提供协调服务。让开发者更少关注分布式系统协调服务,将有限的精力投入到更有价值的业务的开发。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王万林 Ben

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值