Zookeeper下载与安装教程(for windows)

Zookeeper下载

1、首先进入apache官网

  • https://www.apache.org/
    然后点击中间的Projects->Project List菜单项进入ProjectList页面,如下图:
    在这里插入图片描述
    2、在ProjectList页面中找点Zookeeper链接,然后点击进入Zookeeper的主页,如下图:
    在这里插入图片描述
    3、在Zookeeper主页的顶部点击菜单Project->Releases,进入Zookeeper发布版本信息页面,如下图:
    在这里插入图片描述
    4、找到最新版的下载链接,如下图:
    在这里插入图片描述
    5、目前最新版本是3.6.2,点击链接进入下载的镜像地址页面,如下图:
    在这里插入图片描述
    6、在国内直接选择清华大学的镜像下载链接进行下载就行,下载后如下图:
    在这里插入图片描述

Zookeeper安装

前置条件

  • 已安装JDK
  • 已配置了环境变量JAVA_HOME,PATH

单机模式部署

1、解压apache-zookeeper-3.6.2-bin.tar.gz至D:\zookeeper\apache-zookeeper-3.6.2-bin。
2、复制D:\zookeeper\apache-zookeeper-3.6.2-bin\conf\zoo-sample.cfg,粘贴为D:\zookeeper\apache-zookeeper-3.6.2-bin\zoo.cfg。
3、修改D:\zookeeper\apache-zookeeper-3.6.2-bin\zoo.cfg。
主要修改了dataDir,如下:

# 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:\\zookeeper\\data
# 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

# server.N = YYY:A:B

配置文件关键配置项说明:

  • tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
  • initLimit:LF初始通信时限,集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
  • syncLimit:LF同步通信时限,集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
  • dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
  • clientPort:客户端连接端口,这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求
  • autopurge.snapRetainCount:保留数量。
  • autopurge.purgeInterval:清理时间间隔,单位:小时。
  • server.N = YYY:A:B,其中N表示服务器编号,YYY表示服务器的IP地址,A为LF通信端口,表示该服务器与集群中的leader交换的信息的端口。B为选举端口,表示选举新leader时服务器间相互通信的端口(当leader挂掉时,其余服务器会相互通信,选择出新的leader)。一般来说,集群中每个服务器的A端口都是一样,每个服务器的B端口也是一样。但是当所采用的为伪集群时,IP地址都一样,只能时A端口和B端口不一样。

4、启动Zookeeper服务器。
在bin目录下执行

zkServer.cmd

就可以了,如下:

D:\zookeeper\apache-zookeeper-3.6.2-bin\bin>zkServer.cmd

D:\zookeeper\apache-zookeeper-3.6.2-bin\bin>call "C:\Java\jre1.8.0_144"\bin\java "-Dzookeeper.log.dir=D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\logs" "-Dzookeeper.root.logger=INFO,CONSOLE" "-Dzookeeper.log.file=zookeeper-Administrator-server-ECS-A0E1-0001.log" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:OnOutOfMemoryError=cmd /c taskkill /pid %%p /t /f" -cp "D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\classes;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\lib\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf\zoo.cfg"
2020-11-13 14:13:15,368 [myid:] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf\zoo.cfg
2020-11-13 14:13:15,399 [myid:] - INFO  [main:QuorumPeerConfig@460] - clientPortAddress is 0.0.0.0:2181
2020-11-13 14:13:15,399 [myid:] - INFO  [main:QuorumPeerConfig@464] - secureClientPort is not set
2020-11-13 14:13:15,399 [myid:] - INFO  [main:QuorumPeerConfig@480] - observerMasterPort is not set
2020-11-13 14:13:15,399 [myid:] - INFO  [main:QuorumPeerConfig@497] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-11-13 14:13:15,399 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2020-11-13 14:13:15,399 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2020-11-13 14:13:15,399 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2020-11-13 14:13:15,399 [myid:] - WARN  [main:QuorumPeerMain@138] - Either no config or no quorum defined in config, running in standalone mode
2020-11-13 14:13:15,399 [myid:] - INFO  [main:ManagedUtil@44] - Log4j 1.2 jmx support found and enabled.
2020-11-13 14:13:15,461 [myid:] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf\zoo.cfg
2020-11-13 14:13:15,461 [myid:] - INFO  [main:QuorumPeerConfig@460] - clientPortAddress is 0.0.0.0:2181
2020-11-13 14:13:15,461 [myid:] - INFO  [main:QuorumPeerConfig@464] - secureClientPort is not set
2020-11-13 14:13:15,461 [myid:] - INFO  [main:QuorumPeerConfig@480] - observerMasterPort is not set
2020-11-13 14:13:15,461 [myid:] - INFO  [main:QuorumPeerConfig@497] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-11-13 14:13:15,461 [myid:] - INFO  [main:ZooKeeperServerMain@122] - Starting server
2020-11-13 14:13:15,508 [myid:] - INFO  [main:ServerMetrics@62] - ServerMetrics initialized with provider org.apache.zookeeper.metrics.impl.DefaultMetricsProvider@61443d8f
2020-11-13 14:13:15,524 [myid:] - INFO  [main:FileTxnSnapLog@124] - zookeeper.snapshot.trust.empty : false
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -   ______                  _                         
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -  |___  /                 | |                        
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -                                               | |   
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -                                               |_|   
2020-11-13 14:13:15,524 [myid:] - INFO  [main:ZookeeperBanner@42] -
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:zookeeper.version=3.6.2--803c7f1a12f85978cb049af5e4ef23bd8b688715, built on 09/04/2020 12:44 GMT
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:host.name=ecs-a0e1-0001
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.version=1.8.0_144
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.vendor=Oracle Corporation
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.home=C:\Java\jre1.8.0_144
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.class.path=D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\classes;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\lib\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\audience-annotations-0.5.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\commons-cli-1.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\commons-lang-2.6.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-annotations-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-core-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-databind-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\javax.servlet-api-3.1.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-http-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-io-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-security-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-server-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-servlet-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-util-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jline-2.14.6.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\json-simple-1.1.1.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\log4j-1.2.17.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\metrics-core-3.2.5.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-buffer-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-codec-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-common-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-handler-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-resolver-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-native-epoll-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-native-unix-common-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_common-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_hotspot-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_servlet-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\slf4j-api-1.7.25.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\slf4j-log4j12-1.7.25.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\snappy-java-1.1.7.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-jute-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-prometheus-metrics-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.library.path=C:\Java\jre1.8.0_144\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Python39\Scripts\;C:\Python39\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs;D:\nodejs\node_global;C:\Program Files\Git\cmd;C:\Java\jre1.8.0_144\bin;C:\Redis\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm;D:\nodejs\node_global;C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin;C:\Java\jre1.8.0_144\bin;.
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\2\
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:java.compiler=<NA>
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.name=Windows Server 2016
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.arch=amd64
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.version=10.0
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:user.name=Administrator
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:user.home=C:\Users\Administrator
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:user.dir=D:\zookeeper\apache-zookeeper-3.6.2-bin\bin
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.free=231MB
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.max=3641MB
2020-11-13 14:13:15,539 [myid:] - INFO  [main:Environment@98] - Server environment:os.memory.total=245MB
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@129] - zookeeper.enableEagerACLCheck = false
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@137] - zookeeper.digest.enabled = true
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@141] - zookeeper.closeSessionTxn.enabled = true
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@1444] - zookeeper.flushDelay=0
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@1453] - zookeeper.maxWriteQueuePollTime=0
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@1462] - zookeeper.maxBatchSize=1000
2020-11-13 14:13:15,539 [myid:] - INFO  [main:ZooKeeperServer@243] - zookeeper.intBufferStartingSizeBytes = 1024
2020-11-13 14:13:15,555 [myid:] - INFO  [main:BlueThrottle@141] - Weighed connection throttling is disabled
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ZooKeeperServer@1256] - minSessionTimeout set to 4000
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ZooKeeperServer@1265] - maxSessionTimeout set to 40000
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@111] - zookeeper.pathStats.slotCapacity = 60
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@112] - zookeeper.pathStats.slotDuration = 15
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@113] - zookeeper.pathStats.maxDepth = 6
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@114] - zookeeper.pathStats.initialDelay = 5
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@115] - zookeeper.pathStats.delay = 5
2020-11-13 14:13:15,555 [myid:] - INFO  [main:RequestPathMetricsCollector@116] - zookeeper.pathStats.enabled = false
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ZooKeeperServer@1481] - The max bytes for all large requests are set to 104857600
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ZooKeeperServer@1495] - The large request threshold is set to -1
2020-11-13 14:13:15,555 [myid:] - INFO  [main:ZooKeeperServer@339] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 clientPortListenBacklog -1 datadir D:\zookeeper\data\version-2 snapdir D:\zookeeper\data\version-2
2020-11-13 14:13:15,571 [myid:] - INFO  [main:Log@169] - Logging initialized @365ms to org.eclipse.jetty.util.log.Slf4jLog
2020-11-13 14:13:15,633 [myid:] - WARN  [main:ContextHandler@1520] - o.e.j.s.ServletContextHandler@32709393{/,null,UNAVAILABLE} contextPath ends with /*
2020-11-13 14:13:15,633 [myid:] - WARN  [main:ContextHandler@1531] - Empty contextPath
2020-11-13 14:13:15,649 [myid:] - INFO  [main:Server@359] - jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 1.8.0_144-b01
2020-11-13 14:13:15,680 [myid:] - INFO  [main:DefaultSessionIdManager@333] - DefaultSessionIdManager workerName=node0
2020-11-13 14:13:15,680 [myid:] - INFO  [main:DefaultSessionIdManager@338] - No SessionScavenger set, using defaults
2020-11-13 14:13:15,680 [myid:] - INFO  [main:HouseKeeper@140] - node0 Scavenging every 660000ms
2020-11-13 14:13:15,680 [myid:] - WARN  [main:ConstraintSecurityHandler@757] - ServletContext@o.e.j.s.ServletContextHandler@32709393{/,null,STARTING} has uncovered http methods for path: /*
2020-11-13 14:13:15,696 [myid:] - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@32709393{/,null,AVAILABLE}
2020-11-13 14:13:15,727 [myid:] - INFO  [main:AbstractConnector@330] - Started ServerConnector@2f686d1f{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2020-11-13 14:13:15,727 [myid:] - INFO  [main:Server@399] - Started @514ms
2020-11-13 14:13:15,727 [myid:] - INFO  [main:JettyAdminServer@182] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2020-11-13 14:13:15,727 [myid:] - INFO  [main:ServerCnxnFactory@169] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2020-11-13 14:13:15,727 [myid:] - WARN  [main:ServerCnxnFactory@309] - maxCnxns is not configured, using default value 0.
2020-11-13 14:13:15,727 [myid:] - INFO  [main:NIOServerCnxnFactory@666] - Configuring NIO connection handler with 10s sessionless connection timeout, 2 selector thread(s), 16 worker threads, and 64 kB direct buffers.
2020-11-13 14:13:15,727 [myid:] - INFO  [main:NIOServerCnxnFactory@674] - binding to port 0.0.0.0/0.0.0.0:2181
2020-11-13 14:13:15,755 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-11-13 14:13:15,755 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-11-13 14:13:15,756 [myid:] - INFO  [main:ZKDatabase@132] - zookeeper.snapshotSizeFactor = 0.33
2020-11-13 14:13:15,757 [myid:] - INFO  [main:ZKDatabase@152] - zookeeper.commitLogCount=500
2020-11-13 14:13:15,761 [myid:] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
2020-11-13 14:13:15,767 [myid:] - INFO  [main:FileSnap@85] - Reading snapshot D:\zookeeper\data\version-2\snapshot.0
2020-11-13 14:13:15,769 [myid:] - INFO  [main:DataTree@1737] - The digest value is empty in snapshot
2020-11-13 14:13:15,780 [myid:] - INFO  [main:FileTxnSnapLog@363] - 8 txns loaded in 3 ms
2020-11-13 14:13:15,780 [myid:] - INFO  [main:ZKDatabase@289] - Snapshot loaded in 22 ms, highest zxid is 0x8, digest is 1371985504
2020-11-13 14:13:15,781 [myid:] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x8 to D:\zookeeper\data\version-2\snapshot.8
2020-11-13 14:13:15,782 [myid:] - INFO  [main:ZooKeeperServer@529] - Snapshot taken in 2 ms
2020-11-13 14:13:15,790 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@136] - PrepRequestProcessor (sid:0) started, reconfigEnabled=false
2020-11-13 14:13:15,790 [myid:] - INFO  [main:RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000
2020-11-13 14:13:15,802 [myid:] - INFO  [main:ContainerManager@83] - Using checkIntervalMs=60000 maxPerMinute=10000 maxNeverUsedIntervalMs=0
2020-11-13 14:13:15,802 [myid:] - INFO  [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.

伪集群模式部署

伪集群模式就是在同一主机启动多个zookeeper并组成集群

1、在同一个主机上,通过复制得到三个zookeeper实例

  • zookeeper-3.6.2-12181
  • zookeeper-3.6.2-12182
  • zookeeper-3.6.2-12183

2、对三个zookeeper节点进行配置
zookeeper1配置文件/conf/zoo.cfg修改如下:

tickTime=2000
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\data\\zookeeper-cluster\\zookeeper-3.6.2-12181\\data
clientPort=12181

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

注:server.1中的数字1为服务器的ID,需要与data/myid文件中的id一致

zookeeper2配置文件/conf/zoo.cfg修改如下:

tickTime=2000
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\data\\zookeeper-cluster\\zookeeper-3.6.2-12182\\data
clientPort=12182

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

zookeeper3配置文件/conf/zoo.cfg修改如下:

tickTime=2000
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\data\\zookeeper-cluster\\zookeeper-3.6.2-12183\\data
clientPort=12183

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.3=127.0.0.1:16888:17888

3、分别启动三个zookeeper节点

集群模式部署

集群模式就是在不同主机上安装zookeeper然后组成集群的模式,可以参考伪集群模式安装

1、在三台机器上分别部署1个ZooKeeper实例
2、zookeeper配置文件conf/zoo.cfg,如下:

tickTime=2000
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\data
clientPort=2181

server.1=127.0.0.1:2888:3888
server.2=127.0.0.2:2888:3888
server.3=127.0.0.3:2888:3888

3、zookeeper的data/myid配置,使用如下命令:
当然zookeeper1 对应的是 1,zookeeper2 对应的是 2,zookeeper3 对应的是 3
4、分别启动三个zookeeper节点,即完成对ZooKeeper集群的安装

Zookeeper简单操作

1、使用客户端连接Zookeeper服务。
在bin目录下执行

zkCli.cmd -server 127.0.0.1:2181

就可以了,如下:

D:\zookeeper\apache-zookeeper-3.6.2-bin\bin>zkCli.cmd -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2020-11-13 14:15:07,950 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.6.2--803c7f1a12f85978cb049af5e4ef23bd8b688715, built on 09/04/2020 12:44 GMT
2020-11-13 14:15:07,952 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ecs-a0e1-0001
2020-11-13 14:15:07,952 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_144
2020-11-13 14:15:07,954 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2020-11-13 14:15:07,954 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=C:\Java\jre1.8.0_144
2020-11-13 14:15:07,954 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\classes;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\build\lib\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\*;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\audience-annotations-0.5.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\commons-cli-1.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\commons-lang-2.6.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-annotations-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-core-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jackson-databind-2.10.3.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\javax.servlet-api-3.1.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-http-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-io-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-security-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-server-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-servlet-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jetty-util-9.4.24.v20191120.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\jline-2.14.6.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\json-simple-1.1.1.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\log4j-1.2.17.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\metrics-core-3.2.5.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-buffer-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-codec-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-common-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-handler-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-resolver-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-native-epoll-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\netty-transport-native-unix-common-4.1.50.Final.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_common-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_hotspot-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\simpleclient_servlet-0.6.0.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\slf4j-api-1.7.25.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\slf4j-log4j12-1.7.25.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\snappy-java-1.1.7.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-jute-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\lib\zookeeper-prometheus-metrics-3.6.2.jar;D:\zookeeper\apache-zookeeper-3.6.2-bin\bin\..\conf
2020-11-13 14:15:07,954 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=C:\Java\jre1.8.0_144\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Python39\Scripts\;C:\Python39\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs;D:\nodejs\node_global;C:\Program Files\Git\cmd;C:\Java\jre1.8.0_144\bin;C:\Redis\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm;D:\nodejs\node_global;C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin;C:\Java\jre1.8.0_144\bin;.
2020-11-13 14:15:07,955 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\2\
2020-11-13 14:15:07,956 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2020-11-13 14:15:07,956 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Windows Server 2016
2020-11-13 14:15:07,957 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2020-11-13 14:15:07,957 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=10.0
2020-11-13 14:15:07,958 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=Administrator
2020-11-13 14:15:07,958 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=C:\Users\Administrator
2020-11-13 14:15:07,959 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=D:\zookeeper\apache-zookeeper-3.6.2-bin\bin
2020-11-13 14:15:07,959 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=236MB
2020-11-13 14:15:07,960 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=3641MB
2020-11-13 14:15:07,961 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=245MB
2020-11-13 14:15:07,966 [myid:] - INFO  [main:ZooKeeper@1006] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@41a4555e
2020-11-13 14:15:07,970 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2020-11-13 14:15:08,050 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2020-11-13 14:15:08,056 [myid:] - INFO  [main:ClientCnxn@1716] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2020-11-13 14:15:08,061 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1167] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181.
2020-11-13 14:15:08,061 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1169] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-11-13 14:15:08,063 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@999] - Socket connection established, initiating session, client: /127.0.0.1:56145, server: 127.0.0.1/127.0.0.1:2181
JLine support is enabled
2020-11-13 14:15:08,077 [myid:127.0.0.1:2181] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1433] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, session id = 0x10095960df40000, negotiated timeout = 30000

WATCHER::

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

2、在客户端使用ls命令来查看当前Zookeeper中所包含的内容:

  • 命令:ls /
[zk: 127.0.0.1:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 1]

3、创建一个新的znode节点“zk"以及与它关联的字符串

  • 命令:create zk/ myData
[zk: 127.0.0.1:2181(CONNECTED) 1] create /zk myData
Created /zk
[zk: 127.0.0.1:2181(CONNECTED) 2] ls /
[zk, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3]

4、获取znode节点"zk"

  • 命令:get /zk
[zk: 127.0.0.1:2181(CONNECTED) 3] get /zk
myData
[zk: 127.0.0.1:2181(CONNECTED) 4]

5、删除znode节点"zk"

  • 命令:delete /zk
[zk: 127.0.0.1:2181(CONNECTED) 4] delete /zk
[zk: 127.0.0.1:2181(CONNECTED) 5]

6、退出客户端

  • 命令:quit
[zk: 127.0.0.1:2181(CONNECTED) 5] quit

WATCHER::

WatchedEvent state:Closed type:None path:null
2020-11-13 14:27:42,998 [myid:] - INFO  [main:ZooKeeper@1619] - Session: 0x10095960df40000 closed
2020-11-13 14:27:42,998 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@577] - EventThread shut down for session: 0x10095960df40000
2020-11-13 14:27:43,000 [myid:] - ERROR [main:ServiceUtils@42] - Exiting JVM with code 0
D:\zookeeper\apache-zookeeper-3.6.2-bin\bin>
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页