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 ...
随机推荐
- Unity 模拟点击Home键和启动其他app
using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehav ...
- Unity 获得视频的某一帧,生成缩略图
Unity 并无直接获取视频某一帧图像的API,所以想要生成缩略图就要自己写方法了, 图片和视频都可以用这种方式生成缩略图,另,转载请标明出处,谢谢. using System.Collections ...
- 洛谷——P1966 火柴排队
https://www.luogu.org/problem/show?pid=1966 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列 ...
- 转:Mac下搭建svn服务器和XCode配置svn
Mac下搭建svn服务器和XCode配置svn 先打开命令行终端. 1.创建svn repository svnadmin create /yourpath/svnroot/repository 2. ...
- 实战Jquery(四)--标签页效果
这两天完毕了实战四五六的样例,实例四是标签页的实现方法,实例五是级联菜单下拉框,实例六是窗体效果,都是web层经常使用的效果.越到后面越发认为技术这东西,就是一种思路的展现,懂了要实现 ...
- 9.java 操作mongodb插入、读取、修改以及删除基础
1 package mongodb; import java.net.UnknownHostException; import java.util.ArrayList; import java.uti ...
- RandomStringUtils生成随机数
org.apache.commons.lang.RandomStringUtils; //产生5位长度的随机字符串,中文环 ...
- 关于HTML5和CSS3的几个“新增”
html5和css3分别是目前最新的web前端编程的标准,加入了新的标准和要求. 1.HTML5新增input输入类型,即type后面的值 文本域 <input type="text& ...
- Asp.Net碎知识
在aspx页面 获取值: UserModel user=new UserModel();实例化 user.Address=context["txtAddress"]; 如果前台不需 ...
- SQL传数组到存储过程中
方法一 CREATE PROC D_t_Base_Employee @str varchar(100) as declare @sql varchar(1000) set @sql='DELETE E ...