Zookeeper 入门手册

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ZOOKEEPER开发入门北京先进数通信息技术有限公司-1-ZOOKEEPER入门手册北京先进数通信息技术有限公司EAISZOOKEEPER开发入门北京先进数通信息技术有限公司-2-编写说明标题:ZOOKEEPER入门练习类别:文档存放位置:编辑软件:MicrosoftWordXP中文版版本历史:版本作者日期备注V1.0梅光弦2012-12-4编写目的:通过简单的例子程序循序渐进地学习ZOOKEEPER的开发应用。本文档由产品组维护,供各项目组使用。ZOOKEEPER开发入门北京先进数通信息技术有限公司-3-目录编写说明..................................................................................................................................................2目录..................................................................................................................................................31.1.本文目的......................................................................................................................................41.2.阅读建议......................................................................................................................................42.起步.....................................................................................................................................................42.1.DEMO00搭建ZOOKEEPER集群服务器...................................................................................42.1.1.功能概述...............................................................................................................................42.1.2.开发过程...............................................................................................................................42.1.3.执行效果...............................................................................................................................42.2.DEMO01ZOOKEEPER基本操作...............................................................................................52.2.1.功能概述...............................................................................................................................52.2.2.开发过程...............................................................................................................................52.2.3.执行效果.............................................................................................................................162.3.DEMO002ZOOKEEPER临时节点................................................................................................162.3.1.功能描述.............................................................................................................................162.3.2.开发过程.............................................................................................................................162.3.3.执行效果.............................................................................................................................182.4.DEMO003监控ZOOKEEPER节点...............................................................................................182.4.1.功能描述.............................................................................................................................182.4.2.开发过程.............................................................................................................................182.4.3.执行效果.............................................................................................................................23ZOOKEEPER开发入门北京先进数通信息技术有限公司-4-前言1.1.本文目的本文是Zookeeper开发的入门手册,将会在一个最简单的例子入手,为读者逐渐深入地介绍Zookeeper上的应用开发。1.2.阅读建议本文假定读者是一个Unix系统下的开发人员,有一定的应用编程经验,熟悉J2EE的应用开发。请参考提供的对应DEMO包,对应下面的章节,一步一步对照开发。2.起步本章的目的在于,通过循序渐进的练习,让初学者了解ZOOKEEPER的基本概念,掌握开发方法,具备实际应用的能力。2.1.DEMO00搭建ZOOKEEPER集群服务器2.1.1.功能概述在一台机器上搭建一个由3个Server组成的ZOOKEEPER伪集群服务器,可以进行集群服务的启动、停止。2.1.2.开发过程1、参考《ZOOKEEPER介绍v1.0.doc》,搭建一个伪集群服务器。2.1.3.执行效果在ZOOKEEPER集群的每个服务器的../zookeeper/bin目录下,运行shzkServer.shstart,当出现以下界面说明ZOOKEEPER启动成功。ZOOKEEPER开发入门北京先进数通信息技术有限公司-5-zookeeper/bin目录下,运行zkCli.sh–server172.16.4.224:2181(IP、端口与实际配置一致)。当出现以下界面说明已经成功连接上ZOOKEEPER客户端。2.2.DEMO01ZOOKEEPER基本操作2.2.1.功能概述熟悉Zookeeper的API,练习Zookeeper的增、删、改、查操作。2.2.2.开发过程1、Eclipse新建一个Java工程,导入Zookeeper依赖的jar包zookeeper-3.4.3.jarslf4j-log4j12-1.6.1.jarslf4j-api-1.6.1.jarlog4j-1.2.15.jar2、编写增、删、改、查的代码。packagezookeeper;importjava.io.IOException;importjava.util.List;importorg.apache.zookeeper.KeeperException;/***@类名ZkServer.javaZOOKEEPER开发入门北京先进数通信息技术有限公司-6-*@描述:*zookeeper的操作封装接口,实现了常用的操作*创建、销毁、写入、修改、查询等。*@作者梅光弦*@创建时间2012-12-4下午02:49:58*@版本v1.0*/publicinterfaceZkServer{/****@paramaddress*@paramserverName*@throwsIOException*/publicvoidinit(Stringaddress)throwsIOException;/****@throwsInterruptedException*/publicvoiddestroy()throwsInterruptedException;/****@parampath*@return*@throwsKeeperException*/publicListStringgetChilds(Stringpath)throwsKeeperException,InterruptedException;/****@parampath*@return*@throwsKeeperException*@throwsInterruptedException*/publicStringgetData(Stringpath)throwsKeeperException,InterruptedException;/****@parampathZOOKEEPER开发入门北京先进数通信息技术有限公司-7-*@paramdata*@throwsKeeperException*/publicvoidchangeData(Stringpath,Stringdata)throwsKeeperException,InterruptedException;/****@parampath*@paramdata*@throwsKeeperException*@throwsInterruptedException*/publicvoidappendTempNode(Stringpath,Stringdata)throwsKeeperException,InterruptedException;/

1 / 23
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功