ZooKeeper客户端命令行操作

ZooKeeper客户端命令行操作

  1. 启动服务端

    [[email protected] zookeeper-3.4.10]$ bin/zkServer.sh start
  2. 查看状态信息
    Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    [[email protected] zookeeper-3.4.10]$ bin/zkServer.sh status
    ZooKeeper JMX enabled by default
    Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
    Mode: follower
  3. 启动客户端
    [[email protected] zookeeper-3.4.10]$ bin/zkCli.sh
  4. 查看当前znode中所包含的内容
    [zk: localhost:2181(CONNECTED) 1] ls /
    [zookeeper]
  5. 查看当前节点的详细数据
    [zk: localhost:2181(CONNECTED) 2] ls2 /
    [zookeeper]
    cZxid = 0x0
    ctime = Thu Jan 01 08:00:00 CST 1970
    mZxid = 0x0
    mtime = Thu Jan 01 08:00:00 CST 1970
    pZxid = 0x0
    cversion = -1
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 0
    numChildren = 1
  6. 分别创建两个普通节点
    [zk: localhost:2181(CONNECTED) 3] create /simon "user"
    [zk: localhost:2181(CONNECTED) 0] create /simon/a "a"
    Created /simon/a
  7. 获得节点的值
    [zk: localhost:2181(CONNECTED) 1] get /simon
    user
    cZxid = 0x100000004
    ctime = Thu Oct 24 21:59:31 CST 2019
    mZxid = 0x100000004
    mtime = Thu Oct 24 21:59:31 CST 2019
    pZxid = 0x100000007
    cversion = 1
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 4
    numChildren = 1
    
    [zk: localhost:2181(CONNECTED) 2] get /simon/a
    a
    cZxid = 0x100000007
    ctime = Thu Oct 24 22:19:10 CST 2019
    mZxid = 0x100000007
    mtime = Thu Oct 24 22:19:10 CST 2019
    pZxid = 0x100000007
    cversion = 0
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 1
    numChildren = 0
  8. 创建临时节点
    [zk: localhost:2181(CONNECTED) 3] create -e /simon/temp "temp"
    Created /simon/temp

    (1)在客户端可以查看到

    [zk: localhost:2181(CONNECTED) 5] ls /simon
    [a, temp]
    

    (2)退出当前客户端之后再重启客户端

    [zk: localhost:2181(CONNECTED) 6] quit
    Quitting...
    2019-10-24 22:22:00,789 [myid:] - INFO  [main:[email protected]] - Session: 0x26dfe0bc0f60002 closed
    2019-10-24 22:22:00,790 [myid:] - INFO  [main-EventThread:[email protected]] - EventThread shut down for session: 0x26dfe0bc0f60002
    
    [[email protected] zookeeper-3.4.10]$ bin/zkCli.sh
    

    (3)再次查看根目录下临时节点已经被删除

    [zk: localhost:2181(CONNECTED) 0] ls /simon
    [a]
    
  9. 创建带序号的节点

    (1)先创建一个普通的根节点/simon/b

    [zk: localhost:2181(CONNECTED) 1] create /simon/b "b"
    Created /simon/b
    

    (2)创建一个带序号的节点

    [zk: localhost:2181(CONNECTED) 1] create -s /simon/b/ba "ba"
    Created /simon/b/ba0000000001
    [zk: localhost:2181(CONNECTED) 2] create -s /simon/b/bb "bb"
    Created /simon/b/bb0000000002
    [zk: localhost:2181(CONNECTED) 3] create -s /simon/b/bc "bc"
    Created /simon/b/bc0000000003
    

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

  10. 修改节点数据的值
    [zk: localhost:2181(CONNECTED) 4] set /simon/b "B"
    
    [zk: localhost:2181(CONNECTED) 5] get /simon/b
    [zk: localhost:2181(CONNECTED) 5] get /simon/b
    B
    cZxid = 0x10000000b
    ctime = Thu Oct 24 22:23:07 CST 2019
    mZxid = 0x100000012
    mtime = Thu Oct 24 22:26:16 CST 2019
    pZxid = 0x100000011
    cversion = 4
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 1
    numChildren = 4
    
  11. 节点值的变化监听

    (1)在Hadoop104主机上注册监听/simon节点数据的变化

    [zk: localhost:2181(CONNECTED) 0] get /simon watch    #监听根节点用:get 子节点:ls
    user
    cZxid = 0x100000004
    ctime = Thu Oct 24 21:59:31 CST 2019
    mZxid = 0x100000004
    mtime = Thu Oct 24 21:59:31 CST 2019
    pZxid = 0x10000000b
    cversion = 4
    dataVersion = 0
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 4
    numChildren = 2
    

    (2)在Hadoop103主机上修改/simon节点的数据

    [zk: localhost:2181(CONNECTED) 0] set /simon "hello world"
    cZxid = 0x100000004
    ctime = Thu Oct 24 21:59:31 CST 2019
    mZxid = 0x100000015
    mtime = Thu Oct 24 22:29:32 CST 2019
    pZxid = 0x10000000b
    cversion = 4
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 11
    numChildren = 2
    

    (3)在Hadoop104节点上观察数据的变化的监听

    [zk: localhost:2181(CONNECTED) 1]
    WATCHER::
    
    WatchedEvent state:SyncConnected type:NodeDataChanged path:/simon
    
  12. 节点的子节点变化监听(路劲变化)

    (1)在Hadoop104主机上注册监听/simon节点的子节点变化

    [zk: localhost:2181(CONNECTED) 0] ls /simon watch
    [a, b]
    

    (2)在Hadoop103主机/simon节点创建子节点

    [zk: localhost:2181(CONNECTED) 4] create /simon/c "c"
    Created /simon/c
    

    (3)观察Hadoop104主机收到的子节点变化的监听

    [zk: localhost:2181(CONNECTED) 4] ls /simon watch
    WATCHER::
    
    WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/simon
    
  13. 删除节点
    [zk: localhost:2181(CONNECTED) 6] delete /simon/b/bd
    
  14. 递归删除节点
    [zk: localhost:2181(CONNECTED) 7] rmr /simon/b
    
  15. 查看节点的状态
    [zk: localhost:2181(CONNECTED) 8] stat /simon
    cZxid = 0x100000004
    ctime = Thu Oct 24 21:59:31 CST 2019
    mZxid = 0x100000015
    mtime = Thu Oct 24 22:29:32 CST 2019
    pZxid = 0x100000021
    cversion = 6
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 11
    numChildren = 2
    

原文地址:https://www.cnblogs.com/simon-1024/p/11741465.html

时间: 2024-10-03 04:59:58

ZooKeeper客户端命令行操作的相关文章

zookeeper客户端命令行查看dubbo服务的生产者和消费者

假设zookeeper安装在192.168.5.130这台服务器上,现在我们通过命令行查看dubbo在zookeeper注册服务的生产者和消费者信息 首先通过命令切换到/usr/zookeeper-3.4.10/bin目录,然后输入 ./zkCli.sh -server 192.168.5.130:2888 (2888为zookeeper在服务器上提供服务的端口)会看到如下截图: 然后在命令行再输入: ls / 查看目录信息,就能看到注册的dubbo服务,截图如下: 3 在命令行依次输入: ls

zookeeper基本特性与基于Linux的ZK客户端命令行学习

zookeeper常用命令行操作 通过 zkCli.sh 来打开zk客户端: [[email protected] ~]# zkCli.sh [zk: localhost:2181(CONNECTED) 0] ls 与 ls2 命令: [zk: localhost:2181(CONNECTED) 0] ls / # ls命令用于查看节点,类似于Linux中的查看目录 [zookeeper] [zk: localhost:2181(CONNECTED) 1] ls2 / # ls2命令用于查看节点

CentOS7.5搭建Zookeeper3.4.12集群与命令行操作

一. 分布式安装部署 1.0 下载地址 官网首页: https://zookeeper.apache.org/ 下载地址: http://mirror.bit.edu.cn/apache/zookeeper/ 1.1 集群规划 在node21.node22和ode23三个节点上部署Zookeeper,三个节点都已安装jdk. IP 节点名称 Zookeeper JDK 192.168.100.21 node21 Zookeeper JDK 192.168.100.22 node22 Zookee

Ubuntu server版上使用命令行操作VPN客户端

Ubuntu server版上使用命令行操作VPN客户端 VPN,虚拟专用网络,这个技术还是非常实用的.最近笔者参与的项目中就使用上了VPN,大概情况是这样的,有两个开发团队,在异地,代码服务器在深圳了,它使用的是企业内部局域网,支持上网功能的,我们在公网上弄了个阿里云服务器,装了ubuntu vpn的server,其实我们现在要做的就是把代码服务器通过VPN拨号上去,组建一个新的本地网络,怎么大家VPN的server笔者就不在这描述了,网上已经有大把资料了,笔者下面就简要介绍一下自己在代码服务

zookeeper入门(3)-Zookeeper命令行操作

1.运行zookeeper主目录下的zkCli.sh,即进入zookeeper的命令行工具. 2.查看znode路径 ls / ----查看根路径下的节点 3.获取znode数据 get /zookeeper -----获取/zookeeper这个节点下面的数据 4.监听znode事件 ls /test  watch     ## 就对一个节点的子节点变化事件注册了监听,如下图,当创建了新的子节点,监听器监听到了该事件 get /test watch     ## 就对一个节点的数据内容变化事件

Zookeeper客户端java代码操作

Zookeeper客户端java代码操作 上篇博客记录了shell命令操作zookeeper集群的方式,这次尝试采用java代码来操作.通过查阅API,发现并不困难. 1. 首先获得客户端与服务器的连接 //zookeeper客户端 private ZooKeeper zkCli; //连接地址 private static final String CONNECT_STRING = "hadoop102:2181,hadoop103:2181,hadoop104:2181"; //s

HDFS命令行操作 和 api操作

HDFS,是Hadoop Distributed File System的简称,是Hadoop抽象文件系统的一种实现.Hadoop抽象文件系统可以与本地系统.Amazon S3等集成,甚至可以通过Web协议(webhsfs)来操作.HDFS的文件分布在集群机器上,同时提供副本进行容错及可靠性保证.例如客户端写入读取文件的直接操作都是分布在集群各个机器上的,没有单点性能压力. HDFS相关的搭建可以看我前面的一篇博文,我们今天主要来讲下怎么操作hdfs的api和 hdfs命令行, java内操作H

2015.12.01 软件安装 命令行操作 vi

软件安装 1.App Store 2..dmg/.pkg(相当于光盘镜像) 双击安装 3.绿色软件,*.app 直接拖拽到Application (非官方的安装,要注意在偏好设置中允许任何来源) 常用网址:www.macx.cn        bbs.feng.com 在对MacOS系统的操作当中,有两种操作方式.一种就是图形化操作,另一种就是命令行操作.对比而言,前者更直观,而后者则是更便捷并且节约资源. 基本命令 ls                           查看当前文件夹下的文

ubuntu命令行操作mysql常用操作

登陆mysql [email protected]:~/ruby/mydiary$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. 查看所有的数据库 mysql> show databases; --注意必须要用;结尾否则不会立即执行代码 +--------------------+ | Database | +--------------------+ | inf