使用客户端命令连接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. Halcon 常用算子使用场合

    Chapter 1 :Classification 1.1 Gaussian-Mixture-Models 1.add_sample_class_gmm 功能:把一个训练样本添加到一个高斯混合模型的训 ...

  2. [OC]时间格式中的字符的意义

    Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996;96 M M ...

  3. MySql基础笔记(三)其他重要的事情

    其他重要的事情 一)索引管理优化 1.把多条alter语句整合为一条 2.去除重复的索引 1)当一个索引的最左边部分包含到其他索引中时,被认定为重复索引 create table user( id i ...

  4. Android:ViewGroup和View的Touch事件

    Android中ViewGroup和View中的Touch事件传递机制分析 关键字:GroupView:View:Touch事件 基础知识: onInterceptTouchEvent():在View ...

  5. C#编程 - 交通灯模拟

    程序写的有点繁杂,但大体功能出来的! 效果图: using System; using System.Collections.Generic; using System.Linq; using Sys ...

  6. python正则表达式(四)

    re模块的高级用法 search 需求:匹配出文章阅读的次数 #coding=utf-8 import re ret = re.search(r"\d+", "阅读次数为 ...

  7. 天天爱跑步 [NOIP2016]

    Description 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.<天天爱跑步>是一个养成类游戏,需要玩家每天按时上线,完成打卡任务.这个游戏的地图可 ...

  8. 使用iscroll,无法正常滑动的原因

    iscroll的dom元素的结构是固定的,swiper是容器,scroll是需要滚动的容器,list是滚动的内容 <div class="swiper"> <di ...

  9. C#自动识别文件编码

    以下代码源自:http://www.cnblogs.com/stulzq/p/6116627.html /// <summary> /// 用于取得一个文本文件的编码方式(Encoding ...

  10. JAVA中使用LOG4J记录日志(转)

    在项目开发中,记录错误日志是一个很有必要功能.一是方便调试:二是便于发现系统运行过程中的错误:三是存储业务数据,便于后期分析: 在java中,记录日志,有很多种方式. 比如,自己实现. 自己写类,将日 ...