zookeeper安装(Windows版)

背景

由于系统限制,暂时用windows作为开发环境。
开发环境:windows 10
zookeeper版本: zookeeper-3.6.2

过程

下载

zookeeper-3.6.2上下载,直接下载带有bin的tar.gz 。
如果是另一个包,在启动的时候会报一个错:
错误: 找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain
这时候因为缺少lib的包,到上面网页下载一个bin的包,然后将里面的lib直接复制过去。

配置

  1. conf配置
    路径:\apache-zookeeper-3.6.2\conf
    修改:复制一份zoo_sample.cfg,修改为zoo.cfg。
    增加dataDir配置
# The number of milliseconds of each tick
# 心跳的时间间隔
tickTime=2000

# The number of ticks that the initial 
# synchronization phase can take
# Follower 服务器初始化连接时最长能忍受多少个心跳时间间隔数
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.
# Zookeeper 将写数据的日志文件也保存在这个目录里
dataDir=F://apache-zookeeper-3.6.2//apache-zookeeper-3.6.2//data

# the port at which the clients will connect
# Zookeeper 会监听这个端口,接受客户端的访问请求
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
脚本介绍
  • zkServer.sh: ZooKeeper服务器的启动、停止和重启脚本;
  • zkCli.sh:ZooKeeper的简易客户端;
  • zkEnv.sh: 设置ZooKeeper的环境变量;
  • zkCleanup.sh: 清理ZooKeeper历史数据,包括事务日志文件和快照数据文件。

客户端

命令

 addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
        addauth scheme auth
        close
        config [-c] [-w] [-s]
        connect host:port
        create [-s] [-e] [-c] [-t ttl] path [data] [acl]
        delete [-v version] path
        deleteall path [-b batch size]
        delquota [-n|-b] path
        get [-s] [-w] path
        getAcl [-s] path
        getAllChildrenNumber path
        getEphemerals path
        history
        listquota path
        ls [-s] [-w] [-R] path
        printwatches on|off
        quit
        reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
        redo cmdno
        removewatches path [-c|-d|-a] [-l]
        set [-s] [-v version] path data
        setAcl [-s] [-v version] [-R] path acl
        setquota -n|-b val path
        stat [-w] path
        sync path
        version

部分操作

[zk: localhost:2181(CONNECTED) 1] create /testInput "inputData"
Created /testInput
[zk: localhost:2181(CONNECTED) 2] get /testInput
inputData
[zk: localhost:2181(CONNECTED) 3] inputData
[zk: localhost:2181(CONNECTED) 4] get /testInput
inputData
[zk: localhost:2181(CONNECTED) 5] getAcl /testInput
'world,'anyone
: cdrwa
[zk: localhost:2181(CONNECTED) 6] getEphemerals /testInput
[]
[zk: localhost:2181(CONNECTED) 7] reconfig  /testInput
reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
[zk: localhost:2181(CONNECTED) 8] ls /testInput
[]
[zk: localhost:2181(CONNECTED) 9] create /testInput/put01
Created /testInput/put01
[zk: localhost:2181(CONNECTED) 10] getAllChildrenNumber /testInput
1
[zk: localhost:2181(CONNECTED) 11] ls /
[testInput, zookeeper]
[zk: localhost:2181(CONNECTED) 12] get /zookeeper

[zk: localhost:2181(CONNECTED) 13] get /testInput
inputData
[zk: localhost:2181(CONNECTED) 14] ls /testInput
[put01]
[zk: localhost:2181(CONNECTED) 15] get /testInput/put01
null
[zk: localhost:2181(CONNECTED) 16] stat /testInput
cZxid = 0x4
ctime = Wed Mar 24 23:56:58 CST 2021
mZxid = 0x4
mtime = Wed Mar 24 23:56:58 CST 2021
pZxid = 0x8
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 1

总结

安装了以下zookeeper,操作起来很像文件目录+树状结构的感觉,每个node上既有path代表唯一路径,上面还有值,还有子目录。就是查看起来不太好查看,感觉可以加一个前端可视化放边后面的阅读。
后面用java来操作zookeeper,写个demo来展示下。


版权声明:本文为Donatello_Jiang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。