本文主要是介绍如何从0开始搭建一个3节点的ZooKeeper仲裁集群,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
时间戳:2021-04-08 22:00:46
-
场景:客户端与ZK集群交互图
本文,将规划一个3节点的ZK集群。 -
软件安装
本文使用了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脚本,将集群启动起来
-
检查集群的状态
-
客户端连接
/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:2183Connecting 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]
- 小结
ZooKeeper为分布式应用提供协调服务。让开发者更少关注分布式系统协调服务,将有限的精力投入到更有价值的业务的开发。
这篇关于如何从0开始搭建一个3节点的ZooKeeper仲裁集群的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!