使用客户端命令连接Zookeeper

连接Server 
使用命令./zkCli.sh -server 127.0.0.1:2181

使用JAVA连接使用ZK

POM添加引用

<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>

使用curator连接使用ZK

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat; public class CuratorDemo { final static String BasePath = "/curatorTest"; public static void main(String[] args) throws Exception {
CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString("*:2181,*:2182,*:2183").sessionTimeoutMs(4000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.namespace("curator").build(); curatorFramework.start(); Stat stat = curatorFramework.checkExists().forPath(BasePath + "/node1");
Object o;
if (stat == null) { o= curatorFramework.create().creatingParentContainersIfNeeded().
withMode(CreateMode.PERSISTENT).forPath(BasePath + "/node1", "0".getBytes());
} //存储Stat
curatorFramework.getData().storingStatIn(stat).forPath(BasePath + "/node1"); //更新时使用State
stat = curatorFramework.setData().withVersion(stat.getVersion()).forPath(BasePath + "/node1", "1".getBytes());
System.out.println("update => " + stat.getVersion()); curatorFramework.close();
}
}

  

【Zookeeper】连接ZooKeeper的方式的更多相关文章

  1. zookeeper - 通过java代码连接zookeeper(2)

    首先创建一个Maven项目 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...

  2. (转)hbase master挂掉-zookeeper连接超时原因

    link:http://www.51testing.com/?uid-445759-action-viewspace-itemid-812467 并行运行hbase删表,建表操作,多个表多个regio ...

  3. python中使用kazoo连接zookeeper(一)

    http://hi.baidu.com/eldersun/item/b9266e019da769f0f45ba6a4 python下连接zookeeper使用最多的是python 包装的zookeep ...

  4. Zookeeper基础教程(三):Zookeeper连接使用—zkCli

    上一篇介绍Zookeeper的安装,并介绍了使用ZooInspector连接Zookeeper,这里主要介绍以命令行的形式介绍Zookeeper 假如我们已经安装了Zookeeper集群,集群中的安装 ...

  5. dubbo连接zookeeper注册中心因为断网导致线程无限等待问题【转】

    最近维护的系统切换了网络环境,由联通换成了电信网络,因为某些过滤规则导致系统连不上zookeeper服务器(应用系统机器在深圳,网络为电信线路,zookeeper服务器在北京,网络为联通线路),因为我 ...

  6. python连接zookeeper的日志问题

    用python连接zookeeper时,在终端里,一直会有zookeeper的日志冒出来,这样会很烦. -- ::,:(: Exceeded deadline by 11ms 解决方法是在连接后设置一 ...

  7. Zookeeper命令行操作(常用命令;客户端连接;查看znode路径;创建节点;获取znode数据,查看节点内容,设置节点内容,删除节点;监听znode事件;telnet连接zookeeper)

    8.1.常用命令 启动ZK服务 bin/zkServer.sh start 查看ZK服务状态 bin/zkServer.sh status 停止ZK服务 bin/zkServer.sh stop 重启 ...

  8. ZooKeeper连接并创建节点以及实现分布式锁操作节点排序输出最小节点Demo

    class LockThread implements Runnable { private DistributedLock lock; public LockThread(int threadId, ...

  9. java连接zookeeper服务器出现“KeeperErrorCode = ConnectionLoss for ...”

    错误信息如下: Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossExce ...

随机推荐

  1. Alpha(10/10)

    鐵鍋燉腯鱻 项目:小鱼记账 团队成员 项目燃尽图 冲刺情况描述 站立式会议照片 各成员情况 团队成员 学号 姓名 git地址 博客地址 031602240 许郁杨 (组长) https://githu ...

  2. 2D Rotated Rectangle Collision

    Introduction While working on a project for school, I found it necessary to perform a collision chec ...

  3. [PA2014]Żarówki

    [PA2014]Żarówki 题目大意: 有\(n(n\le5\times10^5)\)个房间和\(n\)盏灯,你需要在每个房间里放入一盏灯.每盏灯都有一定功率\(p_i\),每间房间都需要功率不小 ...

  4. css selector 用法

    html.css('a::attr(href)').extract()

  5. Ubuntu 安装 Anaconda3 详细步骤

    主要介绍在 Ubuntu 14.04中安装 Anaconda3 的详细过程.(原文地址:http://blog.csdn.net/u012318074/article/details/77074665 ...

  6. .net core中的对象池

    asp.net core中通过扩展库的方式提供给了一个标准的对象池ObjectPool,定义在Microsoft.Extensions.ObjectPool.dll 程序集中.它本身是个纯虚的抽象类, ...

  7. 无法打开运行空间池,服务器管理器winrm插件可能已损坏或丢失

    在使用windows2012 的服务器或云主机时,服务器安装不了iis服务. 提示 “无法打开运行空间池,服务器管理器winrm插件可能已损坏或丢失”. 这个问题可能的原因是您的机器未设置虚拟内存,可 ...

  8. CSS 埋点统计

    原文地址: https://my.oschina.net/u/1778933/blog/1608904 CSS 埋点统计 当一个网站或者 App 的规模达到一定程度,需要分析用户在 App 或者网站的 ...

  9. C# Task ContinueWith的实现

    看了上一篇C# Task 是什么?返回值如何实现? Wait如何实现 我们提到FinishContinuations方法中会调用TaskContinuation实例,那么我们的ContinueWith ...

  10. 阿里云配置gitlab邮箱

    gitlab_rails['gitlab_email_from'] = 'username@163.com' user['git_user_email'] = "username@163.c ...