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 ...
随机推荐
- Find problem in eXtremeDB
class table1 { char<8> f1; char<80> f2; uint4 f3; uint4 f4; double ...
- 维护的JSP站点数据丢失
两个月前换了份工作,然后接手了三台server.上面乱七八糟的网站和应用大把. 当中有维护一个瀚石苑:http://www.hanshiyuan.com/.三天两头的丢失数据. 都不知道怎么找回,好在 ...
- nios sgdma(Scatter-Gather dma)示例
在 Quartus7.2之后的版本中,除了原有的基于avalon-mm总线的DMA之外,还增加了Scatter-Gather DMA这种基于avalon-ST流总线的DMA IP核,它更适合与大量数据 ...
- 浏览器Console创建canvas base64 png图片
火狐中运行:console.log var canvas = document.createElement('canvas'); canvas.width =1 canvas.height =1 ca ...
- DispatcherServlet 前置控制器
1.DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容 ...
- BZOJ 2553 AC自动机+矩阵快速幂 (神题)
思路: 我们先对所有读进来的T建一个AC自动机 因为走到一个禁忌串就需要回到根 所以呢 搞出来所有的结束点 或一下 fail指针指向的那个点 然后我们就想转移 a[i][j]表示从i节点转移到j节点的 ...
- codeforces 710E Generate a String(简单dp)
传送门:http://codeforces.com/problemset/problem/710/E 分析: 让你写一个全由"a"组成的长为n的串,告诉你两种操作,第一种:插入一个 ...
- java中replaceAll反斜杠\ or java中replaceAll 括号[
java中replaceAll反斜杠\ String s=new String("this is a \\"); s.replaceAll("\\",&qu ...
- C++入门之HelloWorld
1.在VS2017上新建一个C++空白项目,命名为hello 2.在资源文件下新建添加新建项main.cpp 3.在main.cpp中编写hello world输出代码 #include<std ...
- BZOJ3569: DZY Loves Chinese II(线性基构造)
Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图, ...