龙空技术网

Zookeeper客户端命令行操作

Linux云计算架构 138

前言:

此刻朋友们对“命令行打开系统设置”大概比较珍视,姐妹们都想要剖析一些“命令行打开系统设置”的相关内容。那么小编也在网络上汇集了一些关于“命令行打开系统设置””的相关知识,希望你们能喜欢,看官们快快来了解一下吧!

集群操作(1)分别启动Zookeeper

[root@sparkproject001 bin]# /usr/myproject/zookeeper-3.4.10/bin/zkServer.sh start

[root@sparkproject001 bin]# /usr/myproject/zookeeper-3.4.10/bin/zkServer.sh start

[root@sparkproject001 bin]# /usr/myproject/zookeeper-3.4.10/bin/zkServer.sh start

(2)启动客户端命令基本语法

help:显示所有操作命令ls path [watch] :使用 ls 命令来查看当前znode中所包含的内容ls2 path [watch]:查看当前节点数据并能看到更新次数等数据create普通创建-s 含有序列-e 临时(重启或者超时消失)get path [watch]: 获得节点的值set:设置节点的具体值stat:查看节点状态delete:删除节点rmr :递归删除节点

1、help:显示所有操作命令

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

2、分别创建2个普通节点

[zk: sparkproject001:2181(CONNECTED) 1] create /test1 'test1 infor'

Created /test1

[zk: sparkproject001:2181(CONNECTED) 2] create /test1/x1 'test1x1 infor'

Created /test1/x1

[zk: sparkproject001:2181(CONNECTED) 3]

3、获取某节点

[zk: sparkproject001:2181(CONNECTED) 3] get /test1

4、查看列表ls命令

[zk: sparkproject001:2181(CONNECTED) 5] ls /

[cluster, controller_epoch, brokers, zookeeper, admin, isr_change_notification, consumers,

latest_producer_id_block, config, test1]

5、查看列表ls2命令

[zk: sparkproject001:2181(CONNECTED) 6] ls2 /

[cluster, controller_epoch, brokers, zookeeper, admin, isr_change_notification, consumers,

latest_producer_id_block, config, test1]

cZxid = 0x0

ctime = Thu Jan 01 08:00:00 CST 1970

mZxid = 0x0

mtime = Thu Jan 01 08:00:00 CST 1970

pZxid = 0x200000002

cversion = 16

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 0

numChildren = 10

6、创建短暂节点

[zk: sparkproject001:2181(CONNECTED) 0] create -e /TempTest1 'temp node info'

Created /TempTest1

[zk: sparkproject001:2181(CONNECTED) 1] ls /

[cluster, controller_epoch, brokers, zookeeper, admin, isr_change_notification, consumers, TempTest1, latest_producer_id_block, config, test1]

没有退出之前是可以查看到临时节点的,退出后再次查看是看不到临时节点的;

[zk: sparkproject001:2181(CONNECTED) 2] quit

Quitting...

2023-05-30 17:03:39,761 [myid:] - INFO [main:ZooKeeper@684] - Session: 0x1886bda653a0002 closed

[zk: sparkproject001:2181(CONNECTED) 0] ls /

[cluster, controller_epoch, brokers, zookeeper, admin, isr_change_notification, consumers, latest_producer_id_block, config, test1]

7、创建带序号的节点

[zk: sparkproject001:2181(CONNECTED) 0] create -s /test1/x2 'x2 have num'

Created /test1/x20000000001

[zk: sparkproject001:2181(CONNECTED) 1] create -s /test1/x3 'x2 have num'

Created /test1/x30000000002

[zk: sparkproject001:2181(CONNECTED) 2]

如果原来没有序号节点,序号从0开始依次递增。如果原节点下已有2个节点,则再排序时从2开始,以此类推。

8、修改节点set命令

[zk: sparkproject001:2181(CONNECTED) 2] set /test1/x1 'update x1 infor'

cZxid = 0x200000003

ctime = Tue May 30 16:55:04 CST 2023

mZxid = 0x20000000f

mtime = Tue May 30 17:08:06 CST 2023

pZxid = 0x200000003

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 15

numChildren = 0

9、节点的值变化监听

[zk: sparkproject001:2181(CONNECTED) 3] get /test1/x1 watch

update x1 infor

cZxid = 0x200000003

ctime = Tue May 30 16:55:04 CST 2023

mZxid = 0x20000000f

mtime = Tue May 30 17:08:06 CST 2023

pZxid = 0x200000003

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 15

numChildren = 0

第二步:在另一台机器是修改/test1/x1节点的值:

[zk: sparkproject002:2181(CONNECTED) 1] set /test1/x1 'second modifaction'

cZxid = 0x200000003

ctime = Tue May 30 16:55:04 CST 2023

mZxid = 0x200000011

mtime = Tue May 30 17:12:22 CST 2023

pZxid = 0x200000003

cversion = 0

dataVersion = 2

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 18

numChildren = 0

[zk: sparkproject002:2181(CONNECTED) 2]

第三步:可以看到第一台监听机会发出修改通知

[zk: sparkproject001:2181(CONNECTED) 4]

WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:/test1/x1

10、查看节点状态

[zk: sparkproject002:2181(CONNECTED) 2] stat /test1/x1

cZxid = 0x200000003

ctime = Tue May 30 16:55:04 CST 2023

mZxid = 0x200000011

mtime = Tue May 30 17:12:22 CST 2023

pZxid = 0x200000003

cversion = 0

dataVersion = 2

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 18

numChildren = 0

11、删除节点

[zk: sparkproject002:2181(CONNECTED) 9] delete /test1/x1

12、递归删除节点

[zk: sparkproject002:2181(CONNECTED) 10] rmr /test1

标签: #命令行打开系统设置