azurezookeeper

Create a ZooKeeper ensemble

This section describes the creation of a ZooKeeper ensemble with servers located on different hosts. The following example shows an ensemble comprised of three instances, follow these instructions:

  • Launch as much ZooKeeper instances as nodes you want to have in the ensemble. (In this example, three instances).

  • Connect their Virtual Private Clouds (VPCs) by configuring VPC Network Peering.

  • Check that the value of the /opt/bitnami/zookeeper/data/myid file is equal to 1.

  • Edit the /opt/bitnami/zookeeper/conf/zoo.cfg file to add the following content. Remember to replace IP_ADDRESS with the corresponding IP address of each instance.

      server.1=IP_ADDRESS_SERVER1:2888:3888
      server.2=IP_ADDRESS_SERVER2:2888:3888
      server.3=IP_ADDRESS_SERVER3:2888:3888
    
  • Restart ZooKeeper services:

      $ sudo /opt/bitnami/ctlscript.sh restart zookeeper
    

Configuring the second ZooKeeper instance

  • Edit the /opt/bitnami/zookeeper/data/myid file and change the value 1 to 2.

  • Edit the /opt/bitnami/zookeeper/conf/zoo.cfg file to add the following content. Remember to replace IP_ADDRESS with the corresponding IP address of each instance.

      server.1=IP_ADDRESS_SERVER1:2888:3888
      server.2=IP_ADDRESS_SERVER2:2888:3888
      server.3=IP_ADDRESS_SERVER3:2888:3888
    
  • Restart ZooKeeper services:

      $ sudo /opt/bitnami/ctlscript.sh restart zookeeper
    

Configuring the third ZooKeeper instance

  • Edit the /opt/bitnami/zookeeper/data/myid file and change the value 1 to 3.

  • Edit the /opt/bitnami/zookeeper/conf/zoo.cfg file to add the following content. Remember to replace IP_ADDRESS with the corresponding IP address of each instance.

      server.1=IP_ADDRESS_SERVER1:2888:3888
      server.2=IP_ADDRESS_SERVER2:2888:3888
      server.3=IP_ADDRESS_SERVER3:2888:3888
    
  • Restart ZooKeeper services:

      $ sudo /opt/bitnami/ctlscript.sh restart zookeeper
    

Testing the ensemble

To check if the replication is working correctly in the cluster, let’s try the following:

  • In the server 1, connect to ZooKeeper by executing the following:

      $ zkCli.sh
    
  • Create a new directory named ensemble with a string named test using the create / command. This creates a new znode and associates the string test with the node. You should see:

      $ create /ensemble test
      Created /ensemble
    
  • Use the list command again to see how the directory looks like now:

      $ ls /
      [zookeeper, ensemble]
    
  • Go to the server 2 and connect to ZooKeeper using the zkCli.sh command.

  • Use the ls / command to check that you have the same data in both instances. You should see the same output you have obtained in the server 1 when executing that command:

      $ ls /
      [zookeeper, ensemble]
    

Congratulations! You now have a ZooKeeper ensemble running and ready to replicate the data through all the instances/nodes.

Last modification August 31, 2018