Overview (Overview)
Http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html
Getting Started (Getting started)
Http://zookeeper.apache.org/doc/r3.4.6/zookeeperStarted.html
Tutorial (Tutorial)
Http://zookeeper.apache.org/doc/r3.4.6/zookeeperTutorial.html
Java Example (Java sample)
Http://zookeeper.apache.org/doc/r3.4.6/javaExample.html
Programmer ' s Guide (developer Guides)
Http://zookeeper.apache.org/doc/r3.4.6/zookeeperProgrammers.html
Recipes and Solutions (Tips and solutions)
Http://zookeeper.apache.org/doc/r3.4.6/recipes.html
3.4.6 API Online (online API quick Check)
Http://zookeeper.apache.org/doc/r3.4.6/api/index.html
Another recommended zookeeper series of friends Sunddenly
Http://www.cnblogs.com/sunddenly/category/620563.html
First, download
http://apache.opencas.org/zookeeper/
or http://mirrors.cnnic.cn/apache/zookeeper/download the latest version
Download unzip
Extract to 3 directories (simulate 3 ZK servers):
/soft/zookeeper-1
/soft/zookeeper-2
/soft/zookeeper-3
Create a conf/zoo.cfg configuration file under each directory
/soft/zookeeper-1/conf/zoo.cfg content is as follows:
ticktime=2000
initlimit=10
Synclimit=5
Datadir=/soft/tmp/zk1/data
Datalogdir=/soft/tmp/zk1/log
clientport=2181
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
/soft/zookeeper-2/conf/zoo.cfg content is as follows:
ticktime=2000
initlimit=10
Synclimit=5
Datadir=/soft/tmp/zk2/data
Datalogdir=/soft/tmp/zk2/log
clientport=2182
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
/soft/zookeeper-3/conf/zoo.cfg content is as follows:
ticktime=2000
initlimit=10
Synclimit=5
Datadir=/soft/tmp/zk3/data
Datalogdir=/soft/tmp/zk3/log
clientport=2183
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
Note: Because the cluster is simulated on a single machine, the ports cannot be duplicated, and the 2181~2183,2287~2289 and 3387~3389 are staggered. In addition, each ZK instance, need to set up a separate data storage directory, log storage directory, so DataDir, datalogdir these two nodes corresponding directories, need to be created manually first.
Mkdir/soft/tmp/zk1/data
Mkdir/soft/tmp/zk1/log
Mkdir/soft/tmp/zk2/data
Mkdir/soft/tmp/zk2/log
Mkdir/soft/tmp/zk3/data
Mkdir/soft/tmp/zk3/log
There is also a very critical setting in which a file named myID must be created in the same directory as the DataDir for each ZK server configuration file, where the content must be the same as the X in server.x in zoo.cfg, i.e.:
cd/soft/tmp/zk1/data/
Vimyid Input 1 Save
cd/soft/tmp/zk2/data/
Vimyid Input 2 Save
cd/soft/tmp/zk3/data/
Vimyid Input 3 Save
The content in/soft/tmp/zk1/data/myid is 1, corresponding to 1 in Server.1
The content in/soft/tmp/zk2/data/myid is 2, corresponding to 2 in Server.2
The content in/soft/tmp/zk3/data/myid is 3, corresponding to 3 in SERVER.3
In a production environment, the steps for distributed cluster deployment are basically the same as above, except that because each ZK server is distributed on different machines, localhost in the above configuration file is replaced with the real IP of each server. Distributed in different machines, there is no port conflict problem, you can make each server ZK use the same port, so it is easier to manage.
Start validation
/soft/zookeeper-1/bin/zkserver.sh start
/soft/zookeeper-2/bin/zkserver.sh start
/soft/zookeeper-3/bin/zkserver.sh start
Input JPS Check
Ps–ef|grep Zookeeper can also display all boot zookeeper ports
Use a client connection attempt:
Sh/soft/zookeeper-2/bin/zkcli.sh-server localhost:2181
Startup success:
Watcher::
Watchedevent state:syncconnected Type:none Path:null
[zk:localhost:2181 (CONNECTED) 0]
Client command:
LS/view root node; Ls/root View all nodes under the/root node
Create Path data Creation node
Set path data [watcher] sets the node value
Get path data gets the specified node value
Set on the same machine as a pseudo-cluster, but the same implementation of the random server on which to make the node changes, the other nodes will synchronize the effect of time.