3.zookeeper集群搭建

来源:互联网 发布:centos 7.4 官方下载 编辑:程序博客网 时间:2024/06/03 16:27

下载地址

http://www.apache.org/dyn/closer.cgi/zookeeper/


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

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

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

  2. 修改zoo.cfg 内容

        打开zoo.cfg:

# 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.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/tmp/zookeeper# the port at which the clients will connectclientPort=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 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.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=E:/zookeepercluster/servcer001/datadataLogDir=E:/zookeepercluster/servcer001/logs# the port at which the clients will connectclientPort=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=1server.1=localhost:8881:7771server.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对应


启动:

zookeeper/bin/zkServer.sh start

然后以start-foreground方式启动,会看到启动日志

zkServer.sh start-foreground


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


0 0
原创粉丝点击