ZooKeeper 在 Windows 操作系统中的安装、配置与运行

本文介绍在 Windows 操作系统上安装 ZooKeeper 的方法与过程。


目录

  • 版本说明
  • 安装
  • 配置
  • 运行
  • 测试
    • 连接 ZooKeeper 服务
    • 查看帮助
    • 创建 znode
    • 查看所有 znode
    • 查看指定 znode 的值

版本说明

  • Windows 10
  • ZooKeeper 3.6.0
  • JDK 8

安装

  1. 因为 ZooKeeper 依赖 Java 环境运行,所以首先需要下载、安装和配置 JDK(本示例使用 JDK 8)。

  2. 下载 ZooKeeper stable 版本,本示例使用 3.6.0 版本,下载文件是 apache-zookeeper-3.6.0-bin.tar.gz
    注意:不要下载 Source Release 版本,否则启动会报错。Source Release 版本大小只有 3MB 左右,且文件名中没有 bin

  3. 将下载文件拷贝到安装目录下解压缩。


配置

进入解压缩后根目录的 conf 文件夹,复制 zoo_sample.cfg 文件并粘贴在同一目录下,将文件名称修改为 zoo.cfg,修改如下:

 

# 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=D:/Dev/ZooKeeper/data
dataLogDir=D:/Dev/ZooKeeper/log
# the port at which the clients will connect
clientPort=2181
# 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

说明:

  • tickTime:ZooKeeper 使用的基本时间单位(毫秒),用于调节心跳和超时,最小会话超时是两倍 tickTime
  • dataDir:ZooKeeper 存储内存数据库快照,除非另有说明,否则为数据库更新的事务日志。
  • dataLogDir:指定事务日志存储路径,如不设置则使用 dataDir 存储事务日志。这个配置项有助于避免日志记录和内存数据库快照之间的竞争。
  • clientPort:监听客户端连接的端口号,默认为 2181

运行

运行 cmd 打开一个新的命令提示符窗口,进入 ZooKeeper 安装根目录下 bin 子目录,执行以下命令启动:

 

D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin>zkServer.cmd

D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin>call "D:\Dev\Java\jdk1.8.0_222"\bin\java "-Dzookeeper.log.dir=D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\logs" "-Dzookeeper.root.logger=INFO,CONSOLE" "-Dzookeeper.log.file=.log" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%p /t /f" -cp "D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\classes;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\lib\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf\zoo.cfg"
2020-04-24 17:32:31,752 [myid:] - INFO  [main:QuorumPeerConfig@173] - Reading configuration from: D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf\zoo.cfg
2020-04-24 17:32:31,799 [myid:] - INFO  [main:QuorumPeerConfig@459] - clientPortAddress is 0.0.0.0:2181
2020-04-24 17:32:31,799 [myid:] - INFO  [main:QuorumPeerConfig@463] - secureClientPort is not set
2020-04-24 17:32:31,799 [myid:] - INFO  [main:QuorumPeerConfig@479] - observerMasterPort is not set
2020-04-24 17:32:31,799 [myid:] - INFO  [main:QuorumPeerConfig@496] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-04-24 17:32:31,799 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2020-04-24 17:32:31,799 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2020-04-24 17:32:31,814 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2020-04-24 17:32:31,814 [myid:] - WARN  [main:QuorumPeerMain@138] - Either no config or no quorum defined in config, running in standalone mode
2020-04-24 17:32:31,814 [myid:] - INFO  [main:ManagedUtil@45] - Log4j found with jmx enabled.
2020-04-24 17:32:31,908 [myid:] - INFO  [main:QuorumPeerConfig@173] - Reading configuration from: D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf\zoo.cfg
2020-04-24 17:32:31,924 [myid:] - INFO  [main:QuorumPeerConfig@459] - clientPortAddress is 0.0.0.0:2181
2020-04-24 17:32:31,924 [myid:] - INFO  [main:QuorumPeerConfig@463] - secureClientPort is not set
2020-04-24 17:32:31,924 [myid:] - INFO  [main:QuorumPeerConfig@479] - observerMasterPort is not set
2020-04-24 17:32:31,924 [myid:] - INFO  [main:QuorumPeerConfig@496] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-04-24 17:32:31,924 [myid:] - INFO  [main:ZooKeeperServerMain@122] - Starting server
2020-04-24 17:32:32,032 [myid:] - INFO  [main:ServerMetrics@62] - ServerMetrics initialized with provider org.apache.zookeeper.metrics.impl.DefaultMetricsProvider@63d4e2ba
2020-04-24 17:32:32,038 [myid:] - INFO  [main:FileTxnSnapLog@124] - zookeeper.snapshot.trust.empty : false
2020-04-24 17:32:32,059 [myid:] - INFO  [main:ZookeeperBanner@42] -
2020-04-24 17:32:32,060 [myid:] - INFO  [main:ZookeeperBanner@42] -   ______                  _
2020-04-24 17:32:32,063 [myid:] - INFO  [main:ZookeeperBanner@42] -  |___  /                 | |
2020-04-24 17:32:32,069 [myid:] - INFO  [main:ZookeeperBanner@42] -     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __
2020-04-24 17:32:32,070 [myid:] - INFO  [main:ZookeeperBanner@42] -    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
2020-04-24 17:32:32,072 [myid:] - INFO  [main:ZookeeperBanner@42] -   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |
2020-04-24 17:32:32,073 [myid:] - INFO  [main:ZookeeperBanner@42] -  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
2020-04-24 17:32:32,074 [myid:] - INFO  [main:ZookeeperBanner@42] -                                               | |
2020-04-24 17:32:32,075 [myid:] - INFO  [main:ZookeeperBanner@42] -                                               |_|
2020-04-24 17:32:32,076 [myid:] - INFO  [main:ZookeeperBanner@42] -
2020-04-24 17:32:32,102 [myid:] - INFO  [main:Environment@98] - Server environment:zookeeper.version=3.6.0--b4c89dc7f6083829e18fae6e446907ae0b1f22d7, built on 02/25/2020 14:38 GMT
2020-04-24 17:32:32,103 [myid:] - INFO  [main:Environment@98] - Server environment:host.name=
2020-04-24 17:32:32,106 [myid:] - INFO  [main:Environment@98] - Server environment:java.version=1.8.0_222
2020-04-24 17:32:32,107 [myid:] - INFO  [main:Environment@98] - Server environment:java.vendor=
2020-04-24 17:32:32,109 [myid:] - INFO  [main:Environment@98] - Server environment:java.home=D:\Dev\Java\jdk1.8.0_222\jre
2020-04-24 17:32:32,110 [myid:] - INFO  [main:Environment@98] - Server environment:java.class.path=D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\classes;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\lib\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\audience-annotations-0.5.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\commons-cli-1.2.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\commons-lang-2.6.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-annotations-2.9.10.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-core-2.9.10.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-databind-2.9.10.3.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\javax.servlet-api-3.1.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-http-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-io-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-security-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-server-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-servlet-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-util-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jline-2.11.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\json-simple-1.1.1.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\log4j-1.2.17.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\metrics-core-3.2.5.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-buffer-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-codec-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-common-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-handler-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-resolver-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-native-epoll-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-native-unix-common-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_common-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_hotspot-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_servlet-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\slf4j-api-1.7.25.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\slf4j-log4j12-1.7.25.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\snappy-java-1.1.7.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-jute-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-prometheus-metrics-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf
2020-04-24 17:32:32,114 [myid:] - INFO  [main:Environment@98] - Server environment:java.library.path=D:\Dev\Java\jdk1.8.0_222\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\Dev\Java\jdk1.8.0_222\bin;D:\Dev\Maven\apache-maven-3.6.3\bin;D:\Dev\MySQL\mysql-8.0.19-winx64\bin;D:\Dev\TortoiseSVN\bin;C:\TestTools\TMSS;D:\Dev\Git\cmd;D:\Dev\Go\bin;C:\WINDOWS\System32\OpenSSH\;D:\Dev\GoPath\bin;D:\Dev\Flutter\flutter\bin;D:\Dev\Git\bin;D:\Dev\nodejs\;C:\Python37\Scripts\;C:\Python37\;C:\Users\...\go\bin;C:\Users\...\AppData\Local\Microsoft\WindowsApps;D:\Dev\nodejs\node_global;.
2020-04-24 17:32:32,118 [myid:] - INFO  [main:Environment@98] - Server environment:java.io.tmpdir=C:\Users\...\AppData\Local\Temp\
2020-04-24 17:32:32,121 [myid:] - INFO  [main:Environment@98] - Server environment:java.compiler=
2020-04-24 17:32:32,121 [myid:] - INFO  [main:Environment@98] - Server environment:os.name=Windows 10
2020-04-24 17:32:32,122 [myid:] - INFO  [main:Environment@98] - Server environment:os.arch=amd64
2020-04-24 17:32:32,123 [myid:] - INFO  [main:Environment@98] - Server environment:os.version=10.0
2020-04-24 17:32:32,123 [myid:] - INFO  [main:Environment@98] - Server environment:user.name=
2020-04-24 17:32:32,124 [myid:] - INFO  [main:Environment@98] - Server environment:user.home=C:\Users\...
2020-04-24 17:32:32,125 [myid:] - INFO  [main:Environment@98] - Server environment:user.dir=D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin
2020-04-24 17:32:32,125 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.free=231MB
2020-04-24 17:32:32,126 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.max=3639MB
2020-04-24 17:32:32,127 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.total=245MB
2020-04-24 17:32:32,128 [myid:] - INFO  [main:ZooKeeperServer@128] - zookeeper.enableEagerACLCheck = false
2020-04-24 17:32:32,128 [myid:] - INFO  [main:ZooKeeperServer@136] - zookeeper.digest.enabled = true
2020-04-24 17:32:32,129 [myid:] - INFO  [main:ZooKeeperServer@140] - zookeeper.closeSessionTxn.enabled = true
2020-04-24 17:32:32,132 [myid:] - INFO  [main:ZooKeeperServer@1433] - zookeeper.flushDelay=0
2020-04-24 17:32:32,140 [myid:] - INFO  [main:ZooKeeperServer@1442] - zookeeper.maxWriteQueuePollTime=0
2020-04-24 17:32:32,141 [myid:] - INFO  [main:ZooKeeperServer@1451] - zookeeper.maxBatchSize=1000
2020-04-24 17:32:32,142 [myid:] - INFO  [main:ZooKeeperServer@241] - zookeeper.intBufferStartingSizeBytes = 1024
2020-04-24 17:32:32,151 [myid:] - INFO  [main:BlueThrottle@141] - Weighed connection throttling is disabled
2020-04-24 17:32:32,154 [myid:] - INFO  [main:ZooKeeperServer@1246] - minSessionTimeout set to 4000
2020-04-24 17:32:32,154 [myid:] - INFO  [main:ZooKeeperServer@1255] - maxSessionTimeout set to 40000
2020-04-24 17:32:32,157 [myid:] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-04-24 17:32:32,157 [myid:] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-04-24 17:32:32,167 [myid:] - INFO  [main:RequestPathMetricsCollector@111] - zookeeper.pathStats.slotCapacity = 60
2020-04-24 17:32:32,167 [myid:] - INFO  [main:RequestPathMetricsCollector@112] - zookeeper.pathStats.slotDuration = 15
2020-04-24 17:32:32,168 [myid:] - INFO  [main:RequestPathMetricsCollector@113] - zookeeper.pathStats.maxDepth = 6
2020-04-24 17:32:32,169 [myid:] - INFO  [main:RequestPathMetricsCollector@114] - zookeeper.pathStats.initialDelay = 5
2020-04-24 17:32:32,170 [myid:] - INFO  [main:RequestPathMetricsCollector@115] - zookeeper.pathStats.delay = 5
2020-04-24 17:32:32,170 [myid:] - INFO  [main:RequestPathMetricsCollector@116] - zookeeper.pathStats.enabled = false
2020-04-24 17:32:32,184 [myid:] - INFO  [main:ZooKeeperServer@1470] - The max bytes for all large requests are set to 104857600
2020-04-24 17:32:32,185 [myid:] - INFO  [main:ZooKeeperServer@1484] - The large request threshold is set to -1
2020-04-24 17:32:32,186 [myid:] - INFO  [main:ZooKeeperServer@329] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 clientPortListenBacklog -1 datadir D:\Dev\ZooKeeper\log\version-2 snapdir D:\Dev\ZooKeeper\data\version-2
2020-04-24 17:32:32,221 [myid:] - INFO  [main:Log@169] - Logging initialized @852ms to org.eclipse.jetty.util.log.Slf4jLog
2020-04-24 17:32:32,405 [myid:] - WARN  [main:ContextHandler@1520] - o.e.j.s.ServletContextHandler@578486a3{/,null,UNAVAILABLE} contextPath ends with /*
2020-04-24 17:32:32,405 [myid:] - WARN  [main:ContextHandler@1531] - Empty contextPath
2020-04-24 17:32:32,431 [myid:] - INFO  [main:Server@359] - jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 1.8.0_222-_JDK_V100R001C00SPC130B005-b10
2020-04-24 17:32:32,514 [myid:] - INFO  [main:DefaultSessionIdManager@333] - DefaultSessionIdManager workerName=node0
2020-04-24 17:32:32,515 [myid:] - INFO  [main:DefaultSessionIdManager@338] - No SessionScavenger set, using defaults
2020-04-24 17:32:32,524 [myid:] - INFO  [main:HouseKeeper@140] - node0 Scavenging every 600000ms
2020-04-24 17:32:32,548 [myid:] - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@578486a3{/,null,AVAILABLE}
2020-04-24 17:32:32,723 [myid:] - INFO  [main:AbstractConnector@330] - Started ServerConnector@239963d8{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2020-04-24 17:32:32,723 [myid:] - INFO  [main:Server@399] - Started @1361ms
2020-04-24 17:32:32,723 [myid:] - INFO  [main:JettyAdminServer@178] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2020-04-24 17:32:32,739 [myid:] - INFO  [main:ServerCnxnFactory@169] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2020-04-24 17:32:32,739 [myid:] - WARN  [main:ServerCnxnFactory@309] - maxCnxns is not configured, using default value 0.
2020-04-24 17:32:32,739 [myid:] - INFO  [main:NIOServerCnxnFactory@666] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 8 worker threads, and 64 kB direct buffers.
2020-04-24 17:32:32,739 [myid:] - INFO  [main:NIOServerCnxnFactory@674] - binding to port 0.0.0.0/0.0.0.0:2181
2020-04-24 17:32:32,779 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-04-24 17:32:32,782 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-04-24 17:32:32,784 [myid:] - INFO  [main:ZKDatabase@132] - zookeeper.snapshotSizeFactor = 0.33
2020-04-24 17:32:32,784 [myid:] - INFO  [main:ZKDatabase@152] - zookeeper.commitLogCount=500
2020-04-24 17:32:32,801 [myid:] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
2020-04-24 17:32:32,801 [myid:] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x0 to D:\Dev\ZooKeeper\data\version-2\snapshot.0
2020-04-24 17:32:32,811 [myid:] - INFO  [main:ZKDatabase@289] - Snapshot loaded in 26 ms, highest zxid is 0x0, digest is 1371985504
2020-04-24 17:32:32,812 [myid:] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x0 to D:\Dev\ZooKeeper\data\version-2\snapshot.0
2020-04-24 17:32:32,817 [myid:] - INFO  [main:ZooKeeperServer@519] - Snapshot taken in 5 ms
2020-04-24 17:32:32,837 [myid:] - INFO  [main:RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000
2020-04-24 17:32:32,867 [myid:] - INFO  [main:ContainerManager@83] - Using checkIntervalMs=60000 maxPerMinute=10000 maxNeverUsedIntervalMs=0
2020-04-24 17:32:32,868 [myid:] - INFO  [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.

测试

连接 ZooKeeper 服务

 

D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin>zkCli.cmd -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2020-04-24 17:37:53,803 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.0--b4c89dc7f6083829e18fae6e446907ae0b1f22d7, built on 02/25/2020 14:38 GMT
2020-04-24 17:37:53,808 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=
2020-04-24 17:37:53,810 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_222
2020-04-24 17:37:53,814 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=
2020-04-24 17:37:53,818 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=D:\Dev\Java\jdk1.8.0_222\jre
2020-04-24 17:37:53,820 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\classes;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\build\lib\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\*;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\audience-annotations-0.5.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\commons-cli-1.2.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\commons-lang-2.6.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-annotations-2.9.10.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-core-2.9.10.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jackson-databind-2.9.10.3.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\javax.servlet-api-3.1.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-http-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-io-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-security-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-server-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-servlet-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jetty-util-9.4.24.v20191120.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\jline-2.11.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\json-simple-1.1.1.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\log4j-1.2.17.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\metrics-core-3.2.5.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-buffer-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-codec-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-common-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-handler-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-resolver-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-native-epoll-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\netty-transport-native-unix-common-4.1.45.Final.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_common-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_hotspot-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\simpleclient_servlet-0.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\slf4j-api-1.7.25.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\slf4j-log4j12-1.7.25.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\snappy-java-1.1.7.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-jute-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\lib\zookeeper-prometheus-metrics-3.6.0.jar;D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin\..\conf
2020-04-24 17:37:53,821 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=D:\Dev\Java\jdk1.8.0_222\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\Dev\Java\jdk1.8.0_222\bin;D:\Dev\Maven\apache-maven-3.6.3\bin;D:\Dev\MySQL\mysql-8.0.19-winx64\bin;D:\Dev\TortoiseSVN\bin;C:\TestTools\TMSS;D:\Dev\Git\cmd;D:\Dev\Go\bin;C:\WINDOWS\System32\OpenSSH\;D:\Dev\GoPath\bin;D:\Dev\Flutter\flutter\bin;D:\Dev\Git\bin;D:\Dev\nodejs\;C:\Python37\Scripts\;C:\Python37\;C:\Users\...\go\bin;C:\Users\...\AppData\Local\Microsoft\WindowsApps;D:\Dev\nodejs\node_global;.
2020-04-24 17:37:53,822 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=C:\Users\...\AppData\Local\Temp\
2020-04-24 17:37:53,823 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=
2020-04-24 17:37:53,829 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Windows 10
2020-04-24 17:37:53,834 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-04-24 17:37:53,835 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=10.0
2020-04-24 17:37:53,836 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=
2020-04-24 17:37:53,837 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=C:\Users\...
2020-04-24 17:37:53,837 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=D:\Dev\ZooKeeper\apache-zookeeper-3.6.0-bin\bin
2020-04-24 17:37:53,838 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=236MB
2020-04-24 17:37:53,841 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=3639MB
2020-04-24 17:37:53,845 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=245MB
2020-04-24 17:37:53,857 [myid:] - INFO  [main:ZooKeeper@1005] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7637f22
2020-04-24 17:37:53,870 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-04-24 17:37:54,134 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-04-24 17:37:54,147 [myid:] - INFO  [main:ClientCnxn@1703] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2020-04-24 17:37:54,161 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1154] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181.
2020-04-24 17:37:54,162 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1156] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-04-24 17:37:54,170 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@986] - Socket connection established, initiating session, client: /127.0.0.1:51683, server: 127.0.0.1/127.0.0.1:2181
JLine support is enabled
2020-04-24 17:37:54,240 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1420] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, session id = 0x100002de1730000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]

查看帮助

 

[zk: 127.0.0.1:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
        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

创建 znode

 

[zk: 127.0.0.1:2181(CONNECTED) 2] create /zk_test test_data
Created /zk_test

查看所有 znode

 

[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[zk_test, zookeeper]

查看指定 znode 的值

 

[zk: 127.0.0.1:2181(CONNECTED) 4] get /zk_test
test_data

至此已测试 ZooKeeper 安装启动成功,其余命令将在另外的文章中专门讲解。



作者:又语
链接:https://www.jianshu.com/p/1f8a97c4417f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(zookeeper)