查看状态
代码语言:javascript复制[root@h101 zk]# zookeeper-3.4.6.2/bin/zkServer.sh status
JMX enabled by default
Using config: /root/zk/zookeeper-3.4.6.2/bin/../conf/zoo.cfg
Mode: follower
[root@h101 zk]# zookeeper-3.4.6.1/bin/zkServer.sh status
JMX enabled by default
Using config: /root/zk/zookeeper-3.4.6.1/bin/../conf/zoo.cfg
Mode: leader
[root@h101 zk]# zookeeper-3.4.6/bin/zkServer.sh status
JMX enabled by default
Using config: /root/zk/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
[root@h101 zk]#
可知此时每个服务分别的角色
查看进程
代码语言:javascript复制[root@h101 zk]# ps faux | grep zookeeper | grep -v grep
root 5474 0.2 2.8 2103548 55168 pts/0 Sl 19:33 0:06 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /root/zk/zookeeper-3.4.6/bin/../build/classes:/root/zk/zookeeper-3.4.6/bin/../build/lib/*.jar:/root/zk/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zk/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/root/zk/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/root/zk/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/root/zk/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/root/zk/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/root/zk/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/root/zk/zookeeper-3.4.6/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /root/zk/zookeeper-3.4.6/bin/../conf/zoo.cfg
root 5505 0.4 3.1 2109716 61216 pts/0 Sl 19:33 0:12 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /root/zk/zookeeper-3.4.6.1/bin/../build/classes:/root/zk/zookeeper-3.4.6.1/bin/../build/lib/*.jar:/root/zk/zookeeper-3.4.6.1/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zk/zookeeper-3.4.6.1/bin/../lib/slf4j-api-1.6.1.jar:/root/zk/zookeeper-3.4.6.1/bin/../lib/netty-3.7.0.Final.jar:/root/zk/zookeeper-3.4.6.1/bin/../lib/log4j-1.2.16.jar:/root/zk/zookeeper-3.4.6.1/bin/../lib/jline-0.9.94.jar:/root/zk/zookeeper-3.4.6.1/bin/../zookeeper-3.4.6.jar:/root/zk/zookeeper-3.4.6.1/bin/../src/java/lib/*.jar:/root/zk/zookeeper-3.4.6.1/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /root/zk/zookeeper-3.4.6.1/bin/../conf/zoo.cfg
root 5549 0.3 2.8 2103548 53900 pts/0 Sl 19:33 0:10 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /root/zk/zookeeper-3.4.6.2/bin/../build/classes:/root/zk/zookeeper-3.4.6.2/bin/../build/lib/*.jar:/root/zk/zookeeper-3.4.6.2/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zk/zookeeper-3.4.6.2/bin/../lib/slf4j-api-1.6.1.jar:/root/zk/zookeeper-3.4.6.2/bin/../lib/netty-3.7.0.Final.jar:/root/zk/zookeeper-3.4.6.2/bin/../lib/log4j-1.2.16.jar:/root/zk/zookeeper-3.4.6.2/bin/../lib/jline-0.9.94.jar:/root/zk/zookeeper-3.4.6.2/bin/../zookeeper-3.4.6.jar:/root/zk/zookeeper-3.4.6.2/bin/../src/java/lib/*.jar:/root/zk/zookeeper-3.4.6.2/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /root/zk/zookeeper-3.4.6.2/bin/../conf/zoo.cfg
[root@h101 zk]#
代码语言:javascript复制[root@h101 zk]# ll /tmp/zookeeper*/zookeeper_server.pid
-rw-r--r-- 1 root root 4 Dec 3 19:33 /tmp/zookeeper0/zookeeper_server.pid
-rw-r--r-- 1 root root 4 Dec 3 19:33 /tmp/zookeeper1/zookeeper_server.pid
-rw-r--r-- 1 root root 4 Dec 3 19:33 /tmp/zookeeper2/zookeeper_server.pid
[root@h101 zk]# cat /tmp/zookeeper*/zookeeper_server.pid
547455055549[root@h101 zk]#
连接服务
代码语言:javascript复制[root@h101 zk]# zookeeper-3.4.6/bin/zkCli.sh -server localhost:2180
Connecting to localhost:2180
2015-12-03 20:21:25,745 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2015-12-03 20:21:25,752 [myid:] - INFO [main:Environment@100] - Client environment:host.name=h101.temp
2015-12-03 20:21:25,752 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_65
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/root/zk/zookeeper-3.4.6/bin/../build/classes:/root/zk/zookeeper-3.4.6/bin/../build/lib/*.jar:/root/zk/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/root/zk/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/root/zk/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/root/zk/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/root/zk/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/root/zk/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/root/zk/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/root/zk/zookeeper-3.4.6/bin/../conf:
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2015-12-03 20:21:25,757 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2015-12-03 20:21:25,758 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2015-12-03 20:21:25,758 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-504.el6.x86_64
2015-12-03 20:21:25,758 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2015-12-03 20:21:25,758 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2015-12-03 20:21:25,758 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root/zk
2015-12-03 20:21:25,761 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2180 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@3243a52c
Welcome to ZooKeeper!
2015-12-03 20:21:25,821 [myid:] - INFO [main-SendThread(localhost:2180):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2180. Will not attempt to authenticate using SASL (unknown error)
2015-12-03 20:21:25,837 [myid:] - INFO [main-SendThread(localhost:2180):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2180, initiating session
JLine support is enabled
2015-12-03 20:21:25,861 [myid:] - INFO [main-SendThread(localhost:2180):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2180, sessionid = 0x51679e16b90001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2180(CONNECTED) 0]
[zk: localhost:2180(CONNECTED) 0]
[zk: localhost:2180(CONNECTED) 0]
[zk: localhost:2180(CONNECTED) 0]
[zk: localhost:2180(CONNECTED) 0] ls /
[abc, zookeeper]
[zk: localhost:2180(CONNECTED) 1] create /defg defg
Created /defg
[zk: localhost:2180(CONNECTED) 2] get /defg
defg
cZxid = 0x100000009
ctime = Thu Dec 03 20:21:43 CST 2015
mZxid = 0x100000009
mtime = Thu Dec 03 20:21:43 CST 2015
pZxid = 0x100000009
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2180(CONNECTED) 3] connect localhost:2181
2015-12-03 20:24:18,536 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x51679e16b90001 closed
2015-12-03 20:24:18,537 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@d5c4abf
2015-12-03 20:24:18,538 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@512] - EventThread shut down
[zk: localhost:2181(CONNECTING) 4] 2015-12-03 20:24:18,559 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2015-12-03 20:24:18,561 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2015-12-03 20:24:18,575 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x151679e16cc0001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 4] ls /
[abc, defg, zookeeper]
[zk: localhost:2181(CONNECTED) 5] get /defg
defg
cZxid = 0x100000009
ctime = Thu Dec 03 20:21:43 CST 2015
mZxid = 0x100000009
mtime = Thu Dec 03 20:21:43 CST 2015
pZxid = 0x100000009
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2181(CONNECTED) 6] connect localhost:2182
2015-12-03 20:24:38,749 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@512] - EventThread shut down
2015-12-03 20:24:38,750 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x151679e16cc0001 closed
2015-12-03 20:24:38,751 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2182 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@2e3fe12e
2015-12-03 20:24:38,756 [myid:] - INFO [main-SendThread(localhost:2182):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2182. Will not attempt to authenticate using SASL (unknown error)
2015-12-03 20:24:38,757 [myid:] - INFO [main-SendThread(localhost:2182):ClientCnxn$SendThread@852] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2182, initiating session
[zk: localhost:2182(CONNECTING) 7] 2015-12-03 20:24:38,803 [myid:] - INFO [main-SendThread(localhost:2182):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2182, sessionid = 0x251679e27ea0001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2182(CONNECTED) 7] ls /
[abc, defg, zookeeper]
[zk: localhost:2182(CONNECTED) 8] get /defg
defg
cZxid = 0x100000009
ctime = Thu Dec 03 20:21:43 CST 2015
mZxid = 0x100000009
mtime = Thu Dec 03 20:21:43 CST 2015
pZxid = 0x100000009
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: localhost:2182(CONNECTED) 9]