分享

ZooKeeper伪分步式集群安装及java编程命令操作

目录
  • zookeeper介绍
  • zookeeper单节点安装
  • zookeeper伪分布式集群安装
  • zookeeper命令行操作
  • Java编程现实命令行操作

1. zookeeper介绍ZooKeeper是一个为分布式应用所设计的分布的、开源的协调服务,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,简化分布式应用协调及其管理的难度,提供高性能的分布式服务。ZooKeeper本身可以以Standalone模式安装运行,不过它的长处在于通过分布式ZooKeeper集群(一个Leader,多个Follower),基于一定的策略来保证ZooKeeper集群的稳定性和可用性,从而实现分布式应用的可靠性。
ZooKeeper是作为分布式协调服务,是不需要依赖于Hadoop的环境,也可以为其他的分布式环境提供服务。


2. zookeeper单节点安装Standalones模式系统环境:
  • Linux Ubuntu 12.04.2 LTS 64bit server
  • Java: 1.6.0_29 64-Bit Server VM
  1. ~ uname -a
  2. Linux conan 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  3. ~ cat /etc/issue
  4. Ubuntu 12.04.2 LTS \n \l
  5. ~ java -version
  6. java version "1.6.0_29"
  7. Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
  8. Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)
复制代码
[size=12.727272033691406px]下载zookeeper
  1. ~ mkdir /home/conan/toolkit
  2. ~ cd /home/conan/toolkit
  3. ~ wget http://apache.dataguru.cn/zookeeper/stable/zookeeper-3.4.5.tar.gz
  4. ~ tar xvf zookeeper-3.4.5.tar.gz
  5. ~ mv zookeeper-3.4.5 zookeeper345
  6. ~ cd zookeeper345
  7. ~ ls -l
  8. drwxr-xr-x  2 conan conan    4096 Aug 12 04:34 bin
  9. -rw-r--r--  1 conan conan   75988 Aug 12 04:34 build.xml
  10. -rw-r--r--  1 conan conan   70223 Aug 12 04:34 CHANGES.txt
  11. drwxr-xr-x  2 conan conan    4096 Aug 12 04:34 conf
  12. drwxr-xr-x 10 conan conan    4096 Aug 12 04:34 contrib
  13. drwxr-xr-x  2 conan conan    4096 Aug 12 04:34 dist-maven
  14. drwxr-xr-x  6 conan conan    4096 Aug 12 04:34 docs
  15. -rw-r--r--  1 conan conan    1953 Aug 12 04:34 ivysettings.xml
  16. -rw-r--r--  1 conan conan    3120 Aug 12 04:34 ivy.xml
  17. drwxr-xr-x  4 conan conan    4096 Aug 12 04:34 lib
  18. -rw-r--r--  1 conan conan   11358 Aug 12 04:34 LICENSE.txt
  19. -rw-r--r--  1 conan conan     170 Aug 12 04:34 NOTICE.txt
  20. -rw-r--r--  1 conan conan    1770 Aug 12 04:34 README_packaging.txt
  21. -rw-r--r--  1 conan conan    1585 Aug 12 04:34 README.txt
  22. drwxr-xr-x  5 conan conan    4096 Aug 12 04:34 recipes
  23. drwxr-xr-x  8 conan conan    4096 Aug 12 04:34 src
  24. -rw-r--r--  1 conan conan 1315806 Aug 12 04:34 zookeeper-3.4.5.jar
  25. -rw-r--r--  1 conan conan     833 Aug 12 04:34 zookeeper-3.4.5.jar.asc
  26. -rw-r--r--  1 conan conan      33 Aug 12 04:34 zookeeper-3.4.5.jar.md5
  27. -rw-r--r--  1 conan conan      41 Aug 12 04:34 zookeeper-3.4.5.jar.sha1
复制代码
修改配置文件conf/zoo.cfg

  1. ~ mkdir /home/conan/zoo/zk0
  2. ~ cp conf/zoo_sample.cfg conf/zoo.cfg
  3. ~ vi conf/zoo.cfg
  4. ckTime=2000
  5. initLimit=10
  6. syncLimit=5
  7. dataDir=/home/conan/zoo/zk0
  8. clientPort=2181
复制代码
非常简单,我们已经配置好了的zookeeper单节点

启动zookeeper
  1. ~ bin/zkServer.sh
  2. JMX enabled by default
  3. Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg
  4. Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
  5. conan@conan:~/zoo/zk0/zookeeper345$ bin/zkServer.sh start
  6. JMX enabled by default
  7. Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg
  8. Starting zookeeper ... STARTED
  9. #zk的服务显示为QuorumPeerMain
  10. ~ jps
  11. 5321 QuorumPeerMain
  12. 5338 Jps
  13. #查看运行状态
  14. ~ bin/zkServer.sh status
  15. JMX enabled by default
  16. Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg
  17. Mode: standalone
复制代码
单节点的时,Mode会显示为standalone
停止ZooKeeper服务
  1. ~ bin/zkServer.sh stop
  2. JMX enabled by default
  3. Using config: /home/conan/zoo/zk0/zookeeper345/bin/../conf/zoo.cfg
  4. Stopping zookeeper ... STOPPED
复制代码


3. zookeeper伪分布式集群安装
所谓 “伪分布式集群” 就是在,在一台PC中,启动多个ZooKeeper的实例。“完全分布式集群” 是每台PC,启动一个ZooKeeper实例。
由于我的测试环境PC数量有限,所以在一台PC中,启动3个ZooKeeper的实例。
创建环境目录
  1. ~ mkdir /home/conan/zoo/zk1
  2. ~ mkdir /home/conan/zoo/zk2
  3. ~ mkdir /home/conan/zoo/zk3
  4. #新建myid文件
  5. ~ echo "1" > /home/conan/zoo/zk1/myid
  6. ~ echo "2" > /home/conan/zoo/zk2/myid
  7. ~ echo "3" > /home/conan/zoo/zk3/myid
复制代码
分别修改配置文件
修改:dataDir,clientPort
增加:集群的实例,server.X,”X”表示每个目录中的myid的值
  1. ~ vi /home/conan/toolkit/zookeeper345/conf/zk1.cfg
  2. ckTime=2000
  3. initLimit=10
  4. syncLimit=5
  5. dataDir=/home/conan/zoo/zk1
  6. clientPort=2181
  7. server.1=192.168.1.201:2888:3888
  8. server.2=192.168.1.201:2889:3889
  9. server.3=192.168.1.201:2890:3890
  10. ~ vi /home/conan/toolkit/zookeeper345/conf/zk2.cfg
  11. ckTime=2000
  12. initLimit=10
  13. syncLimit=5
  14. dataDir=/home/conan/zoo/zk2
  15. clientPort=2182
  16. server.1=192.168.1.201:2888:3888
  17. server.2=192.168.1.201:2889:3889
  18. server.3=192.168.1.201:2890:3890
  19. ~ vi /home/conan/toolkit/zookeeper345/conf/zk3.cfg
  20. tickTime=2000
  21. initLimit=10
  22. syncLimit=5
  23. dataDir=/home/conan/zoo/zk3
  24. clientPort=2183
  25. server.1=192.168.1.201:2888:3888
  26. server.2=192.168.1.201:2889:3889
  27. server.3=192.168.1.201:2890:3890
复制代码
3个节点的ZooKeeper集群配置完成,接下来我们的启动服务。
启动集群
  1. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk1.cfg
  2. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk2.cfg
  3. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh start zk3.cfg
  4. ~ jps
  5. 5422 QuorumPeerMain
  6. 5395 QuorumPeerMain
  7. 5463 QuorumPeerMain
  8. 5494 Jps
  9. #查看节点状态
  10. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk1.cfg
  11. JMX enabled by default
  12. Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk1.cfg
  13. Mode: follower
  14. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk2.cfg
  15. JMX enabled by default
  16. Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk2.cfg
  17. Mode: leader
  18. ~ /home/conan/toolkit/zookeeper345/bin/zkServer.sh status zk3.cfg
  19. JMX enabled by default
  20. Using config: /home/conan/toolkit/zookeeper345/bin/../conf/zk3.cfg
  21. Mode: follower
复制代码
我们可以看到zk2是leader,zk1和zk3是follower
查看ZooKeeper物理文件目录结构
  1. ~ tree  -L 3 /home/conan/zoo
  2. /home/conan/zoo
  3. ├── zk0
  4. ├── zk1
  5. │   ├── myid
  6. │   ├── version-2
  7. │   │   ├── acceptedEpoch
  8. │   │   ├── currentEpoch
  9. │   │   ├── log.100000001
  10. │   │   └── snapshot.0
  11. │   └── zookeeper_server.pid
  12. ├── zk2
  13. │   ├── myid
  14. │   ├── version-2
  15. │   │   ├── acceptedEpoch
  16. │   │   ├── currentEpoch
  17. │   │   ├── log.100000001
  18. │   │   └── snapshot.0
  19. │   └── zookeeper_server.pid
  20. └── zk3
  21.     ├── myid
  22.     ├── version-2
  23.     │   ├── acceptedEpoch
  24.     │   ├── currentEpoch
  25.     │   ├── log.100000001
  26.     │   └── snapshot.100000000
  27.     └── zookeeper_server.pid
  28. 7 directories, 18 files
复制代码


4. zookeeper命令行操作
我们通过客户端连接ZooKeeper的集群,我们可以任意的zookeeper是进行连接。
  1. ~ /home/conan/toolkit/zookeeper345/bin/zkCli.sh -server 192.168.1.201:2181
  2. Connecting to 192.168.1.201
  3. 2013-08-12 05:25:39,260 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
  4. 2013-08-12 05:25:39,267 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=conan
  5. 2013-08-12 05:25:39,269 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.6.0_29
  6. 2013-08-12 05:25:39,269 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Sun Microsystems Inc.
  7. 2013-08-12 05:25:39,270 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/home/conan/toolkit/jdk16/jre
  8. 2013-08-12 05:25:39,270 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/conan/toolkit/zookeeper345/bin/../build/classes:/home/conan/toolkit/zookeeper345/bin/../build/lib/*.jar:/home/conan/toolkit/zookeeper345/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/conan/toolkit/zookeeper345/bin/../lib/slf4j-api-1.6.1.jar:/home/conan/toolkit/zookeeper345/bin/../lib/netty-3.2.2.Final.jar:/home/conan/toolkit/zookeeper345/bin/../lib/log4j-1.2.15.jar:/home/conan/toolkit/zookeeper345/bin/../lib/jline-0.9.94.jar:/home/conan/toolkit/zookeeper345/bin/../zookeeper-3.4.5.jar:/home/conan/toolkit/zookeeper345/bin/../src/java/lib/*.jar:/home/conan/toolkit/zookeeper345/bin/../conf:
  9. 2013-08-12 05:25:39,271 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/home/conan/toolkit/jdk16/jre/lib/amd64/server:/home/conan/toolkit/jdk16/jre/lib/amd64:/home/conan/toolkit/jdk16/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
  10. 2013-08-12 05:25:39,275 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
  11. 2013-08-12 05:25:39,276 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
  12. 2013-08-12 05:25:39,276 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
  13. 2013-08-12 05:25:39,277 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
  14. 2013-08-12 05:25:39,281 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.5.0-23-generic
  15. 2013-08-12 05:25:39,282 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=conan
  16. 2013-08-12 05:25:39,282 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/conan
  17. 2013-08-12 05:25:39,283 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/conan/zoo
  18. 2013-08-12 05:25:39,284 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=192.168.1.201 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@22ba6c83
  19. Welcome to ZooKeeper!
  20. JLine support is enabled
  21. [zk: 192.168.1.201(CONNECTING) 0] 2013-08-12 05:25:39,336 [myid:] - INFO  [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@966] - Opening socket connection to server 192.168.1.201/192.168.1.201:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration)
  22. 2013-08-12 05:25:39,345 [myid:] - INFO  [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@849] - Socket connection established to 192.168.1.201/192.168.1.201:2181, initiating session
  23. 2013-08-12 05:25:39,384 [myid:] - INFO  [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@1207] - Session establishment complete on server 192.168.1.201/192.168.1.201:2181, sessionid = 0x1406f3c1ef90001, negotiated timeout = 30000
  24. WATCHER::
  25. WatchedEvent state:SyncConnected type:None path:null
  26. [zk: 192.168.1.201(CONNECTED) 0]
复制代码
集群已连接,下面我们要使用一下,ZooKeeper的命令行操作。
命令行操作
通过help打印命令行帮助
  1. [zk: 192.168.1.201(CONNECTED) 1] help
  2. ZooKeeper -server host:port cmd args
  3.         connect host:port
  4.         get path [watch]
  5.         ls path [watch]
  6.         set path data [version]
  7.         rmr path
  8.         delquota [-n|-b] path
  9.         quit
  10.         printwatches on|off
  11.         create [-s] [-e] path data acl
  12.         stat path [watch]
  13.         close
  14.         ls2 path [watch]
  15.         history
  16.         listquota path
  17.         setAcl path acl
  18.         getAcl path
  19.         sync path
  20.         redo cmdno
  21.         addauth scheme auth
  22.         delete path [version]
  23.         setquota -n|-b val path
复制代码
ZooKeeper的结构,很像是目录结构,我们看到了像ls这样熟悉的命令。
  1. #ls,查看/目录内容
  2. [zk: 192.168.1.201(CONNECTED) 1] ls /
  3. [zookeeper]
  4. #create,创建一个znode节点
  5. [zk: 192.168.1.201(CONNECTED) 2] create /node conan
  6. Created /node
  7. #ls,再查看/目录
  8. [zk: 192.168.1.201(CONNECTED) 3] ls /
  9. [node, zookeeper]
  10. #get,查看/node的数据信息
  11. [zk: 192.168.1.201(CONNECTED) 4] get /node
  12. conan
  13. cZxid = 0x100000006
  14. ctime = Mon Aug 12 05:32:49 CST 2013
  15. mZxid = 0x100000006
  16. mtime = Mon Aug 12 05:32:49 CST 2013
  17. pZxid = 0x100000006
  18. cversion = 0
  19. dataVersion = 0
  20. aclVersion = 0
  21. ephemeralOwner = 0x0
  22. dataLength = 5
  23. numChildren = 0
  24. #set,修改数据
  25. [zk: 192.168.1.201(CONNECTED) 5] set /node fens.me
  26. cZxid = 0x100000006
  27. ctime = Mon Aug 12 05:32:49 CST 2013
  28. mZxid = 0x100000007
  29. mtime = Mon Aug 12 05:34:32 CST 2013
  30. pZxid = 0x100000006
  31. cversion = 0
  32. dataVersion = 1
  33. aclVersion = 0
  34. ephemeralOwner = 0x0
  35. dataLength = 7
  36. numChildren = 0
  37. #get,再查看/node的数据信息,已改为fens.me
  38. [zk: 192.168.1.201(CONNECTED) 6] get /node
  39. fens.me
  40. cZxid = 0x100000006
  41. ctime = Mon Aug 12 05:32:49 CST 2013
  42. mZxid = 0x100000007
  43. mtime = Mon Aug 12 05:34:32 CST 2013
  44. pZxid = 0x100000006
  45. cversion = 0
  46. dataVersion = 1
  47. aclVersion = 0
  48. ephemeralOwner = 0x0
  49. dataLength = 7
  50. numChildren = 0
  51. #delete,删除/node
  52. [zk: 192.168.1.201(CONNECTED) 7] delete /node
  53. [zk: 192.168.1.201(CONNECTED) 8] ls /
  54. [zookeeper]
  55. #quit,退出客户端连接
  56. [zk: 192.168.1.201(CONNECTED) 19] quit
  57. Quitting...
  58. 2013-08-12 05:40:29,304 [myid:] - INFO  [main:ZooKeeper@684] - Session: 0x1406f3c1ef90002 closed
  59. 2013-08-12 05:40:29,305 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@509] - EventThread shut down
复制代码

5. Java编程现实命令行操作
  1. package org.conan.zookeeper.demo;
  2. import java.io.IOException;
  3. import org.apache.zookeeper.CreateMode;
  4. import org.apache.zookeeper.KeeperException;
  5. import org.apache.zookeeper.WatchedEvent;
  6. import org.apache.zookeeper.Watcher;
  7. import org.apache.zookeeper.ZooDefs.Ids;
  8. import org.apache.zookeeper.ZooKeeper;
  9. public class BasicDemo1 {
  10.     public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
  11.         // 创建一个与服务器的连接
  12.         ZooKeeper zk = new ZooKeeper("192.168.1.201:2181", 60000, new Watcher() {
  13.             // 监控所有被触发的事件
  14.             public void process(WatchedEvent event) {
  15.                 System.out.println("EVENT:" + event.getType());
  16.             }
  17.         });
  18.         // 查看根节点
  19.         System.out.println("ls / => " + zk.getChildren("/", true));
  20.         // 创建一个目录节点
  21.         if (zk.exists("/node", true) == null) {
  22.             zk.create("/node", "conan".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  23.             System.out.println("create /node conan");
  24.             // 查看/node节点数据
  25.             System.out.println("get /node => " + new String(zk.getData("/node", false, null)));
  26.             // 查看根节点
  27.             System.out.println("ls / => " + zk.getChildren("/", true));
  28.         }
  29.         // 创建一个子目录节点
  30.         if (zk.exists("/node/sub1", true) == null) {
  31.             zk.create("/node/sub1", "sub1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  32.             System.out.println("create /node/sub1 sub1");
  33.             // 查看node节点
  34.             System.out.println("ls /node => " + zk.getChildren("/node", true));
  35.         }
  36.         // 修改节点数据
  37.         if (zk.exists("/node", true) != null) {
  38.             zk.setData("/node", "changed".getBytes(), -1);
  39.             // 查看/node节点数据
  40.             System.out.println("get /node => " + new String(zk.getData("/node", false, null)));
  41.         }
  42.         // 删除节点
  43.         if (zk.exists("/node/sub1", true) != null) {
  44.             zk.delete("/node/sub1", -1);
  45.             zk.delete("/node", -1);
  46.             // 查看根节点
  47.             System.out.println("ls / => " + zk.getChildren("/", true));
  48.         }
  49.         // 关闭连接
  50.         zk.close();
  51.     }
  52. }
复制代码
运行结果:
  1. 2013-08-12 15:33:29,699 [myid:] - INFO  [main:Environment@97] - Client environment:zookeeper.version=3.3.1-942149, built on 05/07/2010 17:14 GMT
  2. 2013-08-12 15:33:29,702 [myid:] - INFO  [main:Environment@97] - Client environment:host.name=PC201304202140
  3. 2013-08-12 15:33:29,702 [myid:] - INFO  [main:Environment@97] - Client environment:java.version=1.6.0_45
  4. 2013-08-12 15:33:29,702 [myid:] - INFO  [main:Environment@97] - Client environment:java.vendor=Sun Microsystems Inc.
  5. 2013-08-12 15:33:29,702 [myid:] - INFO  [main:Environment@97] - Client environment:java.home=D:\toolkit\java\jdk6\jre
  6. 2013-08-12 15:33:29,703 [myid:] - INFO  [main:Environment@97] - Client environment:java.class.path=D:\workspace\java\zkdemo\target\classes;C:\Users\Administrator\.m2\repository\org\apache\hadoop\zookeeper\3.3.1\zookeeper-3.3.1.jar;C:\Users\Administrator\.m2\repository\log4j\log4j\1.2.15\log4j-1.2.15.jar;C:\Users\Administrator\.m2\repository\javax\mail\mail\1.4\mail-1.4.jar;C:\Users\Administrator\.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\Administrator\.m2\repository\jline\jline\0.9.94\jline-0.9.94.jar;C:\Users\Administrator\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar
  7. 2013-08-12 15:33:29,703 [myid:] - INFO  [main:Environment@97] - Client environment:java.library.path=D:\toolkit\java\jdk6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\toolkit\Rtools\bin;D:\toolkit\Rtools\gcc-4.6.3\bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\toolkit\Git\cmd;D:\toolkit\Git\bin;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\QuickTime\QTSystem\;D:\toolkit\MiKTex\miktex\bin\x64\;D:\toolkit\sshclient;D:\toolkit\ant19\bin;D:\toolkit\eclipse;D:\toolkit\gradle15\bin;D:\toolkit\java\jdk6\bin;D:\toolkit\maven3\bin;D:\toolkit\mysql56\bin;D:\toolkit\python27;D:\toolkit\putty;C:\Program Files\R\R-3.0.1\bin\x64;D:\toolkit\mongodb243\bin;D:\toolkit\php54;D:\toolkit\nginx140;D:\toolkit\nodejs;D:\toolkit\npm12\bin;D:\toolkit\java\jdk6\jre\bin\server;.
  8. 2013-08-12 15:33:29,703 [myid:] - INFO  [main:Environment@97] - Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
  9. 2013-08-12 15:33:29,704 [myid:] - INFO  [main:Environment@97] - Client environment:java.compiler=
  10. 2013-08-12 15:33:29,704 [myid:] - INFO  [main:Environment@97] - Client environment:os.name=Windows 7
  11. 2013-08-12 15:33:29,704 [myid:] - INFO  [main:Environment@97] - Client environment:os.arch=amd64
  12. 2013-08-12 15:33:29,705 [myid:] - INFO  [main:Environment@97] - Client environment:os.version=6.1
  13. 2013-08-12 15:33:29,705 [myid:] - INFO  [main:Environment@97] - Client environment:user.name=Administrator
  14. 2013-08-12 15:33:29,705 [myid:] - INFO  [main:Environment@97] - Client environment:user.home=C:\Users\Administrator
  15. 2013-08-12 15:33:29,706 [myid:] - INFO  [main:Environment@97] - Client environment:user.dir=D:\workspace\java\zkdemo
  16. 2013-08-12 15:33:29,707 [myid:] - INFO  [main:ZooKeeper@373] - Initiating client connection, connectString=192.168.1.201:2181 sessionTimeout=60000 watcher=org.conan.zookeeper.demo.BasicDemo1$1@3dfeca64
  17. 2013-08-12 15:33:29,731 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@1000] - Opening socket connection to server /192.168.1.201:2181
  18. 2013-08-12 15:33:38,736 [myid:] - INFO  [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@908] - Socket connection established to 192.168.1.201/192.168.1.201:2181, initiating session
  19. 2013-08-12 15:33:38,804 [myid:] - INFO  [main-SendThread(192.168.1.201:2181):ClientCnxn$SendThread@701] - Session establishment complete on server 192.168.1.201/192.168.1.201:2181, sessionid = 0x1406f3c1ef9000d, negotiated timeout = 60000
  20. EVENT:None
  21. ls / => [zookeeper]
  22. EVENT:NodeCreated
  23. EVENT:NodeChildrenChanged
  24. create /node conan
  25. get /node => conan
  26. ls / => [node, zookeeper]
  27. EVENT:NodeCreated
  28. create /node/sub1 sub1
  29. ls /node => [sub1]
  30. EVENT:NodeDataChanged
  31. get /node => changed
  32. EVENT:NodeDeleted
  33. EVENT:NodeChildrenChanged
  34. EVENT:NodeChildrenChanged
  35. ls / => [zookeeper]
  36. 2013-08-12 15:33:38,877 [myid:] - INFO  [main:ZooKeeper@538] - Session: 0x1406f3c1ef9000d closed
复制代码
pom.xml,maven配置文件
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  4. xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>org.conan.zookeeper</groupId>
  7. <artifactId>zkdemo</artifactId>
  8. <version>0.0.1</version>
  9. <name>zkdemo</name>
  10. <description>zkdemo</description>
  11. <dependencies>
  12. <dependency>
  13. <groupId>org.apache.hadoop</groupId>
  14. <artifactId>zookeeper</artifactId>
  15. <version>3.3.1</version>
  16. <exclusions>
  17. <exclusion>
  18. <groupId>javax.jms</groupId>
  19. <artifactId>jms</artifactId>
  20. </exclusion>
  21. <exclusion>
  22. <groupId>com.sun.jdmk</groupId>
  23. <artifactId>jmxtools</artifactId>
  24. </exclusion>
  25. <exclusion>
  26. <groupId>com.sun.jmx</groupId>
  27. <artifactId>jmxri</artifactId>
  28. </exclusion>
  29. </exclusions>
  30. </dependency>
  31. </dependencies>
  32. </project>
复制代码







没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条