zookeeper_03:Java 客户端(原生API)
- 环境配置
- 下载并ZooKeeper的发行版
- 新建Java project,并导入jar包
- 创建会话
public class CreateSession implements Watcher {
private static ZooKeeper zookeeper;
public static void main(String[] args) throws IOException, InterruptedException {
zookeeper = new ZooKeeper("192.168.1.105:2181",5000,new CreateSession());
System.out.println(zookeeper.getState());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(){
System.out.println("do something");
}
public void process(WatchedEvent event) {
System.out.println("收到事件:"+event);
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething();
}
}
}
}
- 同步创建节点
public class CreateNodeSync implements Watcher {
private static ZooKeeper zookeeper;
public static void main(String[] args) throws IOException, InterruptedException {
zookeeper = new ZooKeeper("192.168.124.128:2181,192.168.124.128:2182,192.168.124.128:2183",5000,new CreateNodeSync());
System.out.println(zookeeper.getState());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(){
try {
String path = zookeeper.create("/test", "test".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
System.out.println("return path:"+path);
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("do something");
}
public void process(WatchedEvent event) {
System.out.println("收到事件:"+event);
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething();
}
}
}
}
- 异步创建节点
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooDefs.Perms;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.server.auth.DigestAuthenticationProvider;
public class CreateNodeSyncAuth implements Watcher {
private static ZooKeeper zookeeper;
private static boolean somethingDone = false;
public static void main(String[] args) throws IOException, InterruptedException {
zookeeper = new ZooKeeper("192.168.124.128:2181,192.168.124.128:2182,192.168.124.128:2183",5000,new CreateNodeSyncAuth());
System.out.println(zookeeper.getState());
Thread.sleep(Integer.MAX_VALUE);
}
/*
* 权限模式(scheme): ip, digest
* 授权对象(ID)
* ip权限模式: 具体的ip地址
* digest权限模式: username:Base64(SHA-1(username:password))
* 权限(permission): create(C), DELETE(D),READ(R), WRITE(W), ADMIN(A)
* 注:单个权限,完全权限,复合权限
*
* 权限组合: scheme + ID + permission
*
*
*
* */
private void doSomething(){
try {
ACL aclIp = new ACL(Perms.READ,new Id("ip","192.168.124.128"));
ACL aclDigest = new ACL(Perms.READ|Perms.WRITE,new Id("digest",DigestAuthenticationProvider.generateDigest("zhangsan:123456")));
ArrayList<ACL> acls = new ArrayList<ACL>();
acls.add(aclDigest);
acls.add(aclIp);
//zookeeper.addAuthInfo("digest", "zhangsan:123456".getBytes());
String path = zookeeper.create("/test", "test".getBytes(), acls, CreateMode.PERSISTENT);
System.out.println("return path:"+path);
somethingDone = true;
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void process(WatchedEvent event) {
System.out.println("收到事件:"+event);
if (event.getState()==KeeperState.SyncConnected){
if (!somethingDone && event.getType()==EventType.None && null==event.getPath()){
doSomething();
}
}
}
}
StringCallback{
public void (int rc,String path,Object ctx,String name)
}
rc是result code 服务端响应结果码。客户端可以从这个结果码中识别出API的调用结果,常见的结果码有:
0(OK),接口调用成功
-4(ConnectionLoss),客户端和服务器连接断开
-110(NodeExists) 节点已存在
-112(SessionExpired)会话已过期
path: 接口调用传入的数据节点的节点路径
ctx: 接口调用传入的ctx参数
name: 实际在服务器端创建的节点名
- 同步删除节点
import java.io.IOException;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
public class DeleteNodeSync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new DeleteNodeSync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zooKeeper){
try {
zooKeeper.delete("/node_7", -1);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
}
}
@Override
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}
}
}
}
- 异步删除节点
import java.io.IOException;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
public class DeleteNodeASync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new DeleteNodeASync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(WatchedEvent event){
zooKeeper.delete("/node_6", -1, new IVoidCallback(),null);
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(event);
}
}
}
static class IVoidCallback implements AsyncCallback.VoidCallback{
public void processResult(int rc, String path, Object ctx) {
StringBuilder sb = new StringBuilder();
sb.append("rc="+rc).append("\n");
sb.append("path"+path).append("\n");
sb.append("ctx="+ctx).append("\n");
System.out.println(sb.toString());
}
}
}
- 同步读取节点
import java.io.IOException;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class GetDataSync implements Watcher{
private static ZooKeeper zooKeeper;
private static Stat stat = new Stat();
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new GetDataSync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zookeeper){
zookeeper.addAuthInfo("digest", "jike:123456".getBytes());
try {
System.out.println(new String(zooKeeper.getData("/node_4", true, stat)));
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
if (event.getType()==EventType.NodeDataChanged){
try {
System.out.println(new String(zooKeeper.getData(event.getPath(), true, stat)));
System.out.println("stat:"+stat);
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
- 异步读取节点
import java.io.IOException;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class GetDataASync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new GetDataASync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zookeeper){
zooKeeper.getData("/node_1", true, new IDataCallback(), null);
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
if (event.getType()==EventType.NodeDataChanged){
try {
zooKeeper.getData(event.getPath(), true, new IDataCallback(), null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
static class IDataCallback implements AsyncCallback.DataCallback{
public void processResult(int rc, String path, Object ctx, byte[] data,Stat stat) {
try {
System.out.println(new String(zooKeeper.getData(path, true, stat)));
System.out.println("stat:"+stat);
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
- 同步节点检测
import java.io.IOException;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class NodeExistsSync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new NodeExistsSync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zooKeeper){
try{
Stat stat = zooKeeper.exists("/node_1", true);
System.out.println(stat);
}catch(Exception e){
}
}
@Override
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
try {
if (event.getType()==EventType.NodeCreated){
System.out.println(event.getPath()+" created");
System.out.println(zooKeeper.exists(event.getPath(), true));
}
else if (event.getType()==EventType.NodeDataChanged){
System.out.println(event.getPath()+" updated");
System.out.println(zooKeeper.exists(event.getPath(), true));
}
else if (event.getType()==EventType.NodeDeleted){
System.out.println(event.getPath()+" deleted");
System.out.println(zooKeeper.exists(event.getPath(), true));
}
} catch (Exception e) {
}
}
}
}
}
- 异步检测节点
import java.io.IOException;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class NodeExistsASync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new NodeExistsASync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zookeeper){
zooKeeper.exists("/node_1", true, new IStateCallback(), null);
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
try {
if (event.getType()==EventType.NodeCreated){
System.out.println(event.getPath()+" created");
zooKeeper.exists(event.getPath(), true, new IStateCallback(), null);
}
else if (event.getType()==EventType.NodeDataChanged){
System.out.println(event.getPath()+" updated");
zooKeeper.exists(event.getPath(), true, new IStateCallback(), null);
}
else if (event.getType()==EventType.NodeDeleted){
System.out.println(event.getPath()+" deleted");
zooKeeper.exists(event.getPath(), true, new IStateCallback(), null);
}
} catch (Exception e) {
}
}
}
}
static class IStateCallback implements AsyncCallback.StatCallback{
public void processResult(int rc, String path, Object ctx, Stat stat) {
System.out.println("rc:"+rc);
}
}
}
- 同步获取子节点
import java.io.IOException;
import java.util.List;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
public class GetChildrenSync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new GetChildrenSync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zooKeeper){
try {
List<String> children = zooKeeper.getChildren("/", true);
System.out.println(children);
} catch (Exception e) {
}
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
if (event.getType()==EventType.NodeChildrenChanged){
try {
System.out.println(zooKeeper.getChildren(event.getPath(), true));
} catch (KeeperException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
- 异步获取子节点
import java.io.IOException;
import java.util.List;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class GetChildrenASync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new GetChildrenASync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zookeeper){
try {
zooKeeper.getChildren("/", true, new IChildren2Callback(), null);
} catch (Exception e) {
}
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}else{
if (event.getType()==EventType.NodeChildrenChanged){
zooKeeper.getChildren(event.getPath(), true, new IChildren2Callback(), null);
}
}
}
}
static class IChildren2Callback implements AsyncCallback.Children2Callback{
public void processResult(int rc, String path, Object ctx,List<String> children, Stat stat) {
StringBuilder sb = new StringBuilder();
sb.append("rc="+rc).append("\n");
sb.append("path="+path).append("\n");
sb.append("ctx="+ctx).append("\n");
sb.append("children="+children).append("\n");
sb.append("stat="+stat).append("\n");
System.out.println(sb.toString());
}
}
}
- 同步更新
import java.io.IOException;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class UpdateNodeSync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new UpdateNodeSync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(ZooKeeper zooKeeper){
try {
Stat stat = zooKeeper.setData("/node_6", "123".getBytes(), -1);
System.out.println("stat:"+stat);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
}
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(zooKeeper);
}
}
}
}
- 异步更新
import java.io.IOException;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class UpdateNodeASync implements Watcher{
private static ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
zooKeeper = new ZooKeeper("192.168.1.105:2181",5000,new UpdateNodeASync());
System.out.println(zooKeeper.getState().toString());
Thread.sleep(Integer.MAX_VALUE);
}
private void doSomething(WatchedEvent event){
zooKeeper.setData("/node_6", "234".getBytes(), -1, new IStatCallback(),null);
}
public void process(WatchedEvent event) {
if (event.getState()==KeeperState.SyncConnected){
if (event.getType()==EventType.None && null==event.getPath()){
doSomething(event);
}
}
}
static class IStatCallback implements AsyncCallback.StatCallback{
public void processResult(int rc, String path, Object ctx, Stat stat) {
StringBuilder sb = new StringBuilder();
sb.append("rc="+rc).append("\n");
sb.append("path"+path).append("\n");
sb.append("ctx="+ctx).append("\n");
sb.append("Stat="+stat).append("\n");
System.out.println(sb.toString());
}
}
}
zookeeper_03:Java 客户端(原生API)的更多相关文章
- ZooKeeper客户端原生API的使用以及ZkClient第三方API的使用
这两部分内容的介绍主要讲的是节点及节点内容和子节点的操作,并且讲解的节点的事件监听以及ACL授权 ZooKeeper客户端原生API的使用 百度网盘地址: http://pan.baidu.com/s ...
- elasticsearch 口水篇(4)java客户端 - 原生esClient
上一篇(elasticsearch 口水篇(3)java客户端 - Jest)Jest是第三方客户端,基于REST Api进行调用(httpClient),本篇简单介绍下elasticsearch原生 ...
- Java 8原生API也可以开发响应式代码?
前段时间工作上比较忙,这篇文章一直没来得及写,本文是阅读<Java8实战>的时候,了解到Java 8里已经提供了一个异步非阻塞的接口(CompletableFuture),可以实现简单的响 ...
- Kubernetes官方java客户端之七:patch操作
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- zookeeper原生API做java客户端
简介 本文是使用apache提供的原生api做zookeeper客户端 jar包 zookeeper-3.4.5.jar Demo package bjsxt.zookeeper.base; im ...
- JAVA客户端API调用memcached两种方式
1. memcached client for java客户端API:memcached client for java 引入jar包:java-memcached-2.6.2.jar package ...
- hadoop系列二:HDFS文件系统的命令及JAVA客户端API
转载请在页首明显处注明作者与出处 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的一些内容,如hadoop,spark,storm,机器学习等. 当前使用的hadoop版本为2.6 ...
- Java原生API操作XML
使用Java操作XML的开源框架比较多,如著名的Dom4J.JDOM等,但个人认为不管你用那个框架都要对JDK原生的API有所了解才能更得心应手的应用.本篇就来简单了解下原生的XML API. JAV ...
- Zookeeper Java客户端API的使用
1. 原生api 具体查看下面github代码 2. ZkClient ZkClient是Github上一个开源的ZooKeeper客户端.ZkClient在ZooKeeper原生 A ...
- Zookeeper系列三:Zookeeper客户端的使用(Zookeeper原生API如何进行调用、ZKClient、Curator)和Zookeeper会话
一.Zookeeper原生API如何进行调用 准备工作: 首先在新建一个maven项目ZK-Demo,然后在pom.xml里面引入zk的依赖 <dependency> <groupI ...
随机推荐
- Android开发_关于如何屏蔽Home键
今天在遇到一个要屏蔽Home键的问题,研究一上午终于解决,方法记录于下: 在Android2.3版本以下重写以下方法就能屏蔽Home键: public void onAttachedToWindow( ...
- 三维扫描 FZU 1063
Description 工业和医学上经常要用到一种诊断技术——核磁共振成像(Magnetic Resonance Imagers).利用该技术可以对三维物体(例如大脑)进行扫描.扫描的结果用一个三维的 ...
- AngularJS的指令(Directive) compile和link的区别及使用示例
如果我想实现这样一个功能,当一个input失去光标焦点时(blur),执行一些语句,比如当输入用户名后,向后台发ajax请求查询用户名是否已经存在,好有及时的页面相应. 输入 camnpr 失去焦点后 ...
- JS三元运算符
语法是 条件 ? 结果1 : 结果2; 问号(?)的前面是条件:后面跟着用冒号(:)分隔的结果1和结果2;满足条件时结果1否则结果2. 例子: var a=1; a>2?a:a=3; alert ...
- 基本语法 - PHP手册笔记
PHP标记 如果文件内容是纯PHP代码,最好在文件末尾删除PHP结束标记.这可以避免在PHP结束标记之后万一意外加入了空格或者换行符,会导致PHP开始输出这些空白,而脚本中此时并无输出的意图.当然PH ...
- FFMPEG图片转视频
1.分离视频音频流 ffmpeg -i input_file -vcodec copy -an output_file_video //分离视频流 ffmpeg -i input_file -acod ...
- HDU1043 Eight(BFS)
Eight(South Central USA 1998) Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- codeforces 518A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- zookeeper数据弱一致性
zookeeper本身支持单机部署和集群部署,生产环境建议使用集群部署,因为集群部署不存在单点故障问题,并且zookeeper建议部署的节点个数为奇数个,只有超过一半的机器不可用整个zk集群才不可用. ...
- spark快速入门之最简配置 spark 1.5.2 hadoop 2.7 配置
配置的伪分布式,ubuntu14.04上 先配置hadoop,参见这个博客,讲的很好 http://www.powerxing.com/install-hadoop/, 但是我在配的过程中还是遇到了问 ...