《Hadoop The Definitive Guide》ch13 ZooKeeper

1. 关于ZooKeeper的介绍,http://www.searchtb.com/2011/01/zookeeper-research.html

zookeeper是一个开源分布式的服务,它提供了分布式协作、分布式同步、配置管理等功能。

2. 安装和运行

export ZOOKEEPER_INSTALL=/local/honghaos/zookeeper/zookeeper-3.4.3/
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin

[ate: /local/nomad2/zookeeper/zookeeper-3.4.3/bin ]
>> zkServer.sh start
JMX enabled by default
Using config: /local/nomad2/zookeeper/zookeeper-3.4.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[ate: /local/nomad2/zookeeper/zookeeper-3.4.3/bin ]
>> echo ruok |nc localhost 2181
imok

3. Group操作示例

3.1 create group

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> export CLASSPATH=ch14.jar:$ZOOKEEPER_INSTALL/*:$ZOOKEEPER_INSTALL/lib/*:$ZOOKEEPER_INSTALL/conf
[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java CreateGroup localhost zoo
2012-07-06 22:54:23,172 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 22:54:23,177 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 22:54:23,178 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 22:54:23,178 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 22:54:23,179 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 22:54:23,179 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 22:54:23,180 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 22:54:23,180 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 22:54:23,181 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 22:54:23,182 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 22:54:23,182 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 22:54:23,183 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 22:54:23,183 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 22:54:23,184 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 22:54:23,184 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 22:54:23,186 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=CreateGroup@2e0ece65
2012-07-06 22:54:23,211 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 22:54:23,216 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 22:54:23,216 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 22:54:23,222 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 22:54:23,243 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0000, negotiated timeout = 5000
Created /zoo
2012-07-06 22:54:23,262 [myid:] - INFO  [main:ZooKeeper@679] - Session: 0x1385c5c640f0000 closed
2012-07-06 22:54:23,262 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@511] - EventThread shut down

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java ListGroup localhost zoo                                                                   
2012-07-06 22:58:01,965 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 22:58:01,968 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 22:58:01,968 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 22:58:01,968 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 22:58:01,969 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 22:58:01,969 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 22:58:01,969 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 22:58:01,970 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 22:58:01,970 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 22:58:01,970 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 22:58:01,971 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 22:58:01,971 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 22:58:01,971 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 22:58:01,972 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 22:58:01,972 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 22:58:01,973 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=ListGroup@15301ed8
2012-07-06 22:58:02,006 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 22:58:02,013 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 22:58:02,014 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 22:58:02,022 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 22:58:02,033 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0002, negotiated timeout = 5000
No members in group zoo

3.2 Join Group

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java JoinGroup localhost zoo duck &
[1]     10264
[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> 2012-07-06 22:58:46,131 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 22:58:46,135 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 22:58:46,136 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 22:58:46,136 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 22:58:46,137 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 22:58:46,137 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 22:58:46,138 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 22:58:46,138 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 22:58:46,139 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 22:58:46,139 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 22:58:46,140 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 22:58:46,140 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 22:58:46,141 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 22:58:46,142 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 22:58:46,142 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 22:58:46,144 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=JoinGroup@15301ed8
2012-07-06 22:58:46,176 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 22:58:46,184 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 22:58:46,184 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 22:58:46,192 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 22:58:46,203 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0003, negotiated timeout = 5000
Created /zoo/duck

list group

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java ListGroup localhost zoo       
2012-07-06 22:59:03,639 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 22:59:03,642 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 22:59:03,643 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 22:59:03,643 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 22:59:03,643 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 22:59:03,643 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 22:59:03,644 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 22:59:03,644 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 22:59:03,645 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 22:59:03,645 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 22:59:03,645 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 22:59:03,646 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 22:59:03,646 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 22:59:03,646 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 22:59:03,646 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 22:59:03,648 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=ListGroup@15301ed8
2012-07-06 22:59:03,669 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 22:59:03,674 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 22:59:03,674 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 22:59:03,681 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 22:59:03,690 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0004, negotiated timeout = 5000
duck
2012-07-06 22:59:03,707 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@511] - EventThread shut down
2012-07-06 22:59:03,707 [myid:] - INFO  [main:ZooKeeper@679] - Session: 0x1385c5c640f0004 closed

3.3 Delete Group

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java DeleteGroup localhost zoo
2012-07-06 23:02:48,452 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 23:02:48,455 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 23:02:48,455 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 23:02:48,456 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 23:02:48,456 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 23:02:48,456 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 23:02:48,457 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 23:02:48,457 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 23:02:48,457 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 23:02:48,458 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 23:02:48,458 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 23:02:48,458 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 23:02:48,459 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 23:02:48,459 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 23:02:48,459 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 23:02:48,460 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=DeleteGroup@a3901c6
2012-07-06 23:02:48,488 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 23:02:48,497 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 23:02:48,497 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 23:02:48,506 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 23:02:48,517 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0006, negotiated timeout = 5000
2012-07-06 23:02:48,545 [myid:] - INFO  [main:ZooKeeper@679] - Session: 0x1385c5c640f0006 closed
2012-07-06 23:02:48,545 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@511] - EventThread shut down

list group

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java ListGroup localhost zoo                                                                              
2012-07-06 23:03:36,764 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 23:03:36,767 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 23:03:36,767 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 23:03:36,767 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 23:03:36,768 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 23:03:36,768 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 23:03:36,768 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 23:03:36,769 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 23:03:36,769 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 23:03:36,769 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 23:03:36,770 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 23:03:36,770 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 23:03:36,770 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 23:03:36,771 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 23:03:36,771 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 23:03:36,772 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=ListGroup@15301ed8
2012-07-06 23:03:36,793 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 23:03:36,803 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 23:03:36,803 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 23:03:36,808 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 23:03:36,815 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0007, negotiated timeout = 5000
Group zoo does not exist

4. http://zh.wikipedia.org/wiki/Paxos算法

Zab协议

5. 应用

配置服务demo

5.1 ConfigUpdater

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> export CLASSPATH=ch14.jar:$ZOOKEEPER_INSTALL/*:$ZOOKEEPER_INSTALL/lib/*:$ZOOKEEPER_INSTALL/conf
[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java ConfigUpdater localhost
2012-07-06 23:38:09,471 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 23:38:09,474 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 23:38:09,474 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 23:38:09,475 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 23:38:09,475 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 23:38:09,475 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 23:38:09,476 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 23:38:09,476 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 23:38:09,477 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 23:38:09,477 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 23:38:09,477 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 23:38:09,478 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 23:38:09,478 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 23:38:09,478 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 23:38:09,479 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 23:38:09,480 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=ActiveKeyValueStore@3c6f579
2012-07-06 23:38:09,501 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 23:38:09,506 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 23:38:09,506 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 23:38:09,511 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 23:38:09,521 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0008, negotiated timeout = 5000
Set /config to 35
Set /config to 96
Set /config to 27
Set /config to 50
Set /config to 2
Set /config to 1
Set /config to 57
Set /config to 71
Set /config to 40

5.2  ConfigWatcher

[ate: /local/nomad2/hadoop/tomwhite-hadoop-book-32dae01 ]
>> java ConfigWatcher localhost
2012-07-06 23:38:13,668 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.4.3-1240972, built on 02/06/2012 10:48 GMT
2012-07-06 23:38:13,673 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=ate
2012-07-06 23:38:13,674 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.6.0_22
2012-07-06 23:38:13,674 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Sun Microsystems Inc.
2012-07-06 23:38:13,675 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-6-sun-1.6.0.22/jre
2012-07-06 23:38:13,676 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=ch14.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//zookeeper-3.4.3.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/log4j-1.2.15.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-log4j12-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/netty-3.2.2.Final.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/jline-0.9.94.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//lib/slf4j-api-1.6.1.jar:/local/nomad2/zookeeper/zookeeper-3.4.3//conf
2012-07-06 23:38:13,676 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.22/jre/../lib/amd64::/opt/SUNWits/Graphics-sw/xil/lib:/lib:/usr/lib:/usr/openwin/lib:/usr/x11r5/lib:/usr/local/lib:/ace:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2012-07-06 23:38:13,677 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2012-07-06 23:38:13,677 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2012-07-06 23:38:13,678 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2012-07-06 23:38:13,678 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2012-07-06 23:38:13,679 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=2.6.24-24-generic
2012-07-06 23:38:13,680 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=nomad2
2012-07-06 23:38:13,680 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/local/nomad2
2012-07-06 23:38:13,681 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/local/nomad2/hadoop/tomwhite-hadoop-book-32dae01
2012-07-06 23:38:13,683 [myid:] - INFO  [main:ZooKeeper@433] - Initiating client connection, connectString=localhost sessionTimeout=5000 watcher=ActiveKeyValueStore@15301ed8
2012-07-06 23:38:13,715 [myid:] - INFO  [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /127.0.0.1:2181
2012-07-06 23:38:13,723 [myid:] - WARN  [main-SendThread(localhost:2181):ZooKeeperSaslClient@123] - SecurityException: java.lang.SecurityException: Unable to locate a login configuration occurred when trying to find JAAS configuration.
2012-07-06 23:38:13,724 [myid:] - INFO  [main-SendThread(localhost:2181):ZooKeeperSaslClient@125] - Client will not SASL-authenticate because the default JAAS configuration section 'Client' could not be found. If you are not using SASL, you may ignore this. On the other hand, if you expected SASL to work, please fix your JAAS configuration.
2012-07-06 23:38:13,732 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2012-07-06 23:38:13,812 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1175] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1385c5c640f0009, negotiated timeout = 5000
Read /config as 96
Read /config as 27
Read /config as 50
Read /config as 2
Read /config as 1
Read /config as 57
Read /config as 71
Read /config as 40

你可能感兴趣的:(《Hadoop The Definitive Guide》ch13 ZooKeeper)