Zoo Keeper Quick Start

Keywords: Zookeeper log4j Java Apache

Link to the original text: http://www.dubby.cn/detail.html?id=9024

This brief introduction

This article is intended for beginners of ZooKeeper, introducing simple installation, configuration, and commands to try to run ZooKeeper. Also mentioned are some slightly responsible installations - replicated deployments, log optimization. Of course, this is only an entry document, if you want to know more about ZooKeeper, you can continue to pay attention to dubby.cn.

Note: ZooKeeper is often abbreviated as zk, which is also used below.

system requirements

Operating system requirements

zk has a variety of components:

  • The client is an application written in Java to connect the zk server.
  • The server side is an application written in Java, which runs on each node.
  • The native client is an application implemented in C, similar to the client, and also used to connect the zk server.
  • Plug-ins provide pluggable plug-ins.
operating system Client Server side Native Client Plug-in unit
GNU/Linux Development & Production Development & Production Development & Production Development & Production
Solaris Development & Production Development & Production I won't support it I won't support it
FreeBSD Development & Production Development & Production I won't support it I won't support it
Windows Development & Production Development & Production I won't support it I won't support it
Mac OS X Development Development I won't support it I won't support it

Software requirements

zk runs on Java and requires JDK version no less than 7 (FreeBSD requires openjdk7).

download

Download page: http://zookeeper.apache.org/releases.html

standalone mode

The most direct and simple way to install and run ZK in stand-alone mode is to try zk.

Unzip the downloaded file and enter the root directory of the unzipped file. You can see a zoo.cfg template in the conf/directory, such as zoo_sample.cfg, copy the file, rename it zoo.cfg, and edit zoo.cfg:

tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181

Here we focus only on these configuration items. Here's a brief explanation:

  • The basic unit of time in tickTime:zk is milliseconds. The other time parameters must be multiplied by this unit of time, which is the real time.
  • Data Dir: The snapshot drop path of data in ZK memory. If no other settings are made, the log defaults to this path, and the myid file is also configured here later.
  • clientPort: The port that listens for client connections.

Save the configuration file, and then you can start:

bin/zkServer.sh start

zk uses log4j, and you can see that many logs are printed out at the terminal.
This step is done in a stand-alone mode, which means that there is no replication and no backup. Once the process hangs up, the whole service will be unavailable. This can generally meet our needs in the test environment, but in the production environment, please use the replication mode.

Connect ZooKeeper

$ bin/zkCli.sh -server 127.0.0.1:2181

You can almost see this input:

Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
Welcome to ZooKeeper!
JLine support is enabled
[zkshell: 0]

Enter help to see all the supported commands:

[zkshell: 0] help
ZooKeeper host:port cmd args
        get path [watch]
        ls path [watch]
        set path data [version]
        delquota [-n|-b] path
        quit
        printwatches on|off
        create path data acl
        stat path [watch]
        listquota path
        history
        setAcl path acl
        getAcl path
        sync path
        redo cmdno
        addauth scheme auth
        delete path [version]
        deleteall path
        setquota -n|-b val path

Let's first use the ls command to view all nodes (znode s):

[zkshell: 8] ls /
[zookeeper]

Then create a new node and enter:

[zkshell: 9] create /zk_test my_data
Created /zk_test

List all the nodes again:

[zkshell: 11] ls /
[zookeeper, zk_test]

You can see a new path called zk_test, which has just been created. While the iron is hot, we use the get command to see the information of this node:

[zkshell: 12] get /zk_test
my_data
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 5
mtime = Fri Jun 05 13:57:06 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0
dataLength = 7
numChildren = 0

We can use the set command to update the value of this node:

[zkshell: 14] set /zk_test junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0
[zkshell: 15] get /zk_test
junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0

You can execute the get/zk_test command again to see if the value has changed.

Delete the node:

[zkshell: 16] delete /zk_test
[zkshell: 17] ls /
[zookeeper]
[zkshell: 18]

So far, we have mastered the most basic commands.

Posted by Dan39 on Fri, 24 May 2019 16:29:02 -0700