zookeeper 官网:http://zookeeper.apache.org/ 现在最新版本是 3.4.6 ,但是这个版本我没有运行起来,可能是那配置出现问题了,现在我用的是3.4.5 http://apache.fayea.com/apache-mirror/zookeeper/zookeeper-3.4.5/

环境:windows 8.1 、zookeeper3.4.5

现在要做的是 单机伪集群(木有办法 没有那么多机器啊)

  1. 修改配置文件,在conf中

    将zoo_sample.cfg文件复制一个重命名为zoo.cfg

  2. 修改zoo.cfg 内容

打开zoo.cfg:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

修改后:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=E:/zookeepercluster/servcer001/data
dataLogDir=E:/zookeepercluster/servcer001/logs
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=localhost:8881:7771
server.2=localhost:8882:7772
#server.3=192.168.192.7:8883:7773
#server.4=192.168.192.7:8884:7774
#server.5=192.168.192.7:8885:7775

主要是在下边添加几个服务器的ip地址,因为我的都是本机,所以我这都是一样的地址。

参数解释:

  • tickTime:发送心跳的间隔时间,单位:毫秒

  • dataDir:zookeeper保存数据的目录。

  • clientPort:客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。

  • initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 5个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒

  • syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒

  • server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

3. 在data下面创建一个myid文件,内容为1

这个内容对应的是这个zookeeper的顺序,第一个zookeeper就是1,第二个zookeeper就是2,没有先后顺序,只是不能重复。

这个最好是和 server.x 中的x对应

依次修改配置文件 简历server02,server03,server04节点 目录结构如下:

├── server001

│   ├── data

│   ├── logs

│   └── zookeeper-3.4.5

├── server002

│   ├── data

│   ├── logs

│   └── zookeeper-3.4.5

├── server003

│   ├── data

│   ├── logs

│   └── zookeeper-3.4.5

├── server004

│   ├── data

│   ├── logs

│   └── zookeeper-3.4.5

└── server005

├── data

├── logs

└── zookeeper-3.4.5

这样就配置好了,windows下的单机伪集群。

下面就是启动了:

进入bin下双击 :zkServer.cmd

报这个错误是因为还有节点没有启动起来,都启动了就会不报错了

运行 zkServer.cmd status 可以查看节点的角色  是leader 还是follower

这样一个伪集群就成功了,如果有不对的地方希望大家批评指正,ORZ。

参考文章:

http://www.cnblogs.com/haippy/archive/2012/07/19/2599989.html

http://zookeeper.apache.org/

http://zookeeper.apache.org/doc/current/zookeeperStarted.html

http://zookeeper.apache.org/doc/current/index.html

http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/

zookeeper集群搭建设置的更多相关文章

  1. kafka学习(二)-zookeeper集群搭建

    zookeeper概念 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名 服务等.Zookeeper是h ...

  2. 分布式协调服务Zookeeper集群搭建

    分布式协调服务Zookeeper集群搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装jdk环境 1>.操作环境 [root@node101.yinzhengjie ...

  3. Kafka学习之(五)搭建kafka集群之Zookeeper集群搭建

    Zookeeper是一种在分布式系统中被广泛用来作为:分布式状态管理.分布式协调管理.分布式配置管理.和分布式锁服务的集群.kafka增加和减少服务器都会在Zookeeper节点上触发相应的事件kaf ...

  4. zookeeper集群搭建及Leader选举算法源码解析

    第一章.zookeeper概述 一.zookeeper 简介 zookeeper 是一个开源的分布式应用程序协调服务器,是 Hadoop 的重要组件. zooKeeper 是一个分布式的,开放源码的分 ...

  5. Zookeeper(二) zookeeper集群搭建 与使用

    一.zookeeper集群搭建 鉴于 zookeeper 本身的特点,服务器集群的节点数推荐设置为奇数台.我这里我规划为三台, 为别为 hadoop01,hadoop02,hadoop03    1. ...

  6. ZooKeeper集群搭建过程

    ZooKeeper集群搭建过程 提纲 1.ZooKeeper简介 2.ZooKeeper的下载和安装 3.部署3个节点的ZK伪分布式集群 3.1.解压ZooKeeper安装包 3.2.为每个节点建立d ...

  7. 【图文详解】Zookeeper集群搭建(CentOs6.3)

    Zookeeper简介: Zookeeper是一个分布式协调服务,就是为用户的分布式应用程序提供协调服务的. A.zookeeper是为别的分布式程序服务的 B.Zookeeper本身就是一个分布式程 ...

  8. java 学习笔记(三)ZooKeeper集群搭建实例,以及集成dubbo时的配置 (转)

    ZooKeeper集群搭建实例,以及集成dubbo时的配置 zookeeper是什么: Zookeeper,一种分布式应用的协作服务,是Google的Chubby一个开源的实现,是Hadoop的分布式 ...

  9. zookeeper 集群搭建 转

    通过 VMware ,我们安装了三台虚拟机,用来搭建 zookeeper 集群,虚拟机网络地址如下: hostname                      ipaddress           ...

随机推荐

  1. SQL Server 数据库DML触发器 【一】

    今天学习SQL Server数据库中DML触发器(DDL触发器以后有时间继续学习). 当删除一条创建有触发器的表中的内容时,触发器执行SQL语句. 1.首相先创建一张表,表名称是 [Test] , 内 ...

  2. 跟我一起学写jQuery插件开发方法(转载)

    jQuery如此流行,各式各样的jQuery插件也是满天飞.你有没有想过把自己的一些常用的JS功能也写成jQuery插件呢?如果你的答案是肯定的,那么来吧!和我一起学写jQuery插件吧!     很 ...

  3. iOS内购的订单对应和补单

    内购的关键类: 1.SKPayment(SKMutablePayment可将自己的参数一对一与苹果产生的payment对应起来) 2.TransactionObserver:交易状态更新时执行此方法, ...

  4. poj2407---欧拉函数应用

    欧拉函数介绍: 在数论中,对正整数n,欧拉函数是少于或等于n你的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn),其中 ...

  5. 亲测的一款在线作图神器:ProcessOn

    本人近日发现一款作图神器:ProcessOn 它是一款在线的作图工具,完全国产,前台是用HTML5  Canvas加javascript做绘图,后台用java实现数据处理和图片生成, 整站UI基本类似 ...

  6. T-SQL应用,视图、存储过程、触发器、游标、临时表等

    sqlserver常用操作: 视图.存储过程.触发器.函数 --*********************批处理********************* --[在一个批处理中存有一个语法错误,则所有 ...

  7. MVC中Filter拦截问题记录之重定向陷阱

    出错环境:被拦截的页面中使用了未实例化的对象,比如只有登录后才有的UserInfor对象. 理想中:浏览器请求页面时,会被Filter拦截,然后重定向到指定页面: 实际现象:将断点打入Filter中, ...

  8. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  9. Multiwii 代码解读

    GPS部分 GPS_angle[ROLL]   = (nav[LON]*cos_yaw_x - nav[LAT]*sin_yaw_y) /10;GPS_angle[PITCH]  = (nav[LON ...

  10. perspective结合transform的3D效果

    http://css-tricks.com/almanac/properties/p/perspective/ 链接中讲了 perspective的两种用法及比较: 1.perspective:100 ...