Apache ZooKeeper Getting Started Guide 翻译
- 開始:用zookeeper协调分布式程序
- 单例操作
- 管理zookeeper存储
- 连接zookeeper
- 执行zookeeper
- 以复制模式执行zookeeper
- 其他优化
文章主要是针对0基础想尝试使用zookeeper的开发人员,当中包括了一些简单的样例。仅用一台zookeeperserver,一些命令确认server正在执行,一个简单的程序样例。
文章最后,为了方便,也有一些内容考虑到一些相对复杂些的样例。列如,以复制模式部署,优化事务。
可是假设想运用到商业项目中。请參阅 ZooKeeper
Administrator's Guide.
这个时间好比是zookeeper的心跳时间,是最小会话单元的超时时间范围是这个时间的2倍。
假如进程执行失败,zookeeper服务就会挂掉。单例模式启动对于开发环境来说是最好的。假设想已复制模式启动请看Running
Replicated ZooKeeper.
- Java: Use
bin/zkCli.sh -server 127.0.0.1:2181
This lets you perform simple, file-like operations.
C: compile cli_mt (multi-threaded) or cli_st (single-threaded) by running make
cli_mt or make cli_st in
the src/c subdirectory in the ZooKeeper sources. See the README contained within src/c for full details.You can run the program from src/c using:
LD_LIBRARY_PATH=. cli_mt 127.0.0.1:2181
or
LD_LIBRARY_PATH=. cli_st 127.0.0.1:2181
This will give you a simple shell to execute file system like operations on ZooKeeper.
Once you have connected, you should see something like:
Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
Welcome to ZooKeeper!
JLine support is enabled
[zkshell: 0]
[zkshell: 0] help
ZooKeeper host:port cmd args
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
create path data acl
stat path [watch]
listquota path
history
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
deleteall path
setquota -n|-b val path
First, start by issuing the list command, as in ls, yielding:
[zkshell: 9] create /zk_test my_data
Created /zk_test
[zkshell: 11] ls /
[zookeeper, zk_test]
你能够确认下和这个节点关联的数据通过执行get命令。例如以下:
[zkshell: 12] get /zk_test
my_data
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 5
mtime = Fri Jun 05 13:57:06 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0
dataLength = 7
numChildren = 0
[zkshell: 14] set /zk_test junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0
[zkshell: 15] get /zk_test
junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0
命令,数据的确改变了)。
[zkshell: 16] delete /zk_test
[zkshell: 17] ls /
[zookeeper]
[zkshell: 18]
Programming to ZooKeeper
ZooKeeper has a Java bindings and C bindings. They are functionally equivalent. The C bindings exist in two variants: single threaded and multi-threaded. These differ only
in how the messaging loop is done. For more information, see the Programming Examples in the
ZooKeeper Programmer's Guide for sample code using of the different APIs.
这个文件和上面介绍单例模式使用的配置文件和类似。仅仅是有一点小小的不同,例如以下:
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
ticks,每一个tick是2000毫秒,也就是10秒。
当server启动的时候,通过寻找在数据文件夹的myid文件知道是哪台server。这个文件含有以ASCII编码的server编号。
尤其在zookeeperserver依次连接到leader时候。当一个新的leader诞生时,小弟们会通过这个port号利用tcp协议连接到leader。由于默认leader也用tcp协议。我们必需要求另外一个port用于选举leader。就是属性server的第二个port号。
2889:3889, 2890:3890 )。隔离各个dataDir文件夹和不同的port号也是必须的。
(在这个复制模式执行的样例里,每一个执行在单一的机器都有一个配置文件)
Apache ZooKeeper Getting Started Guide 翻译的更多相关文章
- 转载:ZooKeeper Programmer's Guide(中文翻译)
本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实践信息. 本指南的前四节对各种ZooKeeper概念进行较高层次的讨论.这些概念对于理解ZooKeep ...
- 【Apache ZooKeeper】理解ZooKeeper中的ZNodes
理解ZooKeeper中的ZNodes 翻译自:http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html ZooKeeper中的 ...
- Download and Install Apache Zookeeper on Ubuntu
http://www.techburps.com/misc/download-and-install-apache-zookeepr/36 In previous article of this Bi ...
- ZooKeeper Getting Started Guide
http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html What is ZooKeeper? ZooKeeper is a centra ...
- ZooKeeper Administrator's Guide A Guide to Deployment and Administration(吃别人嚼过的馍没意思,直接看官网资料)
Deployment System Requirements Supported Platforms Required Software Clustered (Multi-Server) Setup ...
- Apache ZooKeeper 服务启动源码解释
转载:https://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper-code/ 本文首先讲解了 Apache ZooKeeper 服 ...
- windows下安装apache zookeeper
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...
- 在 Linux 多节点安装配置 Apache Zookeeper 分布式集群
规划: 三台物理服务器就形成了(法定人数).对于高可用性集群,您可以使用高于3的任何奇数.例如,如果设置5台服务器,则集群可以处理两个故障节点等. 物理服务器需要开启的端口 2888 , 3888 和 ...
- Apache ZooKeeper原理剖析及分布式理论名企高频面试v3.7.0
概述 **本人博客网站 **IT小神 www.itxiaoshen.com 定义 Apache ZooKeeper官网 https://zookeeper.apache.org/ 最新版本3.7.0 ...
随机推荐
- 洛谷 P3663 [USACO17FEB]Why Did the Cow Cross the Road III S
P3663 [USACO17FEB]Why Did the Cow Cross the Road III S 题目描述 Why did the cow cross the road? Well, on ...
- vmware启动虚拟机报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine is stored is almost full. To continue, free an additional 1.4 GB of disk space.
报错VMware Workstation has paused this virtual machine because the disk on which the virtual machine i ...
- ArcGIS 空间查询
public static bool QueryMessPoint(IActiveView activeView, IFeatureClass featureClass, string whereCl ...
- HDU 4183Pahom on Water(网络流之最大流)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4183 这题题目意思非常难看懂..我看了好长时间也没看懂..终于是从网上找的翻译. .我就在这翻译一下吧 ...
- 怎样安装Windows7操作系统
1. 打开电脑,插入Windows7安装光盘. 2. 又一次启动电脑: 3. 依据提示按下对应的键.进入选择启动项菜单选择光驱引导.在"Boot Menu"界面按键盘上下键选 ...
- Android App中使用Gallery制作幻灯片播放效果
http://www.jb51.net/article/83313.htm 我们有时候在iPhone手机上或者Windows上面看到动态的图片,可以通过鼠标或者手指触摸来移动它,产生动态的图片滚动效果 ...
- A电脑能ping 通B电脑,但B电脑无法ping能和访问B
过程: A电脑共享了打印机,B电脑想连接A的打印机,发现拒绝访问,无法登录A电脑 问题: A电脑能ping 通B电脑,但B电脑无法ping能和访问B 原因:A电脑禁用了共享访问 处理:使用一键共享设置 ...
- Codeforces Round #240 (Div. 2) 题解
A: 1分钟题,往后扫一遍 int a[MAXN]; int vis[MAXN]; int main(){ int n,m; cin>>n>>m; MEM(vis,); ; i ...
- mescroll报错
1.Cannot read property 'insertBefore' of null:说明你的容器id未找到,应确认你的容器id名与你NEW的容器名一致:
- 【Redis发布订阅】
Redis通过PUBLISH.SUBSCRIBE等命令实现发布与订阅模式. 举例:QQ群的公告,单个发布者,多个收听着. *** 发布/订阅 PUBLISH 频道 消息 将消息发布到指定的频道. . ...