定时清除Zookeeper日志
命令格式:
- java -cp zookeeper.jar:log4j.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> -n <count>
举例:
- java -cp zookeeper.jar:log4j.jar:conf org.apache.zookeeper.server.PurgeTxnLog /log/xres/zookeeper/zk_trlog /www/xres/app/zk_data -n 10
Step1:在zookeeper/bin目录建立purgeTxnLog.sh文件,内容如下所示:
- #!/bin/sh
- # Only follow symlinks if readlink supports it
- if readlink -f "$0" > /dev/null 2>&1
- then
- ZOOBIN=`readlink -f "$0"`
- else
- ZOOBIN="$0"
- fi
- ZOOBINDIR=`dirname "$ZOOBIN"`
- . "$ZOOBINDIR"/zkEnv.sh
- #echo "Purge transaction log is starting..."
- PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/java/jdk1.6.0_21/bin:/usr/java/jdk1.6.0_21/jre/bin:/bin:/home/smdev/bin:$PATH"
- export PATH
- #echo "PATH=$PATH"
- #echo "CLASSPATH=$CLASSPATH"
- java -cp "$CLASSPATH" org.apache.zookeeper.server.PurgeTxnLog /log/xres/zookeeper/zk_trlog /www/xres/app/zk_data -n 10
- #echo "Purge transaction log is finished."
Step2:创建cron任务。
- [smdev@M12-131 bin]$ crontab –e
任务内容如下:
- 0 */1 * * * sh /www/xres/app/zookeeper-3.3.3/bin/purgeTxnLog.sh >> /log/xres/zookeeper/log/purgeTxnLog.log
- [smdev@M12-131 bin]$service crond start