Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Zookeeper In Action

4,111 views

Published on

Getting started with Apache ZooKeeper

Published in: Technology, Education

Zookeeper In Action

  1. 1. ZooKeeper In Action Juven Xu (许晓斌)
  2. 2. • Apache ZooKeeper is an effort to develop and maintain an open-source server which enables highly reliable distributed coordination.
  3. 3. Requirements • JDK 1.6 & JAVA_HOME • Maven (we will need to write some java code)
  4. 4. Installation • Download: http://zookeeper.apache.org/ releases.html • mv conf/zoo_sample.cfg conf/zoo.cfg • edit zoo.cfg: dataDir=/my/zk/dataDir • bin/zkServer.sh start
  5. 5. ZooKeeper Data Tree
  6. 6. ZooKeeper API
  7. 7. bin/zkCli.sh • zkCli.sh -server localhost:2181
  8. 8. Exercise #1 • install zookeeper, start it, and create a znode /test/ node1 with value “hello-world”
  9. 9. Problem with Polling
  10. 10. ZooKeeper Watch
  11. 11. Coding for Watch
  12. 12. Coding for Watch
  13. 13. Exercise #2 • Write your own watch, print new value on each time znode /test/znode1 changes
  14. 14. ZooKeeper Ensemble
  15. 15. To Setup an Ensemble • conf/zoo.cfg: //on all servers
 server.1=10.20.157.1:2888:3888
 server.2=10.20.157.2:2888:3888
 server.3=10.20.157.3:2888:3888 • conf/zoo.cfg: //this location is important
 dataDir=/home/admin/zookeeper/zkData • echo 1 > ${dataDir}/myid //on server.1
 echo 2 > ${dataDir}/myid //on server.2
 echo 3 > ${dataDir}/myid //on server.3

  16. 16. To Setup an Ensemble • If you want to set up ensemble on one machine, make sure these values are different: • dataDir • clientPort • the ports of server.{1-5}
  17. 17. Client of a Ensemble
  18. 18. Exercise #3 • Find 2 friends, set up an Ensemble with them. • Update your client, registering all the 3 servers. • Kill one server, see if ensemble and client still works • Kill another server (now only one left), see how it goes.

×