zookeeper for linux下载安装

来源:互联网 发布:青山大禹软件 编辑:程序博客网 时间:2024/05/14 08:01

一、下载zookeeper源码包

 [root@localhost ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz 

二、解压

[root@localhost ~]# tar -zxvf zookeeper-3.3.6.tar.gz 

三、进入conf目录

[root@localhost ~]# cd zookeeper-3.3.6/conf/[root@localhost conf]# lsconfiguration.xsl  log4j.properties  zoo_sample.cfg

四、拷贝zoo_samle.cfg为zoo.cfg

[root@localhost conf]# cp zoo_sample.cfg zoo.cfg[root@localhost conf]# lsconfiguration.xsl  log4j.properties  zoo.cfg  zoo_sample.cfg

五、编辑zoo.cfg

[root@localhost conf]# vi zoo.cfg
  1. 单机模式:不做集群,内容如下(data目录需改成你真实输出目录):
# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.dataDir=/root/zookeeper-3.3.6/data# the port at which the clients will connectclientPort=2181

2、集群模式:要做集群,内容如下(dataDir目录和server地址需改成你真实部署机器的信息):

tickTime=2000initLimit=10syncLimit=5dataDir=/root/zookeeper-3.3.6/dataclientPort=2181server.0=192.168.0.109:2555:3555   server.1=192.168.0.110:2555:3555   server.2=192.168.0.111:2555:3555 

并在data目录下放置myid文件:(上面zoo.cfg中的dataDir)

mkdir datavi myid

myid指明自己的id,对应上面zoo.cfg中server.后的数字,第一台的内容为1,第二台的内容为2,内容如下

1

六、启动

[root@localhost bin]# ./zkServer.sh startJMX enabled by defaultUsing config: /root/zookeeper-3.3.6/bin/../conf/zoo.cfgStarting zookeeper ... STARTED

七、测试

[root@localhost bin]# ./zkCli.sh -server 127.0.0.1:2181

运行配置的作用

  • initLimit
    ZooKeeper集群模式下包含多个zk进程,其中一个进程为leader,余下的进程为follower。
    当follower最初与leader建立连接时,它们之间会传输相当多的数据,尤其是follower的数据落后leader很多。initLimit配置follower与leader之间建立连接后进行同步的最长时间。

  • syncLimit
    配置follower和leader之间发送消息,请求和应答的最大时间长度。

  • tickTime
    tickTime则是上述两个超时配置的基本单位,例如对于initLimit,其配置值为5,说明其超时时间为 2000ms * 5 = 10秒。

  • dataLogDir
    dataLogDir指定的路径是事务日志保存路径

  • dataDir
    dataDir指定的路径是快照保存路径,当没有指定dataLogDir路径时,事务日志也会保存在该目录下

  • server.id=host:port1:port2
    其中id为一个数字,表示zk进程的id,这个id也是dataDir目录下myid文件的内容。
    host是该zk进程所在的IP地址,port1表示follower和leader交换消息所使用的端口,port2表示选举leader所使用的端口。
    其配置的含义跟单机模式下的含义类似,不同的是集群模式下还有一个myid文件。myid文件的内容只有一行,且内容只能为1 - 255之间的数字,这个数字亦即上面介绍server.id中的id,表示zk进程的id。

注意
如果仅为了测试部署集群模式而在同一台机器上部署zk进程,server.id=host:port1:port2配置中的port参数必须不同。但是,为了减少机器宕机的风险,强烈建议在部署集群模式时,将zk进程部署不同的物理机器上面。