Today, I will talk about how to install Apache ZooKeeper and run the instance of it.
Prerequisites: JRE 1.6 or higher required (for development purposes, I would install JDK instead 1.6 or higher) At the time of writing this blog, the current stable version of Java is 1.8 and that should work perfectly fine (I have 1.7.0_51)
NOTE: I noticed that some of my peers tend to forget to set the environment variables, so please remember to set them before proceeding.
1. Installing Apache ZooKeeper
1. Download Apache ZooKeeper. You can choose from any given mirror – http://www.apache.org/dyn/closer.cgi/zookeeper/
2. Extract it to where you want to install ZooKeeper. I prefer to save it in the
C:\dev\tools directory. Unless you prefer this way as well, you will have to create that directory yourself.
3. Set up the environment variable.
- To do this, first go to Computer, then click on the
- Click on the
Advanced System Settingslink to the left.
- On a new window pop-up, click on the
- Under the
System Variablessection, click
- For the
Variable Name, type in
ZOOKEEPER_HOME. Variable Valuewill be the directory of where you installed the ZooKeeper. Taking mine for example, it would be
- Now we have to edit the
Pathfrom the list and click
- It is VERY important that you DO NOT erase the pre-existing value of the
Pathvariable. At the very end of the variable value, add the following:
%ZOOKEEPER_HOME%\bin;Also, each value needs to be separated by semicolon.
- Once that’s done, click OK and exit out of them all.
That takes care of the ZooKeeper installation part. Now we have to configure it so the instance of ZooKeeper will run properly.
2. Configuring ZooKeeper Server
If you look at the
<zookeeper-install-directory> there should be a
conf folder. Open that up, and then you’ll see a
zoo-sample.cfg file. Copy and paste it in the same directory, it should produce a
zoo-sample - Copy.cfg file. Open that with your favorite text editor (Microsoft Notepad should work as well).
Edit the file as follows:
tickTime=2000 initLimit=5 syncLimit=5 dataDir=/usr/zookeeper/data clientPort=2181 server.1=localhost:2888:3888
NOTE: you really don’t need lines 2 (
initLimit=5), 3 (
syncLimit=5), and 6 (
server.1=localhost:2888:3888). They’re just there for a good practice purposes, and especially for setting up a multi-server cluster, which we are not going to do here.
Save it as
zoo.cfg. Also the original
zoo-sample.cfg file, go ahead and delete it, as it is not needed.
Next step is to create a
myid file. If you noticed earlier in the
zoo.cfg file, we wrote
dataDir=/usr/zookeeper/data. This is actually a directory you’re going to have to create in the C drive. Simply put, this is the directory that ZooKeeper is going to look at to identify that instance of ZooKeeper. We’re going to write 1 in that file.
So go ahead and create that
usr/zookeeper/data directory, and then open up your favorite text editor.
Just type in 1, and save it as
myid, set the file type as
All files. This may not be insignificant, but we are going to not provide it any file extension, this is just for the convention.
Don’t worry about the
version-2 directory from the picture. That is automatically generated once you start the instance of ZooKeeper server.
At this point, you should be done configuring ZooKeeper. Now close out of everything, click the Start button, and open up a command prompt.
3. Test an Instance of Running ZooKeeper Server
Type in the following command:
zkServer.cmd and hit enter. You should get some junk like this that don’t mean much to us.
Now open up another command prompt in a new window. Type in the following command:
zkCli.cmd and hit enter. Assuming you did everything correctly, you should get
[zk: localhost:2181<CONNECTED> 0] at the very last line. See picture below:
If you are getting the same result, then you setup ZooKeeper server correctly. Thanks for reading, and happy zookeeping!