1. 概述
ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
2. 安装&配置
在apache的官方网站提供了好多镜像下载地址,然后找到对应的版本,目前最新的是3.3.6
下载地址:
http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
2.1windows安装
把下载的zookeeper的文件解压到指定目录
D:\machine\zookeeper-3.3.6>
解压后的目录查看
D:\machine\zookeeper-3.3.6>dir
驱动器 D 中的卷是 软件
卷的序列号是000F-1D4F
D:\machine\zookeeper-3.3.6 的目录
2014/04/01 12:19 <DIR> .
2014/04/01 12:19 <DIR> ..
2012/07/29 14:24 <DIR> bin
2012/07/29 14:23 59,687 build.xml
2012/07/29 14:23 52,566CHANGES.txt
2012/07/29 14:24 <DIR> conf
2012/07/29 14:23 <DIR> contrib
2012/07/29 14:26 <DIR> dist-maven
2012/07/29 14:24 <DIR> docs
2012/07/29 14:23 2,415 ivy.xml
2012/07/29 14:23 1,932ivysettings.xml
2012/07/29 14:24 <DIR> lib
2012/07/29 14:23 11,358LICENSE.txt
2012/07/29 14:23 165 NOTICE.txt
2012/07/29 14:23 1,578 README.txt
2012/07/29 14:23 <DIR> recipes
2012/07/29 14:24 <DIR> src
2012/07/29 14:23 1,031,338zookeeper-3.3.6.jar
2012/07/29 14:25 198zookeeper-3.3.6.jar.asc
2012/07/29 14:23 33 zookeeper-3.3.6.jar.md5
2012/07/29 14:23 41zookeeper-3.3.6.jar.sha1
11 个文件 1,161,311 字节
10 个目录 103,371,341,824 可用字节
修改conf下增加一个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 anacknowledgement
syncLimit=5
# the directory where the snapshot isstored. //镜像数据位置
dataDir=D:\\data\\zookeeper
#日志位置
dataLogDir=D:\\logs\\zookeeper
# the port at which the clients willconnect 客户端连接的端口
clientPort=2181
进入到bin目录,并且启动zkServer.cmd,这个脚本中会启动一个java进程
D:\machine\zookeeper-3.3.6>cd bin
D:\machine\zookeeper-3.3.6\bin>
D:\machine\zookeeper-3.3.6\bin >zkServer.cmd
D:\machine\zookeeper-3.3.6\bin>java"-Dzookeeper.log.dir=D:\machine\zookeeper-3.3.6\bin\..""-Dzookeeper.root.logger=INFO,CONSOLE" -cp"D:\machine\zookeeper-3.3.6\bin\..\build\classes;D:\machine\zookeeper-3.3.6\bin\..\build\lib\*;D:\machine
\zookeeper-3.3.6\bin\..\*;D:\machine\zookeeper-3.3.6\bin\..\lib\*;D:\machine\zookeeper-3.3.6\bin\..\conf"org.apache.zookeeper.server.quorum.QuorumPeerMain"D:\machine\zookeeper-3.3.6\bin\..\conf\zoo.cfg"
2014-04-01 12:35:47,739 - INFO [main:QuorumPeerConfig@90] - Readingconfiguration from: D:\machine\zookeeper-3.3.6\bin\..\conf\zoo.cfg
2014-04-01 12:35:47,747 - WARN [main:QuorumPeerMain@105] - Either no configor no quorum defined in config, running in standalone mode
2014-04-01 12:35:47,896 - INFO [main:QuorumPeerConfig@90] - Readingconfiguration from: D:\machine\zookeeper-3.3.6\bin\..\conf\zoo.cfg
2014-04-01 12:35:47,897 - INFO [main:ZooKeeperServerMain@94] - Startingserver
2014-04-01 12:35:47,958 - INFO [main:Environment@97] - Serverenvironment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT
2014-04-01 12:35:47,959 - INFO [main:Environment@97] - Serverenvironment:host.name=houchangren.ds.gome.com.cn
2014-04-01 12:35:47,959 - INFO [main:Environment@97] - Serverenvironment:java.version=1.6.0_26
2014-04-01 12:35:47,960 - INFO [main:Environment@97] - Serverenvironment:java.vendor=Sun Microsystems Inc.
2014-04-01 12:35:47,961 - INFO [main:Environment@97] - Server environment:java.home=D:\ProgramFiles\Java\jre6
2014-04-01 12:35:47,965 - INFO [main:Environment@97] - Serverenvironment:java.class.path=D:\machine\zookeeper-3.3.6\bin\..\build\classes;D:\machine\zookeeper-3.3.6\bin\..\build\lib\*;D:\machine\zookeeper-3.3.6\bin\..\zookeeper-3.3.6.jar;D
:\machine\zookeeper-3.3.6\bin\..\lib\jline-0.9.94.jar;D:\machine\zookeeper-3.3.6\bin\..\lib\log4j-1.2.15.jar;D:\machine\zookeeper-3.3.6\bin\..\conf
2014-04-01 12:35:47,968 - INFO [main:Environment@97] - Serverenvironment:java.library.path=C:\Windows\system32;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramFiles (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system
32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\ProgramFiles\Java\jdk1.6.0_26\bin;D:\application\apache-maven-3.1.0\bin;D:\application\TortoiseSVN\bin;D:\application\SlikSvn\bin;D:\application\IDMComp
uter Solutions\UltraEdit\;.
2014-04-01 12:35:47,972 - INFO [main:Environment@97] - Serverenvironment:java.io.tmpdir=C:\Users\HOUCHA~1\AppData\Local\Temp\
2014-04-01 12:35:47,981 - INFO [main:Environment@97] - Serverenvironment:java.compiler=<NA>
2014-04-01 12:35:47,991 - INFO [main:Environment@97] - Serverenvironment:os.name=Windows 7
2014-04-01 12:35:47,997 - INFO [main:Environment@97] - Serverenvironment:os.arch=amd64
2014-04-01 12:35:48,000 - INFO [main:Environment@97] - Serverenvironment:os.version=6.1
2014-04-01 12:35:48,004 - INFO [main:Environment@97] - Serverenvironment:user.name=houchangren
2014-04-01 12:35:48,007 - INFO [main:Environment@97] - Serverenvironment:user.home=C:\Users\houchangren
2014-04-01 12:35:48,010 - INFO [main:Environment@97] - Serverenvironment:user.dir=D:\machine\zookeeper-3.3.6\bin
2014-04-01 12:35:48,024 - INFO [main:ZooKeeperServer@673] - tickTime set to2000
2014-04-01 12:35:48,025 - INFO [main:ZooKeeperServer@682] -minSessionTimeout set to -1
2014-04-01 12:35:48,026 - INFO [main:ZooKeeperServer@691] -maxSessionTimeout set to -1
2014-04-01 12:35:48,084 - INFO [main:NIOServerCnxn$Factory@143] - binding toport 0.0.0.0/0.0.0.0:2181
2014-04-01 12:35:48,095 - INFO [main:FileTxnSnapLog@256] - Snapshotting: 0
启动后jps可以看到QuorumPeerMain的进程
C:\Users\houchangren>jps
908 QuorumPeerMain
916 Jps
4272 org.eclipse.equinox.launcher_1.2.0.v20110502.jar
启动客户端运行查看一下
D:\machine\zookeeper-3.3.6\bin>zkCli.cmd-server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2014-04-01 12:39:53,744 - INFO [main:Environment@97] - Clientenvironment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT
2014-04-01 12:39:53,746 - INFO [main:Environment@97] - Clientenvironment:host.name=houchangren.ds.gome.com.cn
2014-04-01 12:39:53,747 - INFO [main:Environment@97] - Clientenvironment:java.version=1.6.0_26
2014-04-01 12:39:53,749 - INFO [main:Environment@97] - Clientenvironment:java.vendor=Sun Microsystems Inc.
2014-04-01 12:39:53,750 - INFO [main:Environment@97] - Clientenvironment:java.home=D:\Program Files\Java\jre6
2014-04-01 12:39:53,751 - INFO [main:Environment@97] - Client environment:java.class.path=D:\machine\zookeeper-3.3.6\bin\..\build\classes;D:\machine\zookeeper-3.3.6\bin\..\build\lib\*;D:\machine\zookeeper-3.3.6\bin\..\zookeeper-3.3.6.jar;D
:\machine\zookeeper-3.3.6\bin\..\lib\jline-0.9.94.jar;D:\machine\zookeeper-3.3.6\bin\..\lib\log4j-1.2.15.jar;D:\machine\zookeeper-3.3.6\bin\..\conf
2014-04-01 12:39:53,752 - INFO [main:Environment@97] - Clientenvironment:java.library.path=C:\Windows\system32;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramFiles (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system
32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\ProgramFiles\Java\jdk1.6.0_26\bin;D:\application\apache-maven-3.1.0\bin;D:\application\TortoiseSVN\bin;D:\application\SlikSvn\bin;D:\application\IDMComp
uter Solutions\UltraEdit\;.
2014-04-01 12:39:53,758 - INFO [main:Environment@97] - Clientenvironment:java.io.tmpdir=C:\Users\HOUCHA~1\AppData\Local\Temp\
2014-04-01 12:39:53,760 - INFO [main:Environment@97] - Client environment:java.compiler=<NA>
2014-04-01 12:39:53,764 - INFO [main:Environment@97] - Clientenvironment:os.name=Windows 7
2014-04-01 12:39:53,765 - INFO [main:Environment@97] - Clientenvironment:os.arch=amd64
2014-04-01 12:39:53,766 - INFO [main:Environment@97] - Clientenvironment:os.version=6.1
2014-04-01 12:39:53,767 - INFO [main:Environment@97] - Clientenvironment:user.name=houchangren
2014-04-01 12:39:53,768 - INFO [main:Environment@97] - Clientenvironment:user.home=C:\Users\houchangren
2014-04-01 12:39:53,774 - INFO [main:Environment@97] - Clientenvironment:user.dir=D:\machine\zookeeper-3.3.6\bin
2014-04-01 12:39:53,777 - INFO [main:ZooKeeper@379] - Initiating clientconnection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@a3901c6
Welcome to ZooKeeper!
2014-04-01 12:39:53,798 - INFO [main-SendThread():ClientCnxn$SendThread@1058] - Opening socketconnection to server /127.0.0.1:2181
2014-04-01 12:39:53,818 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn$Factory@251]- Accepted socket connection from /127.0.0.1:58086
2014-04-01 12:39:53,819 - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@947] - Socketconnection established to 127.0.0.1/127.0.0.1:2181, initiating session
2014-04-01 12:39:53,826 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@777] - Clientattempting to establish new session at /127.0.0.1:58086
JLine support is enabled
2014-04-01 12:39:53,828 - INFO [SyncThread:0:FileTxnLog@199] - Creating newlog file: log.1
[zk: 127.0.0.1:2181(CONNECTING) 0]2014-04-01 12:39:53,978 - INFO [SyncThread:0:NIOServerCnxn@1580] - Established session0x1451b925d040000 with negotiated timeout 30000 for client /127.0.0.1:58086
2014-04-01 12:39:53,980 - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@736] - Sessionestablishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid =0x1451b925d040000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:Nonepath:null
[zk: 127.0.0.1:2181(CONNECTED) 0] ls
ZooKeeper -server host:port cmd args
connect host:port
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
create [-s] [-e] path data acl
stat path [watch]
close
ls2 path [watch]
history
listquota path
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]
这个时候zookeeper已经安装成功了,
参考官方文档:
http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html