Zookeeper基本數據模型

ZooKeeper基本數據模型

3.1 基本數據模型介紹

  • zk的數據模型也能夠理解爲linux/unix的文件目錄: /usr/local/...
  • 每個節點都稱之爲znode, 它能夠有子節點, 也能夠有數據
  • 每一個節點分爲臨時節點和永久節點,臨時節點在客戶端斷開後消失
  • 每個zk節點都有各自的版本號, 能夠經過命令行來顯示節點信息
  • 每當節點數據發生變化, 那麼該節點的版本號會累加(樂觀鎖)
  • 刪除/修改過期節點, 版本號不匹配會報錯
  • 每一個zk節點存儲的數據不宜過大, 幾k便可
  • 節點能夠設置權限acl, 能夠經過權限來限制用戶的訪問

3.2 ZooKeeper數據模型的基本操做

  • 客戶端鏈接node

    • $ZOOKEEPER_HOME/bin 運行zkServer.sh start 開啓zookeeperlinux

    • 進入客戶端shell

      ./zkCli.sh
      
      2018-12-29 02:23:22,904 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x167f60ba5ea0002, negotiated timeout = 30000
      
      WATCHER::
      
      WatchedEvent state:SyncConnected type:None path:null
      [zk: localhost:2181(CONNECTED) 0]
      • ls 列出目錄 help 查看幫助
      WatchedEvent state:SyncConnected type:None path:null
      [zk: localhost:2181(CONNECTED) 0] ls /
      [zookeeper]
      [zk: localhost:2181(CONNECTED) 1] ls /zookeeper
      [quota]
      [zk: localhost:2181(CONNECTED) 2] ls /zookeeper/quota
      []
      [zk: localhost:2181(CONNECTED) 3] 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
  • 查看znode結構session

    • ls 列出目錄 help 查看幫助ui

      WatchedEvent state:SyncConnected type:None path:null
      [zk: localhost:2181(CONNECTED) 0] ls /
      [zookeeper]
      [zk: localhost:2181(CONNECTED) 1] ls /zookeeper
      [quota]
      [zk: localhost:2181(CONNECTED) 2] ls /zookeeper/quota
      []
      [zk: localhost:2181(CONNECTED) 3] 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
  • 關閉客戶端鏈接 ctrl+c命令行

相關文章
相關標籤/搜索