zookeeper 之 zoo.cfg 配置


前言:

  学习zookeeper 也有两天时间了收获很多,于是我今天想学习一下 zookeeper 中的 zoo.cfg 文件。对于不知道为什么需要zoo.cfg的朋友,可以看一下我zookeeper系列中对zoo.cfg由来的讲解。

版本:

  apache-zookeeper-3.5.7-bin.tar.gz

zoo_sample.cfg(zoo.cfg)文件:

  使用过zookeeper 的朋友应该知道 需要将 conf/zoo_sample.cfg 重命名为 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=/temp/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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

  以上配置内容不是很全面,若要更好的学习,还得去 zookeeper 官网 上看文档。

官网文档解释:

  • tickTime :ZooKeeper使用的基本时间单位(毫秒)。它用于做心跳,并且最小会话超时将是tickTime的两倍。
  • initLimit:是超时ZooKeeper用于限制仲裁中的ZooKeeper服务器必须连接到领导者的时间长度
    zookeeper集群中的包含多台server, 其中一台为leader, 集群中其余的server为follower. initLimit参数配置初始化连接时, follower和leader之间的最长心跳时间. 此时该参数设置为5, 说明时间限制为5倍tickTime, 即5*2000=10000ms=10s.
  • syscLimit:限制了服务器与领导者之间的过时距离。
    该参数配置leader和follower之间发送消息, 请求和应答的最大时间长度. 此时该参数设置为2, 说明时间限制为2倍tickTime, 即4000ms.
  • dataDir:存储内存数据库快照的位置,除非另有说明,否则存储数据库更新的事务日志。
  • dataLogDir:适用于存储日志,若不指定日志将和快照都存放到dataDir 中
  • clientPort:用于侦听客户端连接的端口
  • server.X:ip:2888:3888 集群配置 
    server.X的条目列出了组成ZooKeeper服务的服务器。服务器启动时,它通过在数据目录中查找文件myid来知道它是哪台服务器。该文件包含ASCII的服务器号。
        
    zookeeper集群配置
        server.1=ip1:2888:3888
        server.2=ip2:2888:3888
        server.3=ip3:2888:3888
        
    单服务集群配置,只需要端口不同即可
        server.1=ip:2888:3888
        server.2=ip:4888:5888
        server.3=ip:6888:7888    
        
    注意:
        1: 并不是非得用 2888:3888,若ip是一样的,将端口改成其他都可以。
        2: server.x ,x必须为数字,并且是唯一的。
        3: zookeeper 服务集群数必须为奇数,最少支持数为 3
        4: 集群这里需要配置外,还需要指定一个 myid文件
  • maxClientCnxns: 客户端连接最大数量
  • autopurge.snapRetainCount:保留在 dataDir 中的快照数数量。
  • autopurge.purgeInterval:清除任务间隔(单位小时),设置为“0”则禁用自动清除功能

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM