ZooKeeper Administrator's Guide
Deployment
This section contains information about deploying Zookeeper and covers these topics:
The first two sections assume you are interested in installing ZooKeeper in a production environment such as a datacenter. The final section covers situations in which you are setting up ZooKeeper on a limited basis - for evaluation, testing, or development - but not in a production environment.
System Requirements
Supported Platforms
-
GNU/Linux is supported as a development and production platform for both server and client.
-
Sun Solaris is supported as a development and production platform for both server and client.
-
FreeBSD is supported as a development and production platform for clients only. Java NIO selector support in the FreeBSD JVM is broken.
-
Win32 is supported as a development platform only for both server and client.
-
MacOSX is supported as a development platform only for both server and client.
Required Software
ZooKeeper runs in Java, release 1.6 or greater (JDK 6 or greater). It runs as an ensemble of ZooKeeper servers. Three ZooKeeper servers is the minimum recommended size for an ensemble, and we also recommend that they run on separate machines. At Yahoo!, ZooKeeper is usually deployed on dedicated RHEL boxes, with dual-core processors, 2GB of RAM, and 80GB IDE hard drives.
Clustered (Multi-Server) Setup
For reliable ZooKeeper service, you should deploy ZooKeeper in a cluster known as an ensemble. As long as a majority of the ensemble are up, the service will be available. Because Zookeeper requires a majority, it is best to use an odd number of machines. For example, with four machines ZooKeeper can only handle the failure of a single machine; if two machines fail, the remaining two machines do not constitute a majority. However, with five machines ZooKeeper can handle the failure of two machines.
Here are the steps to setting a server that will be part of an ensemble. These steps should be performed on every host in the ensemble:
-
Install the Java JDK. You can use the native packaging system for your system, or download the JDK from:
-
Set the Java heap size. This is very important to avoid swapping, which will seriously degrade(降低) ZooKeeper performance. To determine the correct value, use load tests, and make sure you are well below the usage limit that would cause you to swap. Be conservative(保守的) - use a maximum heap size of 3GB for a 4GB machine.
-
Install the ZooKeeper Server Package. It can be downloaded from:
-
Create a configuration file. This file can be called anything. Use the following settings as a starting point:
tickTime=2000 dataDir=/var/zookeeper/ clientPort=2181 initLimit=5 syncLimit=2 server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
You can find the meanings of these and other configuration settings in the section Configuration Parameters. A word though about a few here:
Every machine that is part of the ZooKeeper ensemble should know about every other machine in the ensemble. You accomplish(达到|完成) this with the series of lines of the form server.id=host:port:port. The parameters host and port are straightforward. You attribute the server id to each machine by creating a file named myid, one for each server, which resides(位于|驻扎) in that server's data directory, as specified(指定) by the configuration file parameter dataDir.
-
The myid file consists of a single line containing only the text of that machine's id. So myid of server 1 would contain the text "1" and nothing else. The id must be unique within the ensemble and should have a value between 1 and 255.
-
If your configuration file is set up, you can start a ZooKeeper server:
$ java -cp zookeeper.jar:lib/log4j-1.2.15.jar:conf \ org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg
QuorumPeerMain starts a ZooKeeper server, JMX management beans are also registered which allows management through a JMX management console. The ZooKeeper JMX document contains details on managing ZooKeeper with JMX.
See the script bin/zkServer.sh, which is included in the release, for an example of starting server instances.
-
Test your deployment by connecting to the hosts:
-
In Java, you can run the following command to execute simple operations:
$ java -cp zookeeper.jar:src/java/lib/log4j-1.2.15.jar:conf:src/java/lib/jline-0.9.94.jar \ org.apache.zookeeper.ZooKeeperMain -server 127.0.0.1:2181
-
Running either program gives you a shell in which to execute simple file-system-like operations. To connect to ZooKeeper with the multithreaded client, for example, you would run: $ cli_mt 127.0.0.1:2181
Single Server and Developer Setup
If you want to setup ZooKeeper for development purposes, you will probably want to setup a single server instance of ZooKeeper, and then install either the Java or C client-side libraries and bindings on your development machine.
The steps to setting up a single server instance are the similar to the above, except the configuration file is simpler. You can find the complete instructions in the Installing and Running ZooKeeper in Single Server Mode section of the ZooKeeper Getting Started Guide.
For information on installing the client side libraries, refer to the Bindings section of the ZooKeeper Programmer's Guide.
Administration
This section contains information about running and maintaining ZooKeeper and covers these topics: