如何使用 PurgeTxnLog 清除 zookeeper 日志?
How to purge zookeeper logs with PurgeTxnLog?
Zookeeper 迅速将其内部二进制文件遍及我们的生产环境。
根据:http://zookeeper.apache.org/doc/r3.3.3/zookeeperAdmin.html
和
http://dougchang333.blogspot.com/2013/02/zookeeper-cleaning-logs-snapshots.html
这是预期的行为,您必须调用 org.apache.zookeeper.server.PurgeTxnLog
定期旋转它的便便。
所以:
% ls -l1rt /tmp/zookeeper/version-2/
total 314432
-rw-r--r-- 1 root root 67108880 Jun 26 18:00 log.1
-rw-r--r-- 1 root root 947092 Jun 26 18:00 snapshot.e99b
-rw-r--r-- 1 root root 67108880 Jun 27 05:00 log.e99d
-rw-r--r-- 1 root root 1620918 Jun 27 05:00 snapshot.1e266
... many more
% sudo java -cp zookeeper-3.4.6.jar::lib/jline-0.9.94.jar:lib/log4j-1.2.16.jar:lib/netty-3.7.0.Final.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:conf \
org.apache.zookeeper.server.PurgeTxnLog \
/tmp/zookeeper/version-2 /tmp/zookeeper/version-2 -n 3
但我得到:
% ls -l1rt /tmp/zookeeper/version-2/
... all the existing logs plus a new directory
/tmp/zookeeper/version-2/version-2
我是不是做错了什么?
zookeeper-3.4.6/
由于我没有通过 Zookeeper 听到修复,这是一个简单的解决方法:
COUNT=6
DATADIR=/tmp/zookeeper/version-2/
ls -1drt ${DATADIR}/* | head --lines=-${COUNT} | xargs sudo rm -f
应该 运行 每天从 cron 作业或 jenkins 执行一次,以防止 zookeeper 爆炸。
从 3.4.0 开始,ZooKeeper 现在具有自动清除功能。看看https://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html
它说你可以使用 autopurge.snapRetainCount
和 autopurge.purgeInterval
autopurge.snapRetainCount
New in 3.4.0: When enabled, ZooKeeper auto purge feature retains the autopurge.snapRetainCount most recent snapshots and the corresponding transaction logs in the dataDir and dataLogDir respectively and deletes the rest. Defaults to 3. Minimum value is 3.
autopurge.purgeInterval
New in 3.4.0: The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging. Defaults to 0.
您需要在zookeeper的.properties文件中指定参数dataDir
和snapDir
的值为dataDir
。
如果您的配置如下所示。
dataDir=/data/zookeeper
如果你想保留最后10个logs/snapshots
,你需要像下面这样调用PurgeTxnLog
(3.5.9版本)
java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.17.jar:conf org.apache.zookeeper.server.PurgeTxnLog /data/zookeeper /data/zookeeper -n 10
Zookeeper 迅速将其内部二进制文件遍及我们的生产环境。 根据:http://zookeeper.apache.org/doc/r3.3.3/zookeeperAdmin.html 和 http://dougchang333.blogspot.com/2013/02/zookeeper-cleaning-logs-snapshots.html 这是预期的行为,您必须调用 org.apache.zookeeper.server.PurgeTxnLog 定期旋转它的便便。
所以:
% ls -l1rt /tmp/zookeeper/version-2/
total 314432
-rw-r--r-- 1 root root 67108880 Jun 26 18:00 log.1
-rw-r--r-- 1 root root 947092 Jun 26 18:00 snapshot.e99b
-rw-r--r-- 1 root root 67108880 Jun 27 05:00 log.e99d
-rw-r--r-- 1 root root 1620918 Jun 27 05:00 snapshot.1e266
... many more
% sudo java -cp zookeeper-3.4.6.jar::lib/jline-0.9.94.jar:lib/log4j-1.2.16.jar:lib/netty-3.7.0.Final.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:conf \
org.apache.zookeeper.server.PurgeTxnLog \
/tmp/zookeeper/version-2 /tmp/zookeeper/version-2 -n 3
但我得到:
% ls -l1rt /tmp/zookeeper/version-2/
... all the existing logs plus a new directory
/tmp/zookeeper/version-2/version-2
我是不是做错了什么?
zookeeper-3.4.6/
由于我没有通过 Zookeeper 听到修复,这是一个简单的解决方法:
COUNT=6
DATADIR=/tmp/zookeeper/version-2/
ls -1drt ${DATADIR}/* | head --lines=-${COUNT} | xargs sudo rm -f
应该 运行 每天从 cron 作业或 jenkins 执行一次,以防止 zookeeper 爆炸。
从 3.4.0 开始,ZooKeeper 现在具有自动清除功能。看看https://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html
它说你可以使用 autopurge.snapRetainCount
和 autopurge.purgeInterval
autopurge.snapRetainCount
New in 3.4.0: When enabled, ZooKeeper auto purge feature retains the autopurge.snapRetainCount most recent snapshots and the corresponding transaction logs in the dataDir and dataLogDir respectively and deletes the rest. Defaults to 3. Minimum value is 3.
autopurge.purgeInterval
New in 3.4.0: The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging. Defaults to 0.
您需要在zookeeper的.properties文件中指定参数dataDir
和snapDir
的值为dataDir
。
如果您的配置如下所示。
dataDir=/data/zookeeper
如果你想保留最后10个logs/snapshots
,你需要像下面这样调用PurgeTxnLog
(3.5.9版本)
java -cp zookeeper.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-log4j12-1.7.5.jar:lib/log4j-1.2.17.jar:conf org.apache.zookeeper.server.PurgeTxnLog /data/zookeeper /data/zookeeper -n 10