vmware-marketplacezookeeper

Connect to ZooKeeper

You can connect to ZooKeeper from the same server where it is installed with the ZooKeeper client tool. Execute the following command:

$ zkCli.sh

You should see an output similar to this:

Connect to ZooKeeper

You can run the following example to see how to add new data to ZooKeeper, recover it, and delete the created registries:

  • Use the list command to see the data stored in the instance:

      $ ls /
      [zookeeper]
    
  • Create a new directory (in this example, test directory which includes the string mydata) using the create / command. This creates a new znode and associates the string “my_data” with the node. You should see:

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

      $ ls /
      [zookeeper, test]
    
  • Check the information associated to the new node by using the get / command:

      $ get /test
      mydata
      cZxid = 0x23
      ctime = Fri Jun 01 14:43:23 UTC 2018
      mZxid = 0x23
      mtime = Fri Jun 01 14:43:23 UTC 2018
      pZxid = 0x23
      cversion = 0
      dataVersion = 0
      aclVersion = 0
      ephemeralOwner = 0x0
      dataLength = 6
      numChildren = 0
    
  • Change the data associated to the test node using the set / command:

      $ set /test apache
      cZxid = 0x23
      ctime = Fri Jun 01 14:43:23 UTC 2018
      mZxid = 0x24
      mtime = Fri Jun 01 14:51:07 UTC 2018
      pZxid = 0x23
      cversion = 0
      dataVersion = 1
      aclVersion = 0
      ephemeralOwner = 0x0
      dataLength = 6
      numChildren = 0
    

    Run again the get / command to check that the data has been changed from mydata to apache:

      $ get /test
      apache
      cZxid = 0x23
      ctime = Fri Jun 01 14:43:23 UTC 2018
      mZxid = 0x24
      mtime = Fri Jun 01 14:51:07 UTC 2018
      pZxid = 0x23
      cversion = 0
      dataVersion = 1
      aclVersion = 0
      ephemeralOwner = 0x0
      dataLength = 6
      numChildren = 0
    
  • Delete the node with the delete / command:

      $ delete /test
    

    If you execute again the ls / command you should see only the [zookeeper] node.

Last modification December 21, 2022