zookeeper快速入门

今天在阿里云的主机第一次启用,还是遇到了小麻烦。没装java。所以直接wget zookeeper的安装源码后,zookeeper单机模式启动了,实际上在日志文件报错了,没注意。好在很快查到了问题。安装了jdk8在主机上。jps用不了,用jps命令没看到QuorumPeerMain。
zookeeper快速入门_第1张图片

2017-09-17 21:56:32,909 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
2017-09-17 21:56:32,919 [myid:] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2017-09-17 21:56:32,920 [myid:] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2017-09-17 21:56:32,920 [myid:] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2017-09-17 21:56:32,920 [myid:] - WARN  [main:QuorumPeerMain@113] - Either no config or no quorum defined in config, running  in standalone mode
2017-09-17 21:56:32,938 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
2017-09-17 21:56:32,938 [myid:] - INFO  [main:ZooKeeperServerMain@95] - Starting server
2017-09-17 21:56:32,947 [myid:] - INFO  [main:Environment@100] - Server environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:host.name=
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.version=1.8.0_144
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.home=/root/jdk1.8.0_144/jre
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.class.path=/root/zookeeper-3.4.6/bin/../build/classes:/root/zookeeper-3.4.6/bin/../build/lib/*.jar:/root/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/root/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/root/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/root/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/root/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/root/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/root/zookeeper-3.4.6/bin/../conf:
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.io.tmpdir=/tmp
2017-09-17 21:56:32,948 [myid:] - INFO  [main:Environment@100] - Server environment:java.compiler=
2017-09-17 21:56:32,951 [myid:] - INFO  [main:Environment@100] - Server environment:os.name=Linux
2017-09-17 21:56:32,951 [myid:] - INFO  [main:Environment@100] - Server environment:os.arch=amd64
2017-09-17 21:56:32,951 [myid:] - INFO  [main:Environment@100] - Server environment:os.version=4.4.0-63-generic
2017-09-17 21:56:32,952 [myid:] - INFO  [main:Environment@100] - Server environment:user.name=root
2017-09-17 21:56:32,952 [myid:] - INFO  [main:Environment@100] - Server environment:user.home=/root
2017-09-17 21:56:32,952 [myid:] - INFO  [main:Environment@100] - Server environment:user.dir=/root/zookeeper-3.4.6/bin
2017-09-17 21:56:32,959 [myid:] - INFO  [main:ZooKeeperServer@755] - tickTime set to 2000
2017-09-17 21:56:32,960 [myid:] - INFO  [main:ZooKeeperServer@764] - minSessionTimeout set to -1
2017-09-17 21:56:32,960 [myid:] - INFO  [main:ZooKeeperServer@773] - maxSessionTimeout set to -1
2017-09-17 21:56:32,976 [myid:] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:2181

目前服务端在阿里云上,本想本地去连接的,但是一直报这个错误。还没解决,先进行了单机的实验。

2017-09-17 22:22:55,791 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client
 connection, connectString=106.14.201.174:2181 sessionTimeout=30000 watcher=org.
apache.zookeeper.ZooKeeperMain$MyWatcher@6815e601
Welcome to ZooKeeper!
2017-09-17 22:22:55,822 [myid:] - INFO  [main-SendThread(106.14.201.174:2181):Cl
ientCnxn$SendThread@1032] - Opening socket connection to server 106.14.201.174/1
06.14.201.174:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
[zk: 106.14.201.174:2181(CONNECTING) 0] 2017-09-17 22:23:16,820 [myid:] - WARN
[main-SendThread(106.14.201.174:2181):ClientCnxn$SendThread@1162] - Session 0x0
for server null, unexpected error, closing socket connection and attempting reco
nnect
java.net.ConnectException: Connection timed out: no further information
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739
)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocket
NIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2017-09-17 22:23:17,925 [myid:] - INFO  [main-SendThread(106.14.201.174:2181):Cl
ientCnxn$SendThread@1032] - Opening socket connection to server 106.14.201.174/1
06.14.201.174:2181. Will not attempt to authenticate using SASL (unknown error)

正常启动客户端日志

2017-09-17 22:04:26,742 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@3eb07fd3
Welcome to ZooKeeper!
2017-09-17 22:04:26,770 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017-09-17 22:04:26,895 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@852] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
[zk: 127.0.0.1:2181(CONNECTING) 0] 2017-09-17 22:04:26,941 [myid:] - INFO  [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15e90205a5e0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: 127.0.0.1:2181(CONNECTED) 0] 

客户端对节点增查改删操作
增加

[zk: 127.0.0.1:2181(CONNECTED) 0] create star datatest
Command failed: java.lang.IllegalArgumentException: Path must start with / character
[zk: 127.0.0.1:2181(CONNECTED) 1] create //star datatest
Command failed: java.lang.IllegalArgumentException: Invalid path string "//star" caused by empty node name specified @1
[zk: 127.0.0.1:2181(CONNECTED) 2] create /star datatest 
Created /star
[zk: 127.0.0.1:2181(CONNECTED) 3] ls
[zk: 127.0.0.1:2181(CONNECTED) 4] ls node
Command failed: java.lang.IllegalArgumentException: Path must start with / character

查询

[zk: 127.0.0.1:2181(CONNECTED) 5] get /

cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2
[zk: 127.0.0.1:2181(CONNECTED) 6] get /b
Node does not exist: /b
[zk: 127.0.0.1:2181(CONNECTED) 7] get /star
datatest
cZxid = 0x2
ctime = Sun Sep 17 22:05:33 CST 2017
mZxid = 0x2
mtime = Sun Sep 17 22:05:33 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 8
numChildren = 0

修改

[zk: 127.0.0.1:2181(CONNECTED) 8] set /star astron
cZxid = 0x2
ctime = Sun Sep 17 22:05:33 CST 2017
mZxid = 0x3
mtime = Sun Sep 17 22:11:11 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 9] set /star astronstar 
cZxid = 0x2
ctime = Sun Sep 17 22:05:33 CST 2017
mZxid = 0x4
mtime = Sun Sep 17 22:11:47 CST 2017
pZxid = 0x2
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 10
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 10] 

你可能感兴趣的:(Zookeeper)