首页 > 代码库 > 笔记:zookeeper Hello World

笔记:zookeeper Hello World

下载zookeeper-3.4.6 , 试用了一下

standlone

启动

./bin/zkServer.sh start

注: Usage: ./bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}_ 

用cli工具就可以操作了

 ./bin/zkCli.sh -server 127.0.0.1:2181

[zk: 127.0.0.1:2181(CONNECTED) 0] help

ZooKeeper -server host:port cmd args
        connect host:port
        get path [watch]
        ls path [watch]
        set path data [version]
        rmr path
        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
 

cluster

改 conf/zoo.cfg 文件,添加下面两行 (我用173和207两台机器组建 cluster)

server.1=10.15.4.173:2888:3888
server.2=10.15.4.207:2888:3888

创建myid文件

在173上 echo 1 > /tmp/zookeeper/myid

在207上 echo 2 > /tmp/zookeeper/myid


在两台机器都启动  (./bin/zkServer.sh start)

173上查看

$ ./bin/zkServer.sh status
JMX enabled by default
Using config: /home/payne/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader

207上查看

$ ./bin/zkServer.sh status
JMX enabled by default
Using config: /home/payne/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower

注:没有 myid, 或者只启动一台,zkCli.sh 连接不上


ref:

https://zookeeper.apache.org/doc/r3.3.3/zookeeperStarted.html
http://blackproof.iteye.com/blog/2039040
http://blog.csdn.net/pelick/article/details/7269670
http://myjeeva.com/zookeeper-cluster-setup.html



笔记:zookeeper Hello World