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