在使用zookeeper过程中,我们知道,会有dataDir和dataLogDir两个目录,分别用于snapshot和事务日志的输出(默认情况下只有dataDir目录,snapshot和事务日志都保存在这个目录中,正常运行过程中,ZK会不断地把快照数据和事务日志输出到这两个目录,并且如果没有人为操作的话,ZK自己是不会清理这些文件的,需要管理员来清理,这里介绍4种清理日志的方法。在这4种方法中,推荐使用第一种方法,对于运维人员来说,将日志清理工作独立出来,便于统一管理也更可控。毕竟zk自带的一些工具并不怎么给力,这里是社区反映的两个问题:

第一种,也是运维人员最常用的,写一个删除日志脚本,每天定时执行即可:

#!/bin/bash

#snapshot file dir
dataDir=/home/yunva/zookeeper/bin/snapshot/version-
#tran log dir
dataLogDir=/home/yunva/zookeeper/bin/snapshot/version-
#zk log dir
#Leave files
count=
count=$[$count+]
ls -t $dataLogDir/log.* | tail -n +$count | xargs rm -f
ls -t $dataDir/snapshot.* | tail -n +$count | xargs rm -f

crontab -e
2 2 * * * /bin/bash /root/clean_zook_log.sh > /dev/null 2>&1

以上这个脚本定义了删除对应两个目录中的文件,保留最新的30个文件,可以将他写到crontab中,设置为每天凌晨2点2分执行一次就可以了。

第二种,使用ZK的工具类PurgeTxnLog,它的实现了一种简单的历史文件清理策略,简单使用如下:
java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir><snapDir> -n <count>

第三种,对于上面这个Java类的执行,ZK自己已经写好了脚本,在bin/zkCleanup.sh中,所以直接使用这个脚本也是可以执行清理工作的。

第四种,从3.4.0开始,zookeeper提供了自动清理snapshot和事务日志的功能,通过配置 autopurge.snapRetainCount 和 autopurge.purgeInterval 这两个参数能够实现定时清理了。这两个参数都是在zoo.cfg中配置的:
autopurge.purgeInterval  这个参数指定了清理频率,单位是小时,需要填写一个1或更大的整数,默认是0,表示不开启自己清理功能。
autopurge.snapRetainCount 这个参数和上面的参数搭配使用,这个参数指定了需要保留的文件数目。默认是保留3个。

通过配置 autopurge.snapRetainCount 和 autopurge.purgeInterval 这两个参数能够实现定时清理了。
这两个参数都是在zoo.cfg中配置的,将其前面的注释去掉,根据需要修改日志保留个数:

tickTime=
initLimit=
syncLimit=
dataDir=/data/yunva/zookeeper-3.4./data
dataLogDir=/data/yunva/zookeeper-3.4./logs
clientPort=
autopurge.snapRetainCount=
autopurge.purgeInterval=
server.=u04rtv01.yaya.corp::
server.=u04rtv02.yaya.corp::
server.=u04rtv03.yaya.corp::
server.=u04rtv04.yaya.corp::
server.=u04rtv05.yaya.corp::

此处我们的配置就是:保留48小时内的日志,并且保留20个文件

autopurge.purgeInterval  这个参数指定了清理频率,单位是小时,需要填写一个1或更大的整数,默认是0,表示不开启自己清理功能。

autopurge.snapRetainCount 这个参数和上面的参数搭配使用,这个参数指定了需要保留的文件数目。默认是保留3个。

查看zook日志的方法
cd /data/zookeeper-3.4.6

java -classpath .:lib/slf4j-api-1.6.1.jar:zookeeper-3.4.6.jar org.apache.zookeeper.server.LogFormatter /data/zookeeper-3.4.6/logs/version-2/log.400000001

# java -classpath .:lib/slf4j-api-1.6..jar:zookeeper-3.4..jar org.apache.zookeeper.server.LogFormatter /data/zookeeper-3.4./logs/version-/log.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

ZooKeeper Transactional Log File with dbid  txnlog format version 

// :: PM CST session 0x25890ed3acc0000 cxid 0x0 zxid 0x200000001 createSession
// :: PM CST session 0x25890ed3acc0000 cxid 0x2 zxid 0x200000002 create '/consumers,,v{s{31,s{'world,'anyone}}},F,1
// :: PM CST session 0x25890ed3acc0000 cxid 0x4 zxid 0x200000003 error -
// :: PM CST session 0x25890ed3acc0000 cxid 0x5 zxid 0x200000004 create '/brokers,,v{s{31,s{'world,'anyone}}},F,2
// :: PM CST session 0x25890ed3acc0000 cxid 0x6 zxid 0x200000005 create '/brokers/ids,,v{s{31,s{'world,'anyone}}},F,1
// :: PM CST session 0x25890ed3acc0000 cxid 0x8 zxid 0x200000006 create '/brokers/topics,,v{s{31,s{'world,'anyone}}},F,2
// :: PM CST session 0x25890ed3acc0000 cxid 0xa zxid 0x200000007 error -
// :: PM CST session 0x25890ed3acc0000 cxid 0xb zxid 0x200000008 create '/config,,v{s{31,s{'world,'anyone}}},F,3
// :: PM CST session 0x25890ed3acc0000 cxid 0xc zxid 0x200000009 create '/config/changes,,v{s{31,s{'world,'anyone}}},F,1
// :: PM CST session 0x25890ed3acc0000 cxid 0xe zxid 0x20000000a create '/config/topics,,v{s{31,s{'world,'anyone}}},F,2
// :: PM CST session 0x25890ed3acc0000 cxid 0x10 zxid 0x20000000b error -
// :: PM CST session 0x25890ed3acc0000 cxid 0x11 zxid 0x20000000c create '/admin,,v{s{31,s{'world,'anyone}}},F,4
// :: PM CST session 0x25890ed3acc0000 cxid 0x12 zxid 0x20000000d create '/admin/delete_topics,,v{s{31,s{'world,'anyone}}},F,1
// :: PM CST session 0x25890ed3acc0000 cxid 0x16 zxid 0x20000000e create '/controller,#7b2276657273696f6e223a312c2262726f6b65726964223a302c2274696d657374616d70223a2231343739393030333933363132227d,v{s{31,s{'world,'anyone}}},T,5
// :: PM CST session 0x25890ed3acc0000 cxid 0x1a zxid 0x20000000f error -
// :: PM CST session 0x25890ed3acc0000 cxid 0x1b zxid 0x200000010 create '/controller_epoch,#31,v{s{31,s{'world,'anyone}}},F,6
// :: PM CST session 0x25890ed3acc0000 cxid 0x27 zxid 0x200000011 error -
// :: PM CST session 0x25890ed3acc0000 cxid 0x2c zxid 0x200000012 create '/brokers/ids/0,#7b226a6d785f706f7274223a2d312c2274696d657374616d70223a2231343739393030333933363932222c22686f7374223a226c6f63616c686f7374222c2276657273696f6e223a312c22706f7274223a393039327d,v{s{31,s{'world,'anyone}}},T,1
// :: PM CST session 0x25890ed3acc0000 cxid 0x33 zxid 0x200000013 closeSession null
// :: PM CST session 0x15890ed3ace0000 cxid 0x0 zxid 0x200000014 createSession
// :: PM CST session 0x15890ed3ace0000 cxid 0xa zxid 0x200000015 create '/controller,#7b2276657273696f6e223a312c2262726f6b65726964223a302c2274696d657374616d70223a2231343739393030363137383833227d,v{s{31,s{'world,'anyone}}},T,7
// :: PM CST session 0x15890ed3ace0000 cxid 0xf zxid 0x200000016 setData '/controller_epoch,#32,1
// :: PM CST session 0x15890ed3ace0000 cxid 0x1b zxid 0x200000017 error -
// :: PM CST session 0x15890ed3ace0000 cxid 0x20 zxid 0x200000018 create '/brokers/ids/0,#7b226a6d785f706f7274223a2d312c2274696d657374616d70223a2231343739393030363137393735222c22686f7374223a226c6f63616c686f7374222c2276657273696f6e223a312c22706f7274223a393039327d,v{s{31,s{'world,'anyone}}},T,2
// :: PM CST session 0x25890ed3acc0001 cxid 0x0 zxid 0x200000019 createSession
// :: PM CST session 0x25890ed3acc0001 cxid 0xe zxid 0x20000001a error -
// :: PM CST session 0x25890ed3acc0001 cxid 0x11 zxid 0x20000001b closeSession null
// :: PM CST session 0x15890ed3ace0001 cxid 0x0 zxid 0x20000001c createSession
// :: PM CST session 0x15890ed3ace0001 cxid 0xe zxid 0x20000001d create '/brokers/ids/1,#7b226a6d785f706f7274223a2d312c2274696d657374616d70223a2231343739393031303536343337222c22686f7374223a22302e302e302e30222c2276657273696f6e223a312c22706f7274223a393039327d,v{s{31,s{'world,'anyone}}},T,3
// :: PM CST session 0x25890ed3acc0002 cxid 0x0 zxid 0x20000001e createSession
// :: PM CST session 0x25890ed3acc0002 cxid 0xe zxid 0x20000001f create '/brokers/ids/2,#7b226a6d785f706f7274223a2d312c2274696d657374616d70223a2231343739393031303931393335222c22686f7374223a22302e302e302e30222c2276657273696f6e223a312c22706f7274223a393039327d,v{s{31,s{'world,'anyone}}},T,4
// :: PM CST session 0x15890ed3ace0000 cxid 0x32 zxid 0x200000020 closeSession null
// :: PM CST session 0x25890ed3acc0002 cxid 0x14 zxid 0x200000021 create '/controller,#7b2276657273696f6e223a312c2262726f6b65726964223a322c2274696d657374616d70223a2231343739393033343434333634227d,v{s{31,s{'world,'anyone}}},T,8
// :: PM CST session 0x25890ed3acc0002 cxid 0x17 zxid 0x200000022 setData '/controller_epoch,#33,2
// :: PM CST session 0x25890ed3acc0002 cxid 0x25 zxid 0x200000023 error -
// :: PM CST session 0x25890ed3acc0002 cxid 0x2a zxid 0x200000024 closeSession null
// :: PM CST session 0x15890ed3ace0001 cxid 0x1b zxid 0x200000025 create '/controller,#7b2276657273696f6e223a312c2262726f6b65726964223a312c2274696d657374616d70223a2231343739393033343439333833227d,v{s{31,s{'world,'anyone}}},T,9
// :: PM CST session 0x15890ed3ace0001 cxid 0x1e zxid 0x200000026 setData '/controller_epoch,#34,3
// :: PM CST session 0x15890ed3ace0001 cxid 0x2b zxid 0x200000027 error -
// :: PM CST session 0x15890ed3ace0001 cxid 0x2e zxid 0x200000028 closeSession null
EOF reached after txns.

转自

zookeeper3.4.6配置实现自动清理日志 - CSDN博客
https://blog.csdn.net/reblue520/article/details/52311314

zookeeper3.4.6配置实现自动清理日志【转】的更多相关文章

  1. zookeeper3.4.6配置实现自动清理日志

    在使用zookeeper过程中,我们知道,会有dataDir和dataLogDir两个目录,分别用于snapshot和事务日志的输出(默认情况下只有dataDir目录,snapshot和事务日志都保存 ...

  2. sql server 定期自动清理日志

    https://blog.csdn.net/dqs78833488/article/details/51372491

  3. 自动清理MySQL binlog日志

    开启MySQL binlog日志的服务器,如果不设置自动清理日志,默认binlog日志一直保留着,时间一长,服务器磁盘空间被binlog日志占满,导致MySQL数据库出错. 使用下面方法可以安全清理b ...

  4. Tomcat8.5.24日志自动清理(maxDays)功能探究

    前言 测试人员反馈tomcat目录下的日志占用空间很大,需要自动清理.接到这个反馈时,想象着应该是一个很简单的功能,tomcat应该已经实现了日志的自动清理功能.于是乎,我先到网上查询了如何自动清除t ...

  5. IIS日志自动清理

    IIS在运行的过程中日志会不停地增长,若iis的网站被频繁的调用或不当的调用,则会产生很多日志.我在系统运维的时候曾出现过20G的系统盘,由于合作商开发的程序有问题,每几百微秒调用一次web服务,短期 ...

  6. 自动清理SQLServerErrorLog错误日志避免太大

    问题描述:开启SQLServer自动备份后,备份文件越来越多,有没有及时清理,导致服务器空间不足,备份出错,以至于出现几个G的ErrorLog文件,影响系统的登录管理. 解决办法:定期清理SQLSer ...

  7. shell脚本自动清理服务器日志、图片等信息

    在做性能测试的时候,linux服务器时常会产生大量数据,如日志信息,图片信息,文件信息等,压测一段时间后,导致服务器磁盘空间暂满而崩溃,每天手动清理比较麻烦, 利用shell脚本自动清理,脚本如下 1 ...

  8. Linux**系统实现log日志自动清理

    Linux系统实现log日志自动清理 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  9. 自动清理N天前的二进制日志

    这里以自动清理5天前的二进制日志为例(做了同步或依赖于二进制日志备份的请慎用): 以root身份登录数据库,执行以下命令: ; 首次设置expire_logs_days参数后需要执行flush log ...

随机推荐

  1. 运维监控-使用Zabbix Server 创建 Actions

    运维监控-使用Zabbix Server 创建 Actions 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. zabbix的action默认是关闭的,因此我们想使用它就得先启用哟. ...

  2. SearchServer Elasticsearch Cluster / kibana

    S 使用nginx代理kibana并设置身份验证 https://blog.csdn.net/wyl9527/article/details/72598112 使用nginx代理kibana并设置身份 ...

  3. python 面向对象(三)类与类之间的关系 初始化方法一些类

    ###################总结################# 面试的时候 让写python一些特殊方法 __init__ 创建对象的时候初始化 __new__对象实例化调用第一个方法 ...

  4. vue表单校验提交报错TypeError: Cannot read property 'validate' of undefined

    TypeError: Cannot read property 'validate' of undefined at VueComponent.submitForm (plat_users.html: ...

  5. angular,vue,react的父子通信

    父子通信 父传子 vue: 父组件:<child :msg="datamsg" ></child> //子组件的msg属性上加数据,datamsg是数据 子 ...

  6. 解析ArcGis的标注(一)——先看看分数式、假分数式标注是怎样实现的

    该“标注”系列博文的标注引擎使用“标准标注引擎(standard label engine)”,这个概念如不知道,可不理会,ArcGis默认标注引擎就是它. ArcGis的标注表达式支持VBScrip ...

  7. iOS下如何阻止橡皮筋效果

    $(document).ready(function(){ var stopScrolling = function(event) { event.preventDefault(); } docume ...

  8. git 出现 fatal: refusing to merge unrelated histories 错误

    git pull 失败 ,提示:fatal: refusing to merge unrelated histories 其实这个问题是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远 ...

  9. 用Windows Media Service打造的流媒体点播

    所谓流媒体是指采用流式传输的方式在Internet播放的媒体格式.和需要将整个视频文件全部下载之后才能观看的传统方式相比,流媒体技术是通过将视频文件经过特殊的压缩方式分成一个个的小数据包,由视频服务器 ...

  10. Ubuntu18.04下Python Web环境搭建

    Python3的安装与卸载 pip, pip3的安装 Django2.x的安装 mysql的安装及命令行工具mycli的安装 virtualenv及virtualenvwrapper的安装 IPyth ...