Database Reference
In-Depth Information
Installing and Running ZooKeeper
When trying out ZooKeeper for the first time, it's simplest to run it in standalone mode
with a single ZooKeeper server. You can do this on a development machine, for example.
ZooKeeper requires Java to run, so make sure you have it installed first.
Download a stable release of ZooKeeper from the
Apache ZooKeeper releases page
, and
unpack the tarball in a suitable location:
%
tar xzf zookeeper-
x.y.z
.tar.gz
ZooKeeper provides a few binaries to run and interact with the service, and it's convenient
to put the directory containing the binaries on your command-line path:
%
export ZOOKEEPER_HOME=~/sw/zookeeper-
x.y.z
%
export PATH=$PATH:$ZOOKEEPER_HOME/bin
Before running the ZooKeeper service, we need to set up a configuration file. The config-
uration file is conventionally called
zoo.cfg
and placed in the
conf
subdirectory (although
you can also place it in
/etc/zookeeper
, or in the directory defined by the
ZOOCFGDIR
en-
vironment variable, if set). Here's an example:
tickTime
=
2000
dataDir
=
/Users/tom/zookeeper
clientPort
=
2181
This is a standard Java properties file, and the three properties defined in this example are
the minimum required for running ZooKeeper in standalone mode. Briefly,
tickTime
is
the basic time unit in ZooKeeper (specified in milliseconds),
dataDir
is the local filesys-
tem location where ZooKeeper stores persistent data, and
clientPort
is the port
ZooKeeper listens on for client connections (2181 is a common choice). You should change
dataDir
to an appropriate setting for your system.
With a suitable configuration defined, we are now ready to start a local ZooKeeper server:
%
zkServer.sh start
To check whether ZooKeeper is running, send the
ruok
command (“Are you OK?”) to the
client port using
nc
(
telnet
works, too):
%
echo ruok | nc localhost 2181
imok
That's ZooKeeper saying, “I'm OK.”
Table 21-1
lists the commands, known as the “four-
letter words,” for managing ZooKeeper.