Friday, June 15, 2012

How to run Apache Zookeeper server

It is easy to up and run apache zookeeper server. First you need to download latest stable version of zookeeper distribution . Lets say you have downloaded zookeeper-3.3.4 to home directory , Then open Terminal by pressing Ctrl+Alt+t all together.Go to zookeeper bin folder(run  "cd ~/zookeeper-3.3.4/bin" command in terminal)


Then run "zkServer.sh start" command then you will see following three lines
 JMX enabled by default
Using config: /home/zookeeper-3.3.4/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED


If you can see above output in the terminal window. It means you have started Zookeeper server successfully in your local machine.

To stop the server run "zkServer.sh stop" command.

If you need You can run zookeeper default client come up with the distribution, for that, run "zkCli.sh" command. Then you will see

zookeeper-3.3.4/bin/../conf:
...............
2012-06-14 23:47:35,640 - INFO  [main:Environment@97] - Client environment:java.io.tmpdir=/tmp
2012-06-14 23:47:35,641 - INFO  [main:Environment@97] - Client environment:java.compiler=<NA>
........

connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7369ca65
Welcome to ZooKeeper!
2012-06-14 23:47:35,697 - INFO  [main-SendThread():ClientCnxn$SendThread@1061] - Opening socket connection to server localhost/127.0.0.1:2181
JLine support is enabled
2012-06-14 23:47:35,713 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@950] - Socket connection established to localhost/127.0.0.1:2181, initiating session
[zk: localhost:2181(CONNECTING) 0] 2012-06-14 23:47:35,915 - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@739] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x137ec2306ef0000, negotiated timeout = 30000


WATCHER::

WatchedEvent state:SyncConnected type:None path:null 


[zk: localhost:2181(CONNECTED) 0] 

Then type "ls" or what ever you will see list of available commands


[zk: localhost:2181(CONNECTED) 0] ls 
ZooKeeper -server host:port cmd args
    connect host:port
    get path [watch]
    ls path [watch]
    set path data [version]
    delquota [-n|-b] path
    quit
    printwatches on|off
    create [-s] [-e] path data acl
    stat path [watch]
    close
    ls2 path [watch]
    history
    listquota path
    setAcl path acl
    getAcl path
    sync path
    redo cmdno
    addauth scheme auth
    delete path [version]
    setquota -n|-b val path

 [zk: localhost:2181(CONNECTED) 1]

eg: If you like to list down zookeeper root directory, Type "ls / "


Note: If you need you can change zookeeper configuration file(zoo.cfg). You can fine it zookeeper-3.3.4/conf/ directory. Sometimes you need to change its default values. As an example, If you need to connect more than 10 zookeeper client to your zookeeper server Then you should probably add maxClientCnxns=# (#-any number) otherwise defalut value is 10. if you add maxClientCnxns=0 it means there is no any client limit. please refer advanced configuration in Zookeeper administrator's guide

1 comment:

  1. Can you tell me how to run a zookeeper server on windows and how to test if zookeeper server is running on windows

    ReplyDelete

Sample Text

Website counter

Categories