码迷,mamicode.com
首页 > Windows程序 > 详细

Windows安装和使用zookeeper

时间:2015-11-25 11:35:47      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

      修改后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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/

Windows安装和使用zookeeper

标签:

原文地址:http://www.cnblogs.com/levenew/p/4994037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!