ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
zookeeper下载地址:
把下载的zookeeper的文件解压到指定目录,进入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
DOS进入到bin目录,并且启动zkServer.cmd,这个脚本中会启动一个java进程:
E:zookeeper-3.3.6in>zkServer.cmd E:zookeeper-3.3.6in>java "-Dzookeeper.log.dir=E:zookeeper-3.3.6in.." "-Dz ookeeper.root.logger=INFO,CONSOLE" -cp "E:zookeeper-3.3.6in..uildclasses; E:zookeeper-3.3.6in..uildlib*;E:zookeeper-3.3.6in..*;E:zookeeper-3 .3.6in..lib*;E:zookeeper-3.3.6in..conf" org.apache.zookeeper.server.qu orum.QuorumPeerMain "E:zookeeper-3.3.6in..confzoo.cfg" 2015-05-29 17:14:42,907 - INFO [main:QuorumPeerConfig@90] - Reading configurati on from: E:zookeeper-3.3.6in..confzoo.cfg 2015-05-29 17:14:42,915 - WARN [main:QuorumPeerMain@105] - Either no config or no quorum defined in config, running in standalone mode 2015-05-29 17:14:42,968 - INFO [main:QuorumPeerConfig@90] - Reading configurati on from: E:zookeeper-3.3.6in..confzoo.cfg 2015-05-29 17:14:42,970 - INFO [main:ZooKeeperServerMain@94] - Starting server 2015-05-29 17:14:42,985 - INFO [main:Environment@97] - Server environment:zooke eper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT 2015-05-29 17:14:42,987 - INFO [main:Environment@97] - Server environment:host. name=DES0097.jiayin.cn 2015-05-29 17:14:42,989 - INFO [main:Environment@97] - Server environment:java. version=1.6.0_35 2015-05-29 17:14:42,990 - INFO [main:Environment@97] - Server environment:java. vendor=Sun Microsystems Inc. 2015-05-29 17:14:42,991 - INFO [main:Environment@97] - Server environment:java. home=D:Program FilesJavajdk1.6.0_35jre 2015-05-29 17:14:42,992 - INFO [main:Environment@97] - Server environment:java. class.path=E:zookeeper-3.3.6in..uildclasses;E:zookeeper-3.3.6in..ui ldlib*;E:zookeeper-3.3.6in..zookeeper-3.3.6.jar;E:zookeeper-3.3.6in.. libjline-0.9.94.jar;E:zookeeper-3.3.6in..liblog4j-1.2.15.jar;E:zookeepe r-3.3.6in..conf 2015-05-29 17:14:42,994 - INFO [main:Environment@97] - Server environment:java. library.path=D:Program FilesJavajdk1.6.0_35in;C:WindowsSunJavain;C:Wi ndowssystem32;C:Windows;D:Program FilesJavajdk1.6.0_35in;D:Program Files Javajdk1.6.0_35jrein;D:apache-maven-3.0.3in;C:Program Files (x86)Intel iCLS Client;C:Program FilesInteliCLS Client;C:Windowssystem32;C:Windows ;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIn tel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelIntel(R) Ma nagement Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelOpenCL SDK3.0inx86;C:Pro gram Files (x86)IntelOpenCL SDK3.0inx64;C:Program FilesTortoiseSVNin;. 2015-05-29 17:14:42,998 - INFO [main:Environment@97] - Server environment:java. io.tmpdir=C:UsersYANTIA~1AppDataLocalTemp 2015-05-29 17:14:42,999 - INFO [main:Environment@97] - Server environment:java. compiler=<NA> 2015-05-29 17:14:43,000 - INFO [main:Environment@97] - Server environment:os.na me=Windows 7 2015-05-29 17:14:43,001 - INFO [main:Environment@97] - Server environment:os.ar ch=amd64 2015-05-29 17:14:43,002 - INFO [main:Environment@97] - Server environment:os.ve rsion=6.1 2015-05-29 17:14:43,003 - INFO [main:Environment@97] - Server environment:user. name=yantianzeng 2015-05-29 17:14:43,004 - INFO [main:Environment@97] - Server environment:user. home=E:yantianzeng 2015-05-29 17:14:43,006 - INFO [main:Environment@97] - Server environment:user. dir=E:zookeeper-3.3.6in 2015-05-29 17:14:43,012 - INFO [main:ZooKeeperServer@673] - tickTime set to 200 0 2015-05-29 17:14:43,013 - INFO [main:ZooKeeperServer@682] - minSessionTimeout s et to -1 2015-05-29 17:14:43,014 - INFO [main:ZooKeeperServer@691] - maxSessionTimeout s et to -1 2015-05-29 17:14:43,049 - INFO [main:NIOServerCnxn$Factory@143] - binding to po rt 0.0.0.0/0.0.0.0:2181 2015-05-29 17:14:43,062 - INFO [main:FileTxnSnapLog@256] - Snapshotting: 0
bin目录下,执行jps可以看到QuorumPeerMain的进程:
E:zookeeper-3.3.6in>jps 7724 Jps 4416 Program 3640 QuorumPeerMain 992 Program
启动客户端运行zkCli.cmd 127.0.0.1:2181查看一下:
E:zookeeper-3.3.6in>zkCli.cmd 127.0.0.1:2181 Connecting to localhost:2181 2015-05-29 17:29:57,966 - INFO [main:Environment@97] - Client environment:zooke eper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT 2015-05-29 17:29:57,970 - INFO [main:Environment@97] - Client environment:host. name=DES0097.jiayin.cn 2015-05-29 17:29:57,971 - INFO [main:Environment@97] - Client environment:java. version=1.6.0_35 2015-05-29 17:29:57,973 - INFO [main:Environment@97] - Client environment:java. vendor=Sun Microsystems Inc. 2015-05-29 17:29:57,974 - INFO [main:Environment@97] - Client environment:java. home=D:Program FilesJavajdk1.6.0_35jre 2015-05-29 17:29:57,975 - INFO [main:Environment@97] - Client environment:java. class.path=E:zookeeper-3.3.6in..uildclasses;E:zookeeper-3.3.6in..ui ldlib*;E:zookeeper-3.3.6in..zookeeper-3.3.6.jar;E:zookeeper-3.3.6in.. libjline-0.9.94.jar;E:zookeeper-3.3.6in..liblog4j-1.2.15.jar;E:zookeepe r-3.3.6in..conf 2015-05-29 17:29:57,977 - INFO [main:Environment@97] - Client environment:java. library.path=D:Program FilesJavajdk1.6.0_35in;C:WindowsSunJavain;C:Wi ndowssystem32;C:Windows;D:Program FilesJavajdk1.6.0_35in;D:Program Files Javajdk1.6.0_35jrein;D:apache-maven-3.0.3in;C:Program Files (x86)Intel iCLS Client;C:Program FilesInteliCLS Client;C:Windowssystem32;C:Windows ;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIn tel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelIntel(R) Ma nagement Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelOpenCL SDK3.0inx86;C:Pro gram Files (x86)IntelOpenCL SDK3.0inx64;C:Program FilesTortoiseSVNin;. 2015-05-29 17:29:57,981 - INFO [main:Environment@97] - Client environment:java. io.tmpdir=C:UsersYANTIA~1AppDataLocalTemp 2015-05-29 17:29:57,983 - INFO [main:Environment@97] - Client environment:java. compiler=<NA> 2015-05-29 17:29:58,020 - INFO [main:Environment@97] - Client environment:os.na me=Windows 7 2015-05-29 17:29:58,022 - INFO [main:Environment@97] - Client environment:os.ar ch=amd64 2015-05-29 17:29:58,024 - INFO [main:Environment@97] - Client environment:os.ve rsion=6.1 2015-05-29 17:29:58,028 - INFO [main:Environment@97] - Client environment:user. name=yantianzeng 2015-05-29 17:29:58,030 - INFO [main:Environment@97] - Client environment:user. home=E:yantianzeng 2015-05-29 17:29:58,055 - INFO [main:Environment@97] - Client environment:user. dir=E:zookeeper-3.3.6in 2015-05-29 17:29:58,060 - INFO [main:ZooKeeper@379] - Initiating client connect ion, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookee per.ZooKeeperMain$MyWatcher@22998b08 ZooKeeper -server host:port cmd args connect host:port get path [watch]2015-05-29 17:29:58,103 - INFO [main-SendThread():Clien tCnxn$SendThread@1058] - Opening socket connection to server localhost/127.0.0.1 :2181 ls path [watch] set path data [version] delquota [-n|-b] path quit printwatches on|off create [-s] [-e] path data acl 2015-05-29 17:29:58,137 - INFO [main-SendThread(localhost:2181):ClientCnxn$Send Thread@947] - Socket connection established to localhost/127.0.0.1:2181, initiat ing session 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
这个时候zookeeper已经安装成功了,