/etc/zookeeper/conf/zoo.cfg,通過dataLogDir指定事務日志目錄,如dataLogDir=/var/log/zookeeper。conf/log4j.properties中修改zookeeper.root.logger,如zookeeper.root.logger=INFO, ROLLINGFILE。zkServer.sh get-logs查看當前日志,或添加--date參數查看特定日期日志。/var/log/zookeeper目錄,可用cat或tail -f命令查看,如cat /var/log/zookeeper/zookeeper.out。org.apache.zookeeper.server.QuorumPeer的Logging屬性中查看日志。zoo.cfg中配置autopurge.snapRetainCount(保留快照數)和autopurge.purgeInterval(清理間隔,單位小時),如autopurge.snapRetainCount=3,autopurge.purgeInterval=24。zkCleanup.sh腳本,如./bin/zkCleanup.sh -n 3保留最近3個快照及對應日志。/etc/logrotate.d/zookeeper配置文件,添加以下內容實現按天輪轉、保留7天日志并壓縮:/var/log/zookeeper/*.log {
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
}
手動測試輪轉:sudo logrotate -f /etc/logrotate.d/zookeeper。zoo.cfg配置分析。