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:

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

修改后:

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial 
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between 
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just 
  11. # example sakes.
  12. dataDir=E:/zookeepercluster/servcer001/data
  13. dataLogDir=E:/zookeepercluster/servcer001/logs
  14. # the port at which the clients will connect
  15. clientPort=2181
  16. #
  17. # Be sure to read the maintenance section of the 
  18. # administrator guide before turning on autopurge.
  19. #
  20. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  21. #
  22. # The number of snapshots to retain in dataDir
  23. #autopurge.snapRetainCount=3
  24. # Purge task interval in hours
  25. # Set to "0" to disable auto purge feature
  26. #autopurge.purgeInterval=1
  27. server.1=localhost:8881:7771
  28. server.2=localhost:8882:7772
  29. #server.3=192.168.192.7:8883:7773
  30. #server.4=192.168.192.7:8884:7774
  31. #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. android listview 重用view导致的选择混乱问题

    20150526 listview是常用的控件,经常用自定义的adapter,为了提高显示效率,常利用view的重用方式防止重绘,但因为重用利用的是旧的view,常导致显示的数据会由于position ...

  2. SQL Server 2012学习笔记 2 Server Core中命令行安装SQL

    Setup.exe /qs /ACTION=Install /FEATURES=SQLEngine,Replication /INSTANCENAME=MSSQLSERVER /SQLSVCACCOU ...

  3. oracle 使用 decode函数 或 case when 实现行转列

    ----创建测试表 create table student_score( name varchar2(20), subject varchar2(20), score number(4,1) ); ...

  4. 无法连接远程mysql问题

    按照别人的博客操作之后,重启了服务: 前几天,windows上的mysql无法远程连接,在网上搜了一下,都是一个说法,神马改表.加权限.刷新等等,尝试之后都没有用,后来同事告诉了我一个方法,就解决了那 ...

  5. windows8 安装IIS 和 添加网站(转)

    Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows NT版本的可选 ...

  6. 关于iPhone

    ---------------------- 美版有三个版本 A S V A版不能用电信卡,S不能发短信 据说还可能再次上锁 V版目前是大家认为最安全的版本 价格也是比A和S贵的 港版比V版唯一的好处 ...

  7. [spring+springmvc+mybatis实践]学生社团管理系统

    一.简介 ssm框架为现在十分流行的mvc主流框架.mybatis负责与数据库交互,springmvc与spring完美适配,负责控制器和视图渲染.之前有初步学习过ssm框架,这次借学校里的web课设 ...

  8. mongoose的用法(注:连接数据库)

    第一步:连接数据库: mongoose.connect('mongodb://'+user+':'+pass+'@mongo.duapp.com:'+port+'/xzWIRHYlWLAApdsfAz ...

  9. uva 10905 Children's Game (排序)

    题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...

  10. Android 支付宝钱包手势password裂纹战斗

    底 随着移动互联网和手机屏幕越做越大的普及等..购物在移动设备上.消费是必不可少的人们习惯于生活. 随着这股浪潮的兴起,安全.便捷的移动支付的需求也越来越大.故,各大互联网公司纷纷推出了移动支付平台. ...