First go to the official website to download the zookeeper installation package, this article uses the 3.4.6stable version
http://zookeeper.apache.org/doc/r3.4.6/
The directory structure after extracting the TAR command is as follows:
[[email protected] zookeeper-3.4.6]# lltotal 1612drwxr-xr-x 2 1000 4096 1 bin-rw-rw-r--1 82446 build.xml-rw-rw-r--1 80776, changes.txtdrwxr-xr-x 2 1000 1000 4096 Jan 11:39 confdrwxr-xr-x 4096 contribdrwxr-xr-x 2, 4096, DIST-MAV, Geneva Endrwxr-xr-x 6 4096 docs-rw-rw-r--1-1953-ivysettings.xml-rw-rw-r-- 1 3375 ivy.xmldrwxr-xr-x 4 4096 lib-rw-rw-r--1 (11358 F.) EB license.txt-rw-rw-r--1 notice.txt-rw-rw-r--1 1770 20 2014 ($) readme_packaging.txt-rw-rw-r--1 1585, Readme.txtdrwxr-xr-x 5, 4096, R Ecipesdrwxr-xr-x 8 4096 src-rw-rw-r--1-1340305-zookeeper-3.4.6.jar-rw- rw-r--1 1000 1000836 zookeeper-3.4.6.jar.asc-rw-rw-r--1, zookeeper-3.4.6.jar.md5-rw-rw-r--, 1 zookeeper-3.4.6.jar.sha1-rw-r--r--1 root root 46852 Jan 11:42 zookeeper.out
We enter the Conf directory to create a new zoo.cfg configuration file, the file name can be easily, but the default is the file name, why?
Look, zkenv.sh, I know.
If ["x$zoocfg" = "x"]then zoocfg= "Zoo.cfg" fi
1. The contents of the stand-alone mode file are as follows:
#the basic time unit in milliseconds used by Zookeeper,it are used to do heartbeats and the min session timeout would be TWI Ce the ticktimeticktime=2000#the location to store the In-memory database snapshots and, unless specified otherwise,the tr Ansaction log of updates to Databasedatadir=/home/zookeeper/zkdata#the port to listen for client connectionsclientport=21 81
At this point, the stand-alone configuration is over, the following can be started
bin/zkserver.sh start
When the boot is complete, connect to it using the following command:
Bin/zkcli.sh-server serverip:2181
Of course, your client must be a ZK.
[Zk:localhost:2181 (CONNECTED)] llzookeeper-server host:port cmd args connect host:port get path [watch] ls Path [watch] set path data [version] RMR path delquota [-n|-b] path quit printwatches on| Off Create [-S] [-e] path data ACL 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
At this point, the stand-alone mode is over!
2. Cluster mode
Modify the configuration file as follows:
#the basic Time unit in milliseconds used by Zookeeper,it are used to do heartbeats and the min session timeout would be twice the tick Timeticktime=2000#the location to store the In-memory database snapshots and, unless specified otherwise,the transaction l OG of updates to databasedatadir=/home/zookeeper/zkdata#the port-to-listen for client connectionsclientport=2181# Timeouts zookeeper uses to limit the length of time the zookeeper servers in quorum has to connect to a leaderinitlimit=5 #limits how far out of date a server can is from a leadersynclimit=2#with both of above timeouts, you specify the unit of Time using Ticktime. In this example, the timeout for Initlimit are 5 ticks at + milleseconds a tick, or seconds.server.1=192.168.11.176:2 888:3888server.2=192.168.11.177:2888:3888server.3=192.168.11.178:2888:3888
The entries of the formserver. Xlist the servers the ZooKeeper service. When the server starts up, it knows which server it was by looking for the filemyIDIn the data directory. That file has the contains the server number, in ASCII.
The meaning of this sentence, server. The x in X is read from the myID file under the DataDir path, so we're going to create the corresponding myID file, with the contents of
At this point, the configuration of the cluster has been completed!
Go down to each node machine to start zookeeper
SH bin/zkserver.sh start
can go to see Zookeeper.out's boot log output
View node Status
[[Email protected] zookeeper-3.4.6]# sh bin/zkserver.sh statusjmx enabled by defaultusing Config:/home/zookeeper/ zookeeper-3.4.6/bin/. /conf/zoo.cfgmode:leader
[[Email protected] zookeeper-3.4.6]# sh bin/zkserver.sh statusjmx enabled by defaultusing Config:/home/zookeeper/ zookeeper-3.4.6/bin/. /conf/zoo.cfgmode:follower
[[Email protected] zookeeper-3.4.6]# sh bin/zkserver.sh statusjmx enabled by defaultusing Config:/home/zookeeper/ zookeeper-3.4.6/bin/. /conf/zoo.cfgmode:follower
Three nodes, one leader, two follower
Add here: Zookeeper cluster must have an odd number of nodes, because zookeeper has a mechanism, when the cluster of more than half of the nodes are hanging, the entire zookeeper will stop service, if it is even, half to half, zookeeper difficult to judge, So zookeeper's clusters suggest even-numbered stations to build.
Here's another client to connect to the ZK cluster:
[[email protected] zookeeper-3.4.6]# sh bin/zkcli.sh-server 192.168.11.178:2181connecting to 192.168.11.178:21812015-01-22 14:41:08,947 [myID:]-INFO [main:[email protected]]-Client Environment: zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 gmt2015-01-22 14:41:08,975 [myID:]-INFO [main:[email p Rotected]]-Client environment:host.name=com20.authentication2015-01-22 14:41:08,975 [myID:]-INFO [Main:[email protected]]-Client environment:java.version=1.7.0_602015-01-22 14:41:08,989 [myID:]-INFO [main:[email Protected]-Client environment:java.vendor=oracle corporation2015-01-22 14:41:08,990 [myID:]-INFO [Main:[email protected]]-Client environment:java.home=/usr/java/jdk1.7.0_67/jre2015-01-22 14:41:08,991 [myID:]-INFO [main : [email protected]]-Client environment:java.class.path=/home/zookeeper/zookeeper-3.4.6/bin/. /build/classes:/home/zookeeper/zookeeper-3.4.6/bin/. /build/lib/*.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /lib/slf4j-log4j12-1.6.1.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /lib/slf4j-api-1.6.1.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /lib/netty-3.7.0.final.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /lib/log4j-1.2.16.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /lib/jline-0.9.94.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /zookeeper-3.4.6.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /src/java/lib/*.jar:/home/zookeeper/zookeeper-3.4.6/bin/. /conf:.:/ usr/java/jdk1.7.0_67/lib:/usr/java/jdk1.7.0_67/lib/tools.jar:/usr/java/jdk1.7.0_67/lib/dt.jar:/usr/java/ Jdk1.7.0_67/jre/lib:/usr/java/jdk1.7.0_67/jre/lib/charsets.jar:/usr/java/jdk1.7.0_67/jre/lib/rt.jar2015-01-22 14:41:08,991 [myID:]-INFO [main:[email protected]]-Client environment:java.library.path=/usr/java/packages/ Lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib2015-01-22 14:41:08,992 [myID:]-INFO [main:[email protected]]- Client environment:java.io.tmpdir=/tmp2015-01-22 14:41:08,993 [myID:]-INFO [main:[email protected]]-CLient environment:java.compiler=<na>2015-01-22 14:41:08,993 [myID:]-INFO [main:[email protected]]- Client Environment:os.name=linux2015-01-22 14:41:08,994 [myID:]-INFO [main:[email protected]]-Client Environment:os.arch=amd642015-01-22 14:41:08,995 [myID:]-INFO [main:[email protected]]-Client environment:o S.version=2.6.18-308.el52015-01-22 14:41:08,995 [myID:]-INFO [main:[email protected]]-Client Environment: User.name=root2015-01-22 14:41:08,996 [myID:]-INFO [main:[email protected]]-Client environment:user.home=/ Root2015-01-22 14:41:08,996 [myID:]-INFO [main:[email protected]]-Client environment:user.dir=/home/zookeeper /zookeeper-3.4.62015-01-22 14:41:09,000 [myID:]-INFO [main:[email protected]]-Initiating client connection, con nectstring=192.168.11.178:2181 sessiontimeout=30000 [Email protected]welcome to ZooKeeper!2015-01-22 14:41:09,187 [myID:]-INFO [Main-sendthread (192.168.11.178:2181): [EMAIL&NBSP;PROtected]]-Opening socket connection to server 192.168.11.178/192.168.11.178:2181. Won't attempt to authenticate using SASL (unknown error) JLine support is enabled2015-01-22 14:41:09,243 [myID:]-INFO [Main-sendthread (192.168.11.178:2181): [email protected]]-Socket connection established to 192.168.11.178/ 192.168.11.178:2181, initiating session[zk:192.168.11.178:2181 (connecting) 0] 2015-01-22 14:41:09,481 [myID:]-INFO [m Ain-sendthread (192.168.11.178:2181): [email protected]]-Session establishment complete on server 192.168.11.178 /192.168.11.178:2181, SessionID = 0x34b1057cbfa0000, negotiated timeout = 30000watcher::watchedevent State: syncconnected type:none path:null[zk:192.168.11.178:2181 (CONNECTED) 0] [zk:192.168.11.178:2181 (CONNECTED) 1] LS/[ Zookeeper, zk_test][zk:192.168.11.178:2181 (CONNECTED) 2] Get/zk_testmy_dataczxid = 0x5ctime = Thu Jan 13:52:58 CST 20 15mZxid = 0x5mtime = Thu Jan 13:52:58 CST 2015pZxid = 0x5cversion = 0dataVersion = 0aclVersion= 0ephemeralOwner = 0x0datalength = 7numChildren = 0[zk:192.168.11.178:2181 (CONNECTED) 3]
If your client just go to the ZK cluster, only need to unzip the ZK installation package, use the command directly can connect, without any configuration!
In case of any problems, we recommend that you go to the official website for reference, the official website is always authoritative!
Http://zookeeper.apache.org/doc/r3.4.6/zookeeperStarted.html
Share!
Construction of "zookeeper" zookeeper single machine and cluster environment