zookeeper zoo.cfg配置文件

 
一、zookeeper的配置文件 
  
  zoo.cfg   配置文件是我们安装zookeeper的时候复制 重命名出来的文件
 
   命令: cp zoo_smaple.cfg zoo.cfg
  zkServer.sh 获取执行
  进入zookeeper 查看配置文件
  cd /myapp/zookeeper/conf
  
 
 
  执行命令 查看配置文件信息
  
  命令:vim zoo.cfg
     
  这是基本的配置文件。
  
二、zoo.cfg 配置项
  1. 查找配置项
  2. 最小化配置 Minimum Configuration
    clientPort: client需要连接的服务器端口好
    dataDir: 默认情况下,zookeeper的事务日志 和 数据快照 都会保存在 dataDir 目录下
    a. 事务日志
      类似 => redis 【aof 模式】 => write,append ...【aof命令】
    b. 快照
      类似 => redis 【rdb】
  snapcount: 事务日志达到某数量 ,生成一次快照
  tickTime: zookeeper心跳时间 【2000】 检测
  dataLogDir: 用来设置事务日志的的path
 
  3.修改默认的配置
   
    dataDir=/myapp/zookeeper/log1
    dataLogDir=/myapp/zookeeper/log2
    新建log1 log2 文件
 
    
 
    修改配置: dataDir=/myapp/zookeeper/log1 ,dataLogDir=/myapp/zookeeper/log2
    然后重启 zookeeper 
    如果无法关闭可以通过杀死进程的方式重启(必须要重启才能生效配置)
    
    命令 kill -9 4225 杀死进程 (4225 ) 是进程编号; 可以通过   命令 netstat -tlnp 查询;
 
    
 
    
 
 
 
  重启zk
    ./zkServer.sh  start
 
  为什么dataDir 没有快照?
    因为事务日志达到10W阀值 的时候才 生成一次快照(默认值是10W)
    所以我们需要设置配置snapCount的值
 
  官方原文:
  snapCount
  (Java system property: zookeeper.snapCount)
  ZooKeeper records its transactions using snapshots and a transaction log (think write-ahead log).The number of transactions recorded in the transaction log before a snapshot can be taken (and the transaction log rolled) is determined by snapCount. In order to prevent all of the machines in the quorum from taking a snapshot at the same time, each ZooKeeper server will take a snapshot when the number of transactions in the transaction log reaches a runtime generated random value in the [snapCount/2+1, snapCount] range.The default snapCount is 100,000.
 
  修改zoo.cfg文件
  命令: vim zoo.cfg
  snapCount=2
  
 
  重启zk就可以了
 
 
  minSessionTimeout maxSessionTimeout 【txp长连接 + session机制 + watcher】
    默认情况下 : tickTime=2秒
    min=4s
    max=40s
 
  maxClientCnxns : 设置为0 禁用
    为了防止dos攻击 , 一个ip默认60个长连接 (连接zookeeper)
    一般的,机器 放 60个应用程序 一个程序连接一个zookeeper
 
  autopurge.snapRetainCount =3
  autopurge.purgeInterval =1
    【一个小时检测一次,最多保留最近的3个事务日志 和 事务快照】
     快照和事务日志的清理,如果快照个数太多, 照成空间浪费
 
  log4j 日志
    zookeeper的一些运行日志, 输出日志
    如果将zookeeper的这些日志放到指定目录,需要修改配置文件 zkEnv.sh
  
 
  命令:vim zkEnv.sh
  
  
  修改上面的路径就可以了
 
 
原文地址:https://www.cnblogs.com/dragon-L/p/8532287.html