http://blog.csdn.net/aqsunkai/article/details/51683632
Zookeeper installation supports stand-alone mode and cluster mode
: http://www.apache.org/dyn/closer.cgi/zookeeper/, current stable version is 3.4.8
Single-machine mode modifies zookeeper configuration file zoo.cfg
After extracting into the Conf directory, modify the Zoo_sample.cfg file name: Zoo.cfg, this is because the Zoo.cfg configuration file is loaded by default when zookeeper starts. Modify the contents of the Zoo.cfg file as follows:
[HTML]View PlainCopyprint?
- # The number of milliseconds of each tick
- #tickTime: This time is the interval between Zookeeper servers or between the client and server, which means that each ticktime time sends a heartbeat.
- #默认情况下最小的会话超时时间为两倍的tickTime
- Ticktime=
- # The number of ticks that initial
- # Synchronization phase can take
- #zookeeper集群中的包含多台server, one of which is leader, and the rest of the servers in the cluster are follower. When the Initlimit parameter is configured to initialize the connection,
- #follower和leader之间的最长心跳时间. At this point the parameter is set to 5, stating that the time limit is 5 times times ticktime, i.e. 5*2000=10000ms=10s.
- initlimit=5
- # The number of ticks that can pass between
- # Sending a request and getting an acknowledgement
- #该参数配置leader和follower之间发送消息, the maximum length of time to request and answer. At this point the parameter is set to 2, stating that the time limit is twice times ticktime, or 4000ms.
- synclimit=2
- # The directory where the snapshot is stored.
- # do not use/tmp for storage,/tmp here are just
- # example Sakes.
- #dataDir: As the name implies is Zookeeper to save the data directory, by default, Zookeeper will write the data log file is also stored in this directory.
- datadir=D:\\zookeeper-3.4.8\\data
- #dataLogDir: As the name implies, the directory where log files are saved Zookeeper
- datalogdir=D:\\zookeeper-3.4.8\\log
- # The port at which the clients would connect
- #clientPort: This port is the port where the client connects to the Zookeeper server, and Zookeeper listens to the port, accepting requests for client access.
- clientport=2181
- # The maximum number of the client connections.
- # Increase this if you need to handle more clients
- #maxClientCnxns: Limit the number of clients connected to ZooKeeper
- #maxclientcnxns=
- #
- # Be sure to read the maintenance section of the
- # Administrator Guide before turning on Autopurge.
- #
- # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
- #
- # The number of snapshots to retain in DataDir
- #autopurge.snapretaincount=3
- # Purge task interval in hours
- # Set to ' 0 ' to disable Auto Purge feature
- #autopurge.purgeinterval=1
You need to create a new data and log folder under the zookeeper-3.4.8 folder
Start Zookeeper
cmd command into Zookeeper-3.4.8\bin directory, start zkserver.cmd
or simply double-click Zkserver.cmd to start, double-click the window will not close if it is turned off to indicate that it did not start successfully
If the JDK environment variable is set, but the hint java_home is not found, you need to modify Zkenv.cmd part of the directory about Java_home
[HTML]View PlainCopyprint?
- Set java_home="D:\Program files\java\jdk1.7.0_75"
- If not defined Java_home (
- Echo Error:java_home is not set.
- Goto:eof
- )
- If not exist%java_home%\bin\java.exe (
- Echo Error:java_home is incorrectly set.
- Goto:eof
- )
- Set Java=%java_home%\bin\java
Pseudo-Cluster mode
The so-called pseudo-cluster, is to start multiple zookeeper processes in a single machine, and form a cluster to start 3 zookeeper processes as an example.
Copy the zookeeper-3.4.8 folder 2 copies, these three folders are named Zookeeper-3.4.8-1, Zookeeper-3.4.8-2, zookeeper-3.4.8-3
Here are a few options that are configured in the Zoo.cfg file under the Zookeeper-3.4.8-1/conf folder:
[HTML]View PlainCopyprint?
- datadir=D:\\zookeeper-3.4.8-1\\data
- datalogdir=D:\\zookeeper-3.4.8-1\\log
- clientport=2181
- server.1=127.0.0.1:8281:7271
- server.2=127.0.0.1:8282:7272
- server.3=127.0.0.1:8283:7273
Server. X=A:B:C where x is a number that indicates which is the first server. A is the IP address where the server resides. b Configure the port used by the server and the leader in the cluster to exchange messages. C Configure the port to use when electing leader. Because the pseudo-cluster mode is configured, the B and C parameters of each server must be different.
Refer to the Zoo.cfg file under the Zookeeper-3.4.8-1/conf folder to configure Zookeeper-3.4.8-2/conf/zoo.cfg, zookeeper-3.4.8-3/conf/, respectively Zoo.cfg file, only need to modify DataDir, Datalogdir, ClientPort.
Create a new myID file under the DataDir directory set in the three zoo.cfg files, write a number that indicates that this is the number of server, which must correspond to the X in Server.x in the Zoo.cfg file. As in the D:\\zookeeper-3.4.8-1\\data\\myid file, the number is 1.
Then the three zookeeper are activated separately.
Cluster mode
Cluster mode configuration and pseudo-cluster are basically consistent.
Because the server is deployed on different machines in cluster mode, the CONF/ZOO.CFG files for each server can be identical.
Here is an example:
[HTML]View PlainCopyprint?
- Ticktime=
- initlimit=5
- synclimit=2
- datadir=D:\\zookeeper-3.4.8\\data
- datalogdir=D:\\zookeeper-3.4.8\\log
- clientport=2181
- server.21=192.168.0.1:8280:7270
- server.22=192.168.0.2:8280:7270
- server.23=192.168.0.3:8280:7270
The example deploys 3 zookeeper servers, deployed on 192.168.0.1, 192.168.0.2, 192.168.0.3, respectively. It is important to note that the numbers in the myID file in the DataDir directory of each server must be different.
The 192.168.0.1server myID for 21,192.168.0.2server myID myID for 22,192.168.0.3server is 23.
Installation and startup of the Zookeeper registry under Windows