知识库--ZooKeeper create Session (61)

来源:互联网 发布:linux udp服务器 编辑:程序博客网 时间:2024/05/28 18:44

ZooKeeper create Session

zk安装步骤:
1 wget http://zookeeper.apache.org –>具体的版本
2 extract the distribution:

        # tar -xvzf zookeeper-3.4.5.tar.gz --need java6

3 change directory(cd) to the project’s root and rename the sample configuration file:

       # mv conf/zoo_sample.cfg conf/zoo.cfg

4 Move the data directory out of /tmp to avoid having zookeeper filling up your root partition. You can change its location in the zoo.cfg file:

    dataDir=/users/me/zookeeper

5 start a server, execute the following

    # bin/zkServer.sh start    JMX enabled by default    Using config: ../conf/zoo.cfg    Starting zookeeper ... STARTED    #

6 or,To have it running in the foreground in order to see the output of the server, you can run the following:

    # bin/zkServer.sh start-foreground

7 In a different shell under the project root, run the following:

    # bin/zkCli.sh    //具体代码输出    Connecting to localhost:2181    2016-12-26 23:41:05,156 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT    2016-12-26 23:41:05,160 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=l-xxx.cn0    2016-12-26 23:41:05,160 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_45    2016-12-26 23:41:05,162 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation    2016-12-26 23:41:05,162 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/home/zww/java/jdk1.7.0_45/jre    2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/zww.zhang/zookeeper-3.4.9/bin/../build/classes:/home/zww.zhang/zookeeper-3.4.9/bin/../build/lib/*.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/home/zww.zhang/zookeeper-3.4.9/bin/../conf:.:/home/zww/java/default/lib:/home/q/java/default/lib:2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux2016-12-26 23:41:05,163 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd642016-12-26 23:41:05,164 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-358.23.2.el6.x86_642016-12-26 23:41:05,164 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=zww.zhang2016-12-26 23:41:05,164 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/zww.zhang2016-12-26 23:41:05,164 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/zww.zhang/zookeeper-3.4.92016-12-26 23:41:05,166 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@657a8369Welcome to ZooKeeper!//1 The client starts the procedure to establish a session2016-12-26 23:41:05,197 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)//2 The client tries to  connect to localhost/127.0.0.1:21812016-12-26 23:41:05,203 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating sessionJLine support is enabled//3 The client's connection is successful and the server proceeds to initiate a new session2016-12-26 23:41:05,217 [myid:] - WARN  [main-SendThread(localhost:2181):ClientCnxnSocket@139] - Connected to an old server; r-o mode will be unavailable2016-12-26 23:41:05,217 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1552dbafcc3000b, negotiated timeout = 30000//4 The session initialization completes successfully.WATCHER::WatchedEvent state:SyncConnected type:None path:null//5 The server sends the client a SyncConnected event

8 [zk: localhost:2181(CONNECTED) 1] ls /

[app2, app1, zookeeper]

9 [zk: localhost:2181(CONNECTED) 1] create /workers “”

Created /workers

10 [zk: localhost:2181(CONNECTED) 1] delete /workers

11 [zk: localhost:2181(CONNECTED) 1] quit

12 # bin/zkServer.sh stop

0 0
原创粉丝点击