定时清除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 

定时清除zookeeper日志和快照数据非常简单,只需简单3步。

Step1在zookeeper/bin目录建立purgeTxnLog.sh文件,内容如下所示:

 1 #!/bin/sh 
 2  
 3 # Only follow symlinks if readlink supports it 
 4 if readlink -f "$0" > /dev/null 2>&1 
 5 then 
 6   ZOOBIN=`readlink -f "$0"` 
 7 else 
 8   ZOOBIN="$0" 
 9 fi 
10 ZOOBINDIR=`dirname "$ZOOBIN"` 
11  
12 . "$ZOOBINDIR"/zkEnv.sh 
13  
14 #echo "Purge transaction log is starting..." 
15 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" 
16 export PATH 
17 #echo "PATH=$PATH" 
18 #echo "CLASSPATH=$CLASSPATH" 
19  
20 java -cp "$CLASSPATH" org.apache.zookeeper.server.PurgeTxnLog /log/xres/zookeeper/zk_trlog /www/xres/app/zk_data -n 10 
21  
22 #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 

Step3启动服务

[smdev@M12-131 bin]$service crond start 

到此为止,定时清除zookeeper日志和快照数据的全部工作已完成。

原文:http://chenlx.blog.51cto.com/4096635/740112

posted on 2012-05-31 18:09  nwf  阅读(1188)  评论(0编辑  收藏  举报

导航