前言

在前章ZooKeeper安装(集群化)我们安装ZooKeeper集群. 本章, 我们讲解下ZooKeeper的基本操作.


命令行操作

我们通常使用zkCli.sh脚本进行登陆.登陆命令:./zkCli.sh --server 192.168.31.60:2181
其后,基本操作主要有如下几种:

  • help命令
    显示客户所支持的所有命令,如:
[zk: 192.168.31.60:2181(CONNECTED) 2] h
ZooKeeper -server host:port cmd argsstat path [watch]set path data [version]ls path [watch]delquota [-n|-b] pathls2 path [watch]setAcl path aclsetquota -n|-b val pathhistoryredo cmdnoprintwatches on|offdelete path [version]sync pathlistquota pathrmr pathget path [watch]create [-s] [-e] path data acladdauth scheme authquitgetAcl pathcloseconnect host:port

其中, 用的比较多的有create/ls/delete/set/close/rmr.

  • create [-s] [-e] path data acl -s为顺序充点,-e临时节点
    例如:create /servers/hello/1 "123" world:anyone:cdrwa 需要特别注意的是,创建的父结点需要存在.否则会创建失败.
# 失败
[zk: 192.168.31.60:2181(CONNECTED) 7] create /servers/hello/1 ""
Node does not exist: /servers/hello/1
# 成功
[zk: 192.168.31.60:2181(CONNECTED) 13] create /servers/hello "123" world:anyone:cdrwa
Created /servers/hello
  • ls path [watch] 其中[watch]相当于观察者.回调函数.
[zk: 192.168.31.60:2181(CONNECTED) 17] ls /servers
[hello]
  • delete path [version] 删除单个结点.注意不能循环删除.(即/servers/hello无法直接删除父亲结点/servers,需要先删除子结点再删除父结点. )
# 删除失败
[zk: 192.168.31.60:2181(CONNECTED) 15] delete /servers
Node not empty: /servers
# 删除成功
[zk: 192.168.31.60:2181(CONNECTED) 19] delete /servers/hello/1
[zk: 192.168.31.60:2181(CONNECTED) 20] delete /servers/hello
[zk: 192.168.31.60:2181(CONNECTED) 22] delete /servers
  • set path data [version]get path [watch]: 设置结点 / 获得结点
[zk: 192.168.31.60:2181(CONNECTED) 25] get /servers
"123"
cZxid = 0x30000000d
ctime = Sat Mar 23 06:26:54 PDT 2019
mZxid = 0x30000000d
mtime = Sat Mar 23 06:26:54 PDT 2019
pZxid = 0x30000000d
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
[zk: 192.168.31.60:2181(CONNECTED) 26] set /servers "456"
cZxid = 0x30000000d
ctime = Sat Mar 23 06:26:54 PDT 2019
mZxid = 0x30000000e
mtime = Sat Mar 23 06:27:19 PDT 2019
pZxid = 0x30000000d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
[zk: 192.168.31.60:2181(CONNECTED) 27] get /servers
"456"
cZxid = 0x30000000d
ctime = Sat Mar 23 06:26:54 PDT 2019
mZxid = 0x30000000e
mtime = Sat Mar 23 06:27:19 PDT 2019
pZxid = 0x30000000d
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
  • rmr path 强制删除.可以级联删除.
[zk: 192.168.31.60:2181(CONNECTED) 29] rmr /servers
  • history查看历史命令
[zk: 192.168.31.60:2181(CONNECTED) 30] history
20 - delete /servers/hello
21 - delete /servers/
22 - delete /servers
23 - ls
24 - create /servers "123"
25 - get /servers
26 - set /servers "456"
27 - get /servers
28 - rmr servers
29 - rmr /servers
30 - history
  • stat查看结点信息
[zk: 192.168.31.60:2181(CONNECTED) 32] stat /servers
cZxid = 0x300000010
ctime = Sat Mar 23 06:29:53 PDT 2019
mZxid = 0x300000010
mtime = Sat Mar 23 06:29:53 PDT 2019
pZxid = 0x300000010
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
  • close: 断开客户端与服务端的连接.
  • ls2: ls的扩展,多显示一层.
  • setquota 设置子结点配额.
# 设置/zookeeper/node子节点个数最大为4
[zk: 192.168.31.60:2181(CONNECTED) 39] setquota -n 4   /servers
Comment: the parts are option -n val 4 path /servers
# 设置/zookeeper/node节点长度最大为100
setquota –b 100 /zookeeper/node
[zk: 192.168.31.60:2181(CONNECTED) 40] setquota -b 100   /servers
Comment: the parts are option -b val 100 path /servers
Command failed: java.lang.IllegalArgumentException: /servers has a parent /zookeeper/quota/servers which has a quota
# 貌似只能选择其一
  • delquota 删除配额. -n为子节点个数, -b为节点数据长度.如delquota –n 2.
  • listquota 显示配额.没有配置则显示为空.
# 不显示
[zk: 192.168.31.60:2181(CONNECTED) 41] listquota /servers/hello
absolute path is /zookeeper/quota/servers/hello/zookeeper_limits
quota for /servers/hello does not exist.
# 显示
[zk: 192.168.31.60:2181(CONNECTED) 42] listquota /servers
absolute path is /zookeeper/quota/servers/zookeeper_limits
Output quota for /servers count=4,bytes=-1
Output stat for /servers count=2,bytes=18
  • printwatches: 设置和显示监视状态, on或者off. printwatches on

  • sync: 强制同步. 如sync /servers. 由于请求在半数以上的zk server上生效就表示此请求生效, 那么就会有一些zk server上的数据是旧的. sync命令就是强制同步所有的更新操作.(即所有的都更新完毕后,再进行其他操作.)

  • redo: 再次执行某命令. 如redo 10. 其中10为命令ID,需与history配合使用。

setAcl命令: 设置节点Acl.

此处重点说一下acl,acl由大部分组成:1为scheme,2为user,3为permission,一般情况下表示为scheme?permissions。

其中scheme和id是相关的,下面将scheme和id一起说明。

  • scheme和id
    world: 它下面只有一个id, 叫anyone, world:anyone代表任何人,zookeeper中对>所有人有权限的结点就是属于world:anyone的.
  • auth: 它不需要id, 只要是通过authentication的user都有权限(zookeeper支持通过kerberos来进行authencation, 也支持username/password形式的authentication)
  • digest: 它对应的id为username:BASE64(SHA1(password)),它需要先通过username:password形式的authentication
  • ip: 它对应的id为客户机的IP地址,设置的时候可以设置一个ip段,比如ip:192.168.1.0/16, 表示匹配前16个bit的IP段
    super: 在这种scheme情况下,对应的id拥有超级权限,可以做任何事情(cdrwa)
  • permissions
    CREATE©: 创建权限,可以在在当前node下创建child node
    DELETE(d): 删除权限,可以删除当前的node
    READ®: 读权限,可以获取当前node的数据,可以list当前node所有的child nodes
    WRITE(w): 写权限,可以向当前node写数据
    ADMIN(a): 管理权限,可以设置当前node的permission
    综上,一个简单使用setAcl命令,则可以为:
    setAcl /zookeeper/node1 world:anyone:cdrw
  • getAcl: 获取节点Acl。如
getAcl /zookeeper/node1
'world,'anyone
: cdrwa

注:可参见setAcl命令。

addauth: 节点认证。
addauth digest username:password,可参见setAcl命令digest处。
使用方法:
一、通过setAcl设置用户名和密码

setAcl pathdigest:username:base64(sha1(password)):crwda

二、认证

addauth digest username:password


Java API

ZooKeeper提供的API主要使用的有:

  • ZooKeeper

  • ZKClient

  • Cursor
    三种包的使用有点不太相同.但是都是基于命令行的形式,完成了它们各自的API. 主要提供都API:皆为zkClient()/create()/delete()/exists()/getChildren()等等.

  • ZooKeeper

     <!-- ZK Dependence --><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.6</version></dependency>

OriginZooKeeperAPIs

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;import java.io.IOException;
import java.util.List;public class OriginZooKeeperAPIs {private static String connStr =  "192.168.31.60:2181,192.168.31.61:2181,192.168.31.62:2181";private static int timeout = 2000;private static ZooKeeper zooKeeper =  null;//建立客户端连接public static void init() throws IOException {zooKeeper = new ZooKeeper(connStr, timeout, new Watcher() {@Overridepublic void process(WatchedEvent watchedEvent) {System.out.println(watchedEvent.getType()+"  ---  " + watchedEvent.getPath());try {zooKeeper.getChildren("/",true);} catch (KeeperException e) {e.printStackTrace();} catch (InterruptedException e) {e.printStackTrace();}}});}public static void main(String[] args) throws IOException, KeeperException, InterruptedException {init();
//        createNode();
//        exist();
//        getChildren();
//        deleteNode();
//        exist();getData();}//创建节点public static void createNode() throws KeeperException, InterruptedException {String s = zooKeeper.create("/sean", "zs".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);System.out.println(s);}//判断节点是否存在public static void exist() throws KeeperException, InterruptedException {Stat stat = zooKeeper.exists("/sean", false);System.out.println(stat==null?"not exist":"exist");}//获取子节点public static void getChildren() throws KeeperException, InterruptedException {List<String> children = zooKeeper.getChildren("/", true);children.stream().forEach(child -> System.out.println(child));Thread.sleep(Long.MAX_VALUE);}//删除public static void deleteNode() throws KeeperException, InterruptedException {zooKeeper.delete("/sean",-1);}//获取节点数据public static void getData() throws KeeperException, InterruptedException {byte[] data = zooKeeper.getData("/sean", true, null);System.out.println(new String(data));}//更改节点数据public static void setData() throws KeeperException, InterruptedException {zooKeeper.setData("/sean","sean".getBytes(),2);}}
  • ZKClient
     <!-- ZK Dependence --><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.6</version></dependency>    <dependency><groupId>com.101tec</groupId><artifactId>zkclient</artifactId><version>0.5</version></dependency>

OriginalClientAPIs

package com.yanxml.zookeeper.original.zkclient;import java.util.List;import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.serialize.SerializableSerializer;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;import com.yanxml.zookeeper.business.User;
import com.yanxml.zookeeper.config.ZooKeeperConfig;public class OriginalClientAPIs {// 获取ZooKeeper客户端public ZkClient getClient() {ZkClient zkClient = null;zkClient = new ZkClient(ZooKeeperConfig.ZOOURLS, 10000, 10000,new SerializableSerializer());return zkClient;}// 创建一个节点&创建节点的子节点public String createZkNode(ZkClient zkClient) {String path = "";if (null != zkClient) {if (!zkClient.exists("/user")) {User user = new User("Sean", 24);path = zkClient.create("/user", user, CreateMode.PERSISTENT);// log.warn}// 创建子节点if (!zkClient.exists("/user/petter")) {User user = new User("Petter", 24);path = zkClient.create("/user/petter", user,CreateMode.PERSISTENT);}// 创建子节点if (!zkClient.exists("/user/bruce")) {User user = new User("Bruce", 24);path = zkClient.create("/user/bruce", user,CreateMode.PERSISTENT);}// 创建子子节点if (!zkClient.exists("/user/bruce/abel")) {User user = new User("Abel", 24);path = zkClient.create("/user/bruce/abel", user,CreateMode.PERSISTENT);}}return path;}// 获取一个节点public Object getZkNode(ZkClient zkClient) {User user = null;if (null != zkClient) {Stat stat = new Stat();user = zkClient.readData("/user", stat);System.out.println("user:" + user.toString() + " stat:" + stat.toString());return user;}return user;}// 获取子节点(只向下获取一层 儿子的儿子节点不会获取)public List<String> getChildZkNode(ZkClient zkClient) {List<String> resultObj = null;if (null != zkClient) {resultObj = zkClient.getChildren("/user");System.out.println("Children String List: " + resultObj);}return resultObj;}// 查询节点是否存在public boolean existZkNode(ZkClient zkClient) {boolean flag = false;if (null != zkClient) {flag = zkClient.exists("/user");System.out.println("Node Exists: " + " '/user' " + flag);}return flag;}// 删除&循环删除public boolean deleteZkNode(ZkClient zkClient) {boolean flag = false;if (null != zkClient) {// 单节点删除(当存在子节点时候 会出现删除失败的情况)// flag = zkClient.delete("/user");// System.out.println("Delete OK " + " '/user' " + flag);// 循环删除flag = zkClient.deleteRecursive("/user");System.out.println("Recursive delete OK " + " '/user' " + flag);}return flag;}// 修改节点内容public boolean updateZkNode(ZkClient zkClient){boolean flag = false;if( null != zkClient){if(zkClient.exists("/user")){User user = new User("ChiGua", 24);zkClient.writeData("/user", user);}}return flag;}public static void main(String[] args) {OriginalClientAPIs apisDemo = new OriginalClientAPIs();// 获取client端ZkClient zkClient = apisDemo.getClient();// 创建节点apisDemo.createZkNode(zkClient);// 获取节点apisDemo.getZkNode(zkClient);// 获取从节点 地址apisDemo.getChildZkNode(zkClient);// apisDemo.existZkNode(zkClient);// apisDemo.deleteZkNode(zkClient);apisDemo.updateZkNode(zkClient);}}// Bug1:创建 原节点已经存在 创建失败// Bug2:节点包含子节点 删除失败
// Exception in thread "main" org.I0Itec.zkclient.exception.ZkException:
// org.apache.zookeeper.KeeperException$NotEmptyException: KeeperErrorCode =
// Directory not empty for /user
// at org.I0Itec.zkclient.exception.ZkException.create(ZkException.java:68)
// at org.I0Itec.zkclient.ZkClient.retryUntilConnected(ZkClient.java:893)
// at org.I0Itec.zkclient.ZkClient.delete(ZkClient.java:936)
// at
// com.yanxml.zookeeper.original.zkclient.OriginalClientAPIs.deleteZkNode(OriginalClientAPIs.java:84)
// at
// com.yanxml.zookeeper.original.zkclient.OriginalClientAPIs.main(OriginalClientAPIs.java:112)
// Caused by: org.apache.zookeeper.KeeperException$NotEmptyException:
// KeeperErrorCode = Directory not empty for /user
// at org.apache.zookeeper.KeeperException.create(KeeperException.java:125)
// at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
// at org.apache.zookeeper.ZooKeeper.delete(ZooKeeper.java:873)
// at org.I0Itec.zkclient.ZkConnection.delete(ZkConnection.java:102)
// at org.I0Itec.zkclient.ZkClient$9.call(ZkClient.java:940)
// at org.I0Itec.zkclient.ZkClient.retryUntilConnected(ZkClient.java:883)
// ... 3 more

SubscribeChildChanges.java

package com.yanxml.zookeeper.original.zkclient;import java.util.List;
import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;public class SubscribeChildChanges {private static class ZkChildListener implements IZkChildListener{public void handleChildChange(String parentPath, List<String> currentChilds)throws Exception {System.out.println(parentPath);System.out.println(currentChilds.toString());}}public static void main(String[] args) throws InterruptedException {OriginalClientAPIs apisDemo = new OriginalClientAPIs();// 获取client端ZkClient zkClient = apisDemo.getClient();// 注意 这个方法只能往下监听一层 子子节点的改变不能获取到zkClient.subscribeChildChanges("/user", new ZkChildListener());Thread.sleep(Integer.MAX_VALUE);}}

SubscribeDataChanges.java

package com.yanxml.zookeeper.original.zkclient;import org.I0Itec.zkclient.IZkDataListener;
import org.I0Itec.zkclient.ZkClient;public class SubscribeDataChanges {private static class ZkDataListener implements IZkDataListener{public void handleDataChange(String dataPath, Object data)throws Exception {System.out.println(dataPath+":"+data.toString());}public void handleDataDeleted(String dataPath) throws Exception {System.out.println("Deleted:"+dataPath);}}public static void main(String[] args) throws InterruptedException {OriginalClientAPIs apisDemo = new OriginalClientAPIs();// 获取client端ZkClient zkClient = apisDemo.getClient();// 注意 这个方法只能往下监听一层 子子节点的改变不能获取到zkClient.subscribeDataChanges("/user", new ZkDataListener());Thread.sleep(Integer.MAX_VALUE);// 监听相关的方法
//      zkClient.unsubscribeAll();
//      zkClient.unsubscribeChildChanges(arg0, arg1);
//      zkClient.unsubscribeDataChanges(arg0, arg1);
//      zkClient.unsubscribeStateChanges(stateListener);}}
  • Curator
   <!-- cursor  --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-recipes</artifactId><version>2.8.0</version></dependency><!-- fast json --><!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.28</version></dependency>

CuratorAPIs

package com.yanxml.zookeeper.original.curator;import java.security.NoSuchAlgorithmException;
import java.security.acl.Acl;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.apache.curator.retry.RetryUntilElapsed;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs.Perms;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;import com.yanxml.zookeeper.config.ZooKeeperConfig;// curator 馆长public class CuratorAPIs {// Get The ZkClientpublic static CuratorFramework getClient() {CuratorFramework zkClient = null;// RetryPolicy 重试策略 Elapsed 运行// RetryUntilElapsed(maxElapsedTimeMs, sleepMsBetweenRetries)RetryPolicy retryPolicy = new RetryUntilElapsed(5000, 1000);// create method 1:// zkClient = CuratorFrameworkFactory.newClient(ZooKeeperConfig.ZOOURLS,// retryPolicy);// create method 2:zkClient = CuratorFrameworkFactory.builder().connectString(ZooKeeperConfig.ZOOURLS).connectionTimeoutMs(5000).sessionTimeoutMs(5000).retryPolicy(retryPolicy).build();zkClient.start();return zkClient;}// create the zk nodepublic boolean createZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {// 如何将一个对象转换为二进制流// EPHEMERAL短暂的String path = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/user/sean", "123".getBytes());System.out.println("Create Path: " + path);flag = true;}return flag;}// delete the zk nodepublic boolean deleteZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {curatorFramework.delete().deletingChildrenIfNeeded().withVersion(-1).forPath("/user/sean");flag = true;}return flag;}// get the zk nodepublic boolean getZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {Stat stat = new Stat();byte result[] = curatorFramework.getData().storingStatIn(stat).forPath("/user/sean");System.out.println(new String(result));flag = true;}return flag;}// get the child zk nodepublic boolean getChildZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {List<String> resultList = curatorFramework.getChildren().forPath("/user");System.out.println(resultList.toString());flag = true;}return flag;}// change the child zk nodepublic boolean changeZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {Stat stat = new Stat();curatorFramework.getData().storingStatIn(stat).forPath("/user/sean");curatorFramework.setData().withVersion(stat.getVersion()).forPath("/user/sean", "456".getBytes());flag = true;}return flag;}// check the child zk nodepublic boolean checkZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;ExecutorService es = Executors.newFixedThreadPool(5);if (null != curatorFramework) {// 获取节点的状态值Stat stat = curatorFramework.checkExists().forPath("/user/sean");System.out.println(stat.toString());curatorFramework.checkExists().inBackground(new BackgroundCallback() {public void processResult(CuratorFramework arg0,CuratorEvent arg1) throws Exception {Stat stat = arg1.getStat();System.out.println(stat);// arg1.getContext() 即为"123" 存储在ZkNode内的String 字符串System.out.println(arg1.getContext());}}, "123", es).forPath("/user/sean");flag = true;}return flag;}// Subscribe Node & child Nodepublic static boolean subscribeZkNode(CuratorFramework curatorFramework)throws Exception {boolean flag = false;if (null != curatorFramework) {flag = true;// NodeCache The cache value&stat of zkfinal NodeCache nodeCache = new NodeCache(curatorFramework,"/user/sean");nodeCache.start();nodeCache.getListenable().addListener(new NodeCacheListener() {public void nodeChanged() throws Exception {byte currentData[] = nodeCache.getCurrentData().getData();System.out.println("CurrentData:" + new String(currentData));}});}return flag;}// Subscribe Node & child Nodepublic static boolean subscribeChildZkNode(CuratorFramework curatorFramework) throws Exception {boolean flag = false;if (null != curatorFramework) {flag = true;// NodeCache The cache value&stat of zkfinal PathChildrenCache childNodeCache = new PathChildrenCache(curatorFramework, "/user/sean", true);childNodeCache.start();childNodeCache.getListenable().addListener(new PathChildrenCacheListener() {public void childEvent(CuratorFramework zkClient,PathChildrenCacheEvent event) throws Exception {// TODO Auto-generated method stubswitch (event.getType()) {case CHILD_ADDED : {System.out.println("Add Child Node");break;}case CHILD_UPDATED : {System.out.println("Update Child Node");break;}case CHILD_REMOVED : {System.out.println("Remove Child Node");break;}default : {System.out.println("Default");break;}}}});}return flag;}public static boolean authorZkNode(CuratorFramework curatorFramework) throws Exception{boolean flag = false;if (null != curatorFramework) {ACL acl = new ACL(Perms.READ,new Id("ip","192.168.100.204"));// digest 所有权限都有
//          Acl aclDigest =Acl ACL aclDigest = new ACL(Perms.READ|Perms.WRITE,new Id("digest",DigestAuthenticationProvider.generateDigest("jike:123456")));ArrayList<ACL> acls = new ArrayList<ACL>();acls.add(acl);acls.add(aclDigest);// add the acls nodeString path = curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).withACL(acls).forPath("/jike/3","123".getBytes());System.out.println(path);flag = true;}return flag;}public static void main(String[] args) throws Exception {CuratorAPIs curatorApIs = new CuratorAPIs();CuratorFramework curatorFramework = curatorApIs.getClient();// Create The Zk NodecuratorApIs.createZkNode(curatorFramework);// Delete The Zk Node// curatorApIs.deleteZkNode(curatorFramework);// Get The Zk NodecuratorApIs.getZkNode(curatorFramework);// Get The Child Zk NodecuratorApIs.getChildZkNode(curatorFramework);// Change The Zk Node// curatorApIs.changeZkNode(curatorFramework);// Check The Zk Node
//      curatorApIs.checkZkNode(curatorFramework);curatorApIs.authorZkNode(curatorFramework);// 2^32-1Thread.sleep(Integer.MAX_VALUE);}}

Reference

[1]. zookeeper 操作命令
[2]. zookeeper系列(一)zookeeper基础

ZooKeeper 基本操作 与 Java APIs相关推荐

  1. 最新Kafka教程(包含kafka部署与基本操作、java连接kafka、spring连接kafka以及使用springboot)

    最新Kafka教程(包含kafka部署与基本操作.java连接kafka.spring连接kafka以及使用springboot) 欢迎转载,转载请注明网址:https://blog.csdn.net ...

  2. Ⅴ:zookeeper的相关Java Api

    2021最新zookeeper系列 ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤ ...

  3. Google 不想与甲骨文争了,要放弃 Java APIs

    文章来源:http://www.oschina.net/news/69510/android-n-never-use-java-apis?p=3 与Android崛起相伴的其实还有战争,而其中最重要且 ...

  4. 4. ZooKeeper 基本操作

    ZooKeeper的数据模型及其API支持以下九个基本操作: 操作 描述 create 在ZooKeeper命名空间的指定路径中创建一个znode delete 从ZooKeeper命名空间的指定路径 ...

  5. java APIs for xml --------dom(2)

    # Java API for XML Processing (JAXP) # Study Note of JAVA Tutorial Document Object Model APIs 上一篇 实现 ...

  6. 头歌实验 HDFS的基本操作和Java API 操作

    第1关:HDFS的基本操作 命令行 //一行一步 start-dfs.sh hadoop fs -mkdir -p /usr/output mkdir -p /develop/input cd /de ...

  7. solrcloud java_SolrCloud之zookeeper中使用java代码创建集合

    javaAPI调用solrcloud上传配置和删除/创建集合.网上大多都是通过http路径调用创建,以下是通过Zookeeper+solr进行操作: ? public class SolrConfig ...

  8. zookeeper基本操作(常用命令)

    连接zookeeper,在本机连接的话,默认连接的都是自己: help查看zookeeper操作命令: ①ls /   显示根目录,默认根目录是[zookeeper] ②create创建一个/ooxx ...

  9. 链表的基本操作 java_详细实现单链表的基本操作【Java版】

    节点类 static Node head=new Node(); static class Node{ int data; Node next; public Node() {//无参构造方法,默认d ...

最新文章

  1. 如何在Leangoo中,为企业创建项目
  2. CentOS下挂载硬盘(fdisk,mkfs.ext4,mount)
  3. 什么是事务、事务的四个特性ACID、不考虑隔离性会导致的三个问题、四种隔离级别
  4. vc++ 关于 指针操作
  5. 解决Java当中 用point 画图时背景颜色变成黑色问题
  6. 【图论】【最短路】【Dijkstra】最小花费(ssl 2206/luogu 1576)
  7. Navicat Premium 11 12 闪退
  8. ajax 微信code获取_获取链接的参数,判断是否是微信打开,ajax获取数据
  9. it行业如何应对领导_什么是IT文化? 今天的领导者需要知道
  10. 【u107】数字游戏(bds)
  11. C#各种文件操作的代码与注释
  12. Hard lockup occurs due to an infinite loop encountered in distribute_cfs_runtime()
  13. excel表用office2007一保存就闪退
  14. Centos安装显卡驱动
  15. 计算机双机对连局域网,图解双机/多机无线互联技巧_局域网教程
  16. excel公式编辑器_V14.0发布:组件化编辑器+数据透视表
  17. MPLS LDP简介-ielab
  18. oracle共享函数,oracle常用函数及示例分享
  19. 帝国cms自动生成3图
  20. 用最长情的告白陪伴技术人的成长

热门文章

  1. 这三款手机视频拼接软件,可以帮你把视频拼出高级感
  2. patchelf: https://github.com/NixOS/patchelf
  3. 蓝桥软件竞赛 预选赛
  4. 使用python获取股票“业绩快报总资产、净资产”等“上市公司业绩快报”数据
  5. 详讯:微软宣布放弃收购雅虎
  6. 莱布尼茨数学思想的统一性
  7. H5企业网站模板-蓝绿过渡色功能菜单齐全
  8. ubuntu 以及secure crt的上下左右按键无法使用,输入的是ABCD
  9. 苹果三星小心了!传微软正开发智能手表
  10. 达梦数据库DM8数据文件损坏无备份恢复