Install the Java JDK. You can use the native packaging system
for your system, or download the JDK from:
http://java.sun.com/javase/downloads/index.jsp
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:
http://hadoop.apache.org/zookeeper/releases.html
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:
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:
In C, you can compile either the single threaded client or
the multithreaded client: or n the c subdirectory in the
ZooKeeper sources. This compiles the single threaded
client:
$ make cli_st
And this compiles the mulithreaded client:
$ make cli_mt
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
config solr
1. Upload configuration to ZooKeeper
sh zkcli.sh -cmd bootstrap -zkhost 127.0.0.1:9983 -solrhome example/solr