How to setup a basic ZooKeeper ensemble

This article is a guide to setup a ZooKeeper ensemble. I use this to have a local environment for development and testing.

For Zookeeper to work, you really only need to configure a couple of things. The first is the zoo.cfg file, and the second is a myid file in the dataDir. See this link for more info.


It assumes you are using the following software versions.

  • MacOS 10.11.3
  • Vagrant 1.8.5
  • Java 1.8.0
  • Zookeeper 3.4.8

Here are the steps

  1. First, create a workspace.

    mkdir -p ~/vagrant_boxes/zookeeper

    cd ~/vagrant_boxes/zookeeper

  2. Next, create a new vagrant box. I’m using a minimal CentOS vagrant box.

    vagrant box add “CentOS 6.5 x86_64”

  3. We are going to create a vagrant box with the packages we need. So, first we initialize the vagrant box.

    vagrant init -m “CentOS 6.5 x86_64” zoo_base

  4. Next, change the Vagrantfile to the following:

      Vagrant.configure(2) do |config| = "CentOS 6.5 x86_64"
        config.vm.box_url = "zoo_base"
        config.ssh.insert_key = false

  5. Now, install Zookeeper and it’s dependencies.

    vagrant up

    vagrant ssh

    sudo yum install java-1.8.0-openjdk-devel

    sudo yum install wget

    wget ~

    gunzip -c *gz | tar xvf –

  6. Open up your ~/.bash_profile and append the following lines.

      export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk.x86_64
      export PATH=$PATH:$JAVA_HOME/bin
      export ZOOKEEPER_HOME=~/zookeeper-3.4.8
      export PATH=$PATH:$ZOOKEEPER_HOME/bin

  7. Source the profile.

    source ~/.bash_profile

  8. Create a ~/zookeeper-3.4.8/conf/zoo.cfg file with the following contents.


  9. Exit the SSH session and copy the VM for the other zookeeper nodes.


    vagrant halt

    vagrant package

    vagrant box add zookeeper ~/vagrant_boxes/zookeeper/

  10. Edit the Vagrantfile to look like the following below. This will create 5 zookeeper nodes for us using the new Zookeeper VM.

      Vagrant.configure("2") do |config|
        (1..5).each do |i|
          config.vm.define "zoo#{i}" do |node|
   = "zookeeper"
            node.vm.box_url = "zoo#{i}"
            node.vm.hostname = "zoo#{i}"
   :private_network, ip: "{i}"
            # Zookeeper needs an ID file for each node
            node.vm.provision "shell", inline: "mkdir -p /tmp/zookeeper; echo '#{i}' >> /tmp/zookeeper/myid", privileged: false
            # Start Zookeeper
            node.vm.provision "shell", inline: "~/zookeeper-3.4.8/bin/ start", privileged: false
            node.ssh.insert_key = false

  11. Bring the new Vagrant VMs up.

    vagrant up –no-provision

    vagrant provision

Running ZooKeeper

To test to see if the Zookeeper works, you can do the following.

  1. SSH into zoo1.

    vagrant ssh zoo1

  2. Start Zookeeper CLI.

    ~/zookeeper-3.4.8/bin/ -server

  3. Create a new znode and associates the string “my_data” with the node.

    create /zk_test my_data

  4. Now exit the CLI and SSH session and log into zoo4.



    vagrant ssh zoo4

  5. Connect to the Zookeeper CLI again (notice the IP changed).

    ~/zookeeper-3.4.8/bin/ -server

  6. You should be able to see the /zk_test znode with an ls command (it should look like so: “[zookeeper, zk_test]”)

    ls /
    [zookeeper, zk_test]

Leave a Reply