[py]python操作zookeeper

参考: https://blog.csdn.net/heizistudio/article/details/79568188

  • 1.安装zookeeper
zookeeper-3.4.6.tar.gz
tar zxvf zookeeper-3.4.6.tar.gz?
cd zookeeper-3.4.6/src/c

./configure
make
make install
  • 2.启动zookeeper服务
cd zookeeper-3.4.6/conf/
mv zoo_sample.cfg zoo.cfg

vim zoo.cfg #修改dataDir=/data/database/zookeeper
mkdir -p /data/database/zookeeper
cd ..
zookeeper-3.4.5-cdh5.0.0]# cd bin/
./zkServer.sh start ?#启动服务
./zkServer.sh status #查看启动状态
如果显示
Mode: standalone
则表示启动成功

如果显示 It is probably not running,原因是没有安装jdk或者没有配置JAVA_HOME路径
  • 3.安装zkpython
在https://pypi.python.org/pypi/zkpython/0.4.2 下载,然后解压后安装
如果 import zookeeper就表示成功安装
  • 4.python连接和操作zookeeper

输入python进入python界面

>>> import zookeeper
>>> zk=zookeeper.init("localhost:2181")
2018-03-15 13:56:49,486:70665(0x7f0eef010740):ZOO_INFO@log_env@712: Client environment:zookeeper.version=zookeeper C client 3.4.6
2018-03-15 13:56:49,486:70665(0x7f0eef010740):ZOO_INFO@log_env@716: Client environment:host.name=dsk_db90
2018-03-15 13:56:49,486:70665(0x7f0eef010740):ZOO_INFO@log_env@723: Client environment:os.name=Linux
2018-03-15 13:56:49,486:70665(0x7f0eef010740):ZOO_INFO@log_env@724: Client environment:os.arch=3.10.0-514.26.2.el7.x86_64
2018-03-15 13:56:49,486:70665(0x7f0eef010740):ZOO_INFO@log_env@725: Client environment:os.version=#1 SMP Tue Jul 4 15:04:05 UTC 2017
2018-03-15 13:56:49,487:70665(0x7f0eef010740):ZOO_INFO@log_env@733: Client environment:user.name=root
2018-03-15 13:56:49,487:70665(0x7f0eef010740):ZOO_INFO@log_env@741: Client environment:user.home=/root
2018-03-15 13:56:49,487:70665(0x7f0eef010740):ZOO_INFO@log_env@753: Client environment:user.dir=/tmp/zookeeper/version-2
2018-03-15 13:56:49,487:70665(0x7f0eef010740):ZOO_INFO@zookeeper_init@786: Initiating client connection, host=localhost:2181 sessionTimeout=10000 watcher=(nil) sessionId=0 sessionPasswd=<null> context=(nil) flags=0
>>> 2018-03-15 13:56:49,487:70665(0x7f0ee695d700):ZOO_INFO@check_events@1705: initiated connection to server [127.0.0.1:2181]
2018-03-15 13:56:49,494:70665(0x7f0ee695d700):ZOO_INFO@check_events@1752: session establishment complete on server [127.0.0.1:2181], sessionId=0x1622799854c0002, negotiated timeout=10000

>>> name = "dsk_moocdb"
>>> hostip = ?"10.0.7.91"
>>> uptime="uptime"
>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "uptime",uptime)
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>

zookeeper.NoNodeException: no node ? ?改报错是多级路径的话,必须一级级的先建立好
>>> zookeeper.create(zk,"/" + name ,hostip,[{"perms":0x1f,"scheme":"world","id":"anyone"}],0)

'/dsk_moocdb'

zookeeper.BadArgumentsException: bad arguments
>>> zookeeper.create(zk,"/" + name + "/" + hostip,hostip,[{"perms":0x1f,"scheme":"world","id":"anyone"}],0)
'/dsk_moocdb/10.0.7.91'
>>> zookeeper.get_children(zk,"/",None)
['dsk_moocdb', 'zookeeper', 'moocmysql', 'zk_for_py1', 'zk_for_py']

>>> zookeeper.get_children(zk,"/dsk_moocdb",None)
['10.0.7.91']

>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91",None)
[]
>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "uptime","uptime")
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
zookeeper.NoNodeException: no node

>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "uptime","uptime")
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
zookeeper.NoNodeException: no node
>>> print name
dsk_moocdb
>>> print hostip
10.0.7.91
>>> uptime="uptime"
>>> zookeeper.create(zk,"/" + name + "/" + hostip+"/"+uptime,uptime,[{"perms":0x1f,"scheme":"world","id":"anyone"}],1)
'/dsk_moocdb/10.0.7.91/uptime'
>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "uptime","uptime")
0
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91",None)
['uptime']
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime",None)
[]
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime",None)
[]
>>> import os
>>> uptime = os.popen('uptime').read()
>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "uptime",uptime)
0
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime",None)
[]
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime") ? ??
[]
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime")
[]
>>> print uptime?
?12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61
>>> zookeeper.get_children(zk,"/dsk_moocdb/10.0.7.91/uptime")
[]
>>> zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/uptime")
(' 12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61\n', {'pzxid': 42L, 'ctime': 1521088288214L, 'aversion': 0, 'mzxid': 44L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 2, 'dataLength': 71, 'mtime': 1521088366971L, 'cversion': 0, 'czxid': 42L})
>>> zookeeper.create(zk,"/" + name + "/" + hostip+"/"+uptime,uptime,[{"perms":0x1f,"scheme":"world","id":"anyone"}],0)
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
zookeeper.BadArgumentsException: bad arguments
>>> disk_full="disk_full"
>>> zookeeper.create(zk,"/" + name + "/" + hostip+"/"+disk_full,disk_full,[{"perms":0x1f,"scheme":"world","id":"anyone"}],1)
>>> zookeeper.create(zk,"/" + name + "/" + hostip+"/"+disk_full,disk_full,[{"perms":0x1f,"scheme":"world","id":"anyone"}],1)
'/dsk_moocdb/10.0.7.91/disk_full'

>>> zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/uptime") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
(' 12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61\n', {'pzxid': 42L, 'ctime': 1521088288214L, 'aversion': 0, 'mzxid': 44L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 2, 'dataLength': 71, 'mtime': 1521088366971L, 'cversion': 0, 'czxid': 42L})

>>> disk_full = os.popen('df -h').read() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
>>> zookeeper.set(zk,"/" + name + "/" + hostip + "/" + "disk_full",disk_full)
0

>>> zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/uptime") ? ? ? ? ? ? ? ? ? ? ? ??
(' 12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61\n', {'pzxid': 42L, 'ctime': 1521088288214L, 'aversion': 0, 'mzxid': 44L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 2, 'dataLength': 71, 'mtime': 1521088366971L, 'cversion': 0, 'czxid': 42L})

>>> zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")
('\xe6\x96\x87\xe4\xbb\xb6\xe7\xb3\xbb\xe7\xbb\x9f ? ? ? ?\xe5\xae\xb9\xe9\x87\x8f ?\xe5\xb7\xb2\xe7\x94\xa8 ?\xe5\x8f\xaf\xe7\x94\xa8 \xe5\xb7\xb2\xe7\x94\xa8% \xe6\x8c\x82\xe8\xbd\xbd\xe7\x82\xb9\n/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /\ndevtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev\ntmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm\ntmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run\ntmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup\n/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot\n/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1\n/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2\ntmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0\n/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak\n', {'pzxid': 45L, 'ctime': 1521088621727L, 'aversion': 0, 'mzxid': 46L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 1, 'dataLength': 535, 'mtime': 1521088787892L, 'cversion': 0, 'czxid': 45L})
>>> data=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/uptime")
>>>?
>>> print data[0]
?12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61
>>> print data[1]
{'pzxid': 42L, 'ctime': 1521088288214L, 'aversion': 0, 'mzxid': 44L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 2, 'dataLength': 71, 'mtime': 1521088366971L, 'cversion': 0, 'czxid': 42L}
>>> print data[2]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
>>> print data[0]
?12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61
>>> data=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")
>>> print data[0]
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak
>>> data=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")[0]
>>> print data[0]
>> pdata=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")
>>> print data[0]
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak
>>> data=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")
>>> print data[0]
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak
>>> data=zookeeper.get(zk,"/dsk_moocdb/10.0.7.91/disk_full")
>>> data1=data[1]
>>> print data1
{'pzxid': 45L, 'ctime': 1521088621727L, 'aversion': 0, 'mzxid': 46L, 'numChildren': 0, 'ephemeralOwner': 0L, 'version': 1, 'dataLength': 535, 'mtime': 1521088787892L, 'cversion': 0, 'czxid': 45L}
>>> print data1[0]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
KeyError: 0
>>> print data1[pzxid]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
NameError: name 'pzxid' is not defined
>>> print data1[pzxid]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
NameError: name 'pzxid' is not defined
>>> print data1[0] ? ?
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
KeyError: 0
>>> print data1[1]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
KeyError: 1
>>> num=len(data1)
>>> print num
11
>>> print data1[01]
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
KeyError: 1
>>> print data1['pzxid']
45
>>> print data1['numChildren']
0

>>>?
[root@dsk_db90 ~]# /tools/zookeeper-3.4.6/bin/zkCli.sh -server localhost:2181
Connecting to localhost:2181
2018-03-15 14:00:59,288 [myid:] - INFO ?[main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2018-03-15 14:00:59,294 [myid:] - INFO ?[main:Environment@100] - Client environment:host.name=<NA>
2018-03-15 14:00:59,294 [myid:] - INFO ?[main:Environment@100] - Client environment:java.version=1.8.0_141
2018-03-15 14:00:59,297 [myid:] - INFO ?[main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-03-15 14:00:59,298 [myid:] - INFO ?[main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre
2018-03-15 14:00:59,298 [myid:] - INFO ?[main:Environment@100] - Client environment:java.class.path=/tools/zookeeper-3.4.6/bin/../build/classes:/tools/zookeeper-3.4.6/bin/../build/lib/*.jar:/tools/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/tools/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/tools/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/tools/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/tools/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/tools/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/tools/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/tools/zookeeper-3.4.6/bin/../conf:
2018-03-15 14:00:59,298 [myid:] - INFO ?[main:Environment@100] - Client environment:java.library.path=/usr/local/lib::/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-03-15 14:00:59,298 [myid:] - INFO ?[main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-03-15 14:00:59,298 [myid:] - INFO ?[main:Environment@100] - Client environment:java.compiler=<NA>
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:os.name=Linux
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:os.arch=amd64
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:os.version=3.10.0-514.26.2.el7.x86_64
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:user.name=root
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:user.home=/root
2018-03-15 14:00:59,299 [myid:] - INFO ?[main:Environment@100] - Client environment:user.dir=/root
2018-03-15 14:00:59,301 [myid:] - INFO ?[main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5c29bfd
Welcome to ZooKeeper!
2018-03-15 14:00:59,333 [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)
JLine support is enabled
2018-03-15 14:00:59,429 [myid:] - INFO ?[main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2018-03-15 14:00:59,436 [myid:] - INFO ?[main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x1622799854c0003, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
[dsk_moocdb, zookeeper, moocmysql, zk_for_py1, zk_for_py]
[zk: localhost:2181(CONNECTED) 1] ls /dsk_moocdb
[10.0.7.91]
[zk: localhost:2181(CONNECTED) 2] help
ZooKeeper -server host:port cmd args
? ? ? ? stat path [watch]
? ? ? ? set path data [version]
? ? ? ? ls path [watch]
? ? ? ? delquota [-n|-b] path
? ? ? ? ls2 path [watch]
? ? ? ? setAcl path acl
? ? ? ? setquota -n|-b val path
? ? ? ? history?
? ? ? ? redo cmdno
? ? ? ? printwatches on|off
? ? ? ? delete path [version]
? ? ? ? sync path
? ? ? ? listquota path
? ? ? ? rmr path
? ? ? ? get path [watch]
? ? ? ? create [-s] [-e] path data acl
? ? ? ? addauth scheme auth
? ? ? ? quit?
? ? ? ? getAcl path
? ? ? ? close?
? ? ? ? connect host:port
[zk: localhost:2181(CONNECTED) 3] s2 /dsk_moocdb ? ??
ZooKeeper -server host:port cmd args
? ? ? ? stat path [watch]
? ? ? ? set path data [version]
? ? ? ? ls path [watch]
? ? ? ? delquota [-n|-b] path
? ? ? ? ls2 path [watch]
? ? ? ? setAcl path acl
? ? ? ? setquota -n|-b val path
? ? ? ? history?
? ? ? ? redo cmdno
? ? ? ? printwatches on|off
? ? ? ? delete path [version]
? ? ? ? sync path
? ? ? ? listquota path
? ? ? ? rmr path
? ? ? ? get path [watch]
? ? ? ? create [-s] [-e] path data acl
? ? ? ? addauth scheme auth
? ? ? ? quit?
? ? ? ? getAcl path
? ? ? ? close?
? ? ? ? connect host:port
[zk: localhost:2181(CONNECTED) 4] ls2 /dsk_moocdb
[10.0.7.91]
cZxid = 0x26
ctime = Thu Mar 15 12:27:16 CST 2018
mZxid = 0x26
mtime = Thu Mar 15 12:27:16 CST 2018
pZxid = 0x27
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 1
[zk: localhost:2181(CONNECTED) 5] ls2 /dsk_moocdb/10.0.7.91
[disk_full, uptime]
cZxid = 0x27
ctime = Thu Mar 15 12:27:33 CST 2018
mZxid = 0x27
mtime = Thu Mar 15 12:27:33 CST 2018
pZxid = 0x2d
cversion = 2
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 2
[zk: localhost:2181(CONNECTED) 6] ls2 /dsk_moocdb/10.0.7.91/disk_full
[]
cZxid = 0x2d
ctime = Thu Mar 15 12:37:01 CST 2018
mZxid = 0x2e
mtime = Thu Mar 15 12:39:47 CST 2018
pZxid = 0x2d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 535
numChildren = 0
[zk: localhost:2181(CONNECTED) 7] ls2 /dsk_moocdb/10.0.7.91/uptime ??
[]
cZxid = 0x2a
ctime = Thu Mar 15 12:31:28 CST 2018
mZxid = 0x2c
mtime = Thu Mar 15 12:32:46 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 71
numChildren = 0
[zk: localhost:2181(CONNECTED) 8] ls2 /dsk_moocdb/10.0.7.91/uptime/
Command failed: java.lang.IllegalArgumentException: Path must not end with / character
[zk: localhost:2181(CONNECTED) 9] ls2 /dsk_moocdb/10.0.7.91/uptime?
[]
cZxid = 0x2a
ctime = Thu Mar 15 12:31:28 CST 2018
mZxid = 0x2c
mtime = Thu Mar 15 12:32:46 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 71
numChildren = 0
[zk: localhost:2181(CONNECTED) 10] ls /dsk_moocdb/10.0.7.91/uptime?
[]
[zk: localhost:2181(CONNECTED) 11] ls2 /dsk_moocdb/10.0.7.91/uptime
[]
cZxid = 0x2a
ctime = Thu Mar 15 12:31:28 CST 2018
mZxid = 0x2c
mtime = Thu Mar 15 12:32:46 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 71
numChildren = 0
[zk: localhost:2181(CONNECTED) 12] help
ZooKeeper -server host:port cmd args
? ? ? ? stat path [watch]
? ? ? ? set path data [version]
? ? ? ? ls path [watch]
? ? ? ? delquota [-n|-b] path
? ? ? ? ls2 path [watch]
? ? ? ? setAcl path acl
? ? ? ? setquota -n|-b val path
? ? ? ? history?
? ? ? ? redo cmdno
? ? ? ? printwatches on|off
? ? ? ? delete path [version]
? ? ? ? sync path
? ? ? ? listquota path
? ? ? ? rmr path
? ? ? ? get path [watch]
? ? ? ? create [-s] [-e] path data acl
? ? ? ? addauth scheme auth
? ? ? ? quit?
? ? ? ? getAcl path
? ? ? ? close?
? ? ? ? connect host:port
[zk: localhost:2181(CONNECTED) 13] get /dsk_moocdb/10.0.7.91/uptime
?12:32:35 up 35 days, 19:33, ?3 users, ?load average: 0.55, 0.72, 0.61

cZxid = 0x2a
ctime = Thu Mar 15 12:31:28 CST 2018
mZxid = 0x2c
mtime = Thu Mar 15 12:32:46 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 71
numChildren = 0
[zk: localhost:2181(CONNECTED) 14] get /dsk_moocdb/10.0.7.91/disk_full
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak

cZxid = 0x2d
ctime = Thu Mar 15 12:37:01 CST 2018
mZxid = 0x2e
mtime = Thu Mar 15 12:39:47 CST 2018
pZxid = 0x2d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 535
numChildren = 0
[zk: localhost:2181(CONNECTED) 15] get /dsk_moocdb/10.0.7.91/disk_full.1
Node does not exist: /dsk_moocdb/10.0.7.91/disk_full.1
[zk: localhost:2181(CONNECTED) 16] get /dsk_moocdb/10.0.7.91/disk_full ?
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak

cZxid = 0x2d
ctime = Thu Mar 15 12:37:01 CST 2018
mZxid = 0x2e
mtime = Thu Mar 15 12:39:47 CST 2018
pZxid = 0x2d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 535
numChildren = 0
[zk: localhost:2181(CONNECTED) 17] get /dsk_moocdb/10.0.7.91/disk_full[0]
Node does not exist: /dsk_moocdb/10.0.7.91/disk_full[0]
[zk: localhost:2181(CONNECTED) 18] get /dsk_moocdb/10.0.7.91/disk_full[1]
Node does not exist: /dsk_moocdb/10.0.7.91/disk_full[1]
[zk: localhost:2181(CONNECTED) 19] get /dsk_moocdb/10.0.7.91/disk_full ??
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak

cZxid = 0x2d
ctime = Thu Mar 15 12:37:01 CST 2018
mZxid = 0x2e
mtime = Thu Mar 15 12:39:47 CST 2018
pZxid = 0x2d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 535
numChildren = 0
[zk: localhost:2181(CONNECTED) 20] get /dsk_moocdb/10.0.7.91/disk_full
文件系统 ? ? ? ?容量 ?已用 ?可用 已用% 挂载点
/dev/sda3 ? ? ? 542G ?6.7G ?535G ? ?2% /
devtmpfs ? ? ? ?126G ? ? 0 ?126G ? ?0% /dev
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /dev/shm
tmpfs ? ? ? ? ? 126G ? 82M ?126G ? ?1% /run
tmpfs ? ? ? ? ? 126G ? ? 0 ?126G ? ?0% /sys/fs/cgroup
/dev/sda1 ? ? ? 497M ?165M ?333M ? 34% /boot
/dev/sdb1 ? ? ? 3.7T ?1.8T ?2.0T ? 48% /sqldata1
/dev/sdd ? ? ? ?3.7T ?1.8T ?2.0T ? 48% /sqldata2
tmpfs ? ? ? ? ? ?26G ? ? 0 ? 26G ? ?0% /run/user/0
/dev/sdc ? ? ? ? 17T ? 12T ?4.4T ? 74% /mysqlbak

cZxid = 0x2d
ctime = Thu Mar 15 12:37:01 CST 2018
mZxid = 0x2e
mtime = Thu Mar 15 12:39:47 CST 2018
pZxid = 0x2d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 535
numChildren = 0
[zk: localhost:2181(CONNECTED) 21] ls /
[dsk_moocdb, zookeeper, moocmysql, zk_for_py1, zk_for_py]
[zk: localhost:2181(CONNECTED) 22] get /dsk_moocdb ? ? ? ? ? ? ? ? ? ? ??
10.0.7.91
cZxid = 0x26
ctime = Thu Mar 15 12:27:16 CST 2018
mZxid = 0x26
mtime = Thu Mar 15 12:27:16 CST 2018
pZxid = 0x27
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 9
numChildren = 1
[zk: localhost:2181(CONNECTED) 23]?

原文地址:https://www.cnblogs.com/iiiiiher/p/10442946.html

时间: 2024-10-09 10:45:44

[py]python操作zookeeper的相关文章

python 操作zookeeper详解

ZooKeeper 简介 ZooKeeper 是一个分布式的.开放源码的分布式应用程序协调服务,是 Google 的 Chubby 一个开源的实现,是 Hadoop 和 Hbase 的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.域名服务.分布式同步.组服务等.ZooKeeper 支持大部分开发语言,除了某些特定的功能只支持 Java 和 C.python 通过 kazoo 可以实现操作 ZooKeeper . 一.安装 这个简单,使用 pip 命令安装 pip3

Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy

Python之路[第九篇]:Python操作 RabbitMQ.Redis.Memcache.SQLAlchemy Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached基于一个存储键/值对的hashmap.其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信. Memc

Python学习之使用Python操作Redis数据库

最近在写一个检查一台服务器上所有游戏区服配置文件中redis某个key值大小的脚本,本打算使用shell+awk+sed的方式去解决这个问题,但是由于redis的配置信息是php数组形式.shell脚本一时没有写出来,就请教他人帮忙写了个python脚本,但是自己python不是很精通,于是按照脚本中涉及到的python知识现学现用,然后根据自己的需求更改脚本.这里分享一下如何使用python操作redis数据库. Redis的Python驱动源码下载地址是https://github.com/

使用python操作mysql数据库

这是我之前使用mysql时用到的一些库及开发的工具,这里记录下,也方便我查阅. python版本: 2.7.13 mysql版本: 5.5.36 几个python库 1.mysql-connector-python 是MySQL官方的Python驱动 https://dev.mysql.com/doc/connector-python/en/ 安装: pip install mysql-connector 示例代码: https://github.com/mike-zhang/pyExample

使用python操作RabbitMQ,Redis,Memcache,SQLAlchemy 其二

一.概念 1.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached基于一个存储键/值对的hashmap.其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信. 2.RabbitMQ RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla

八、python操作excel及网络编程和异常处理

一.python操作excel 1.读excel,xlrd模块用来读excel # book = xlrd.open_workbook(r'students.xlsx')#打开excel# print(book.sheet_names())#获取所有sheet的名字# sheet = book.sheet_by_index(0)#根据sheet页的位置去取sheet# sheet2 = book.sheet_by_name('Sheet2')#根据sheet页的名字获取sheet页# print

十一天 python操作rabbitmq、redis

1.启动rabbimq.mysql 在""运行""里输入services.msc,找到rabbimq.mysql启动即可 2.启动redis 管理员进入cmd,进入redis所在目录,执行redis-server.exe redis.windows.conf --maxmemory 200M  启动redis  server 执行redis-cli.exe启动客户端 一.python系列之 RabbitMQ - work queues 本节我们创建一个工作队列( w

Python操作Redis、Memcache、RabbitMQ、SQLAlchemy

Python操作 Redis.Memcache.RabbitMQ.SQLAlchemy redis介绍:redis是一个开源的,先进的KEY-VALUE存储,它通常被称为数据结构服务器,因为键可以包含string(字符串).hash(哈希).list(链表).set(集合)和zset(有序集合),这些数据类型都支持push/pop.add/remove及取交集和并集及更丰富的操作,redis支持各种不同方式的排序.为了保证效率,数据都是缓存在内存中,它也可以周期性的把更新的数据写入磁盘或者把修改

Python操作Memcache

Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached基于一个存储键/值对的hashmap.其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过memcached协议与守护进程通信. Memcached安装和基本使用 Memcached安装: 1 wget http://memcached.org/late