事务日志可视化转换
#!/bin/sh
# scriptname: zkLog2txt.sh
# zookeeper事务日志为二进制格式,使用LogFormatter方法转换为可阅读的日志
if [ -z "$1" -o "$1" = "-h" ];then
echo "Useage: $0 <LogFile> [zkDir]"
echo "eg:
$0 /opt/zpdata/version-2/log.3000002c7 /opt/zookeeper \\
|grep '^7/24/13'|grep -A 10 -B 10 GAEI_AF_NotifyServer|more"
exit 0
fi
#LogFile=/dfs/zpdata/version-2/log.100000001
LogFile=$1
zkDir=$2
[ -z "$zkDir" ] && zkDir=/opt/zookeeper
[ ! -f "$LogFile" ] && echo "LogFile:$LogFile not exist!" && exit 1
[ ! -d "$zkDir" ] && echo "zkDir:$zkDir not exist!" && exit 1
[ ! -d "$zkDir/lib" ] && echo "zkDir:$zkDir/lib not exist!" && exit 1
#java -cp $zkDir/zookeeper.jar:$zkDir/lib/slf4j-api-1.6.1.jar:$zkDir/lib/slf4j-log4j12-1.6.1.jar:$zkDir/lib/log4j-1.2.15.jar \
#org.apache.zookeeper.server.LogFormatter "$LogFile"
JAVA_OPTS="$JAVA_OPTS -Djava.ext.dirs=$zkDir:$zkDir/lib"
java $JAVA_OPTS org.apache.zookeeper.server.LogFormatter "$LogFile"
查看zookeeper日志的方法:在zookeeper主机上执行 zkLog2txt.sh <zk日志文件>,如下:
zkLog2txt.sh /hadoop/zookeeper/version-2/log.a00000001 /opt/zookeeper|more