在对某客户VCSA进行巡检时发现日志存储分区磁盘空间已经占满,在进一步的检查中发现analytics-runtime.log.stderr日志体积已经超过6GB,为留足充分观察与判断故障的时间,临时为日志分区进行了5GB的磁盘空间扩容,经过3天的观察,日志体积超过7GB,平均一天超过300MB的增长速度。
经过我们工程师的专业处置,先已成功降低该日志文件体积,实现日志轮转,方法如下:
新建文件vmware-analytics.lr:
vi /etc/logrotate.d/vmware-analytics.lr
保存以下内容至文件:
/var/log/vmware/analytics/analytics-runtime.log.stderr
/var/log/vmware/analytics/analytics-runtime.log.stdout
{
size 1k
nodateext
rotate 10
missingok
notifempty
compress
copytruncate
nocreate
postrotate
/usr/sbin/vmon-cli -r analytics -c /storage/vmware-vmon/vmonserver > /dev/null
#In rare cases timing issue occurs where the file is written with the previous offset and this fills log-0 instead of trucating it
#Logrotate moves log-0.stderr in log-1.stderr and compresses it before that
filestderr=/var/log/vmware/analytics/analytics-runtime.log-0.stderr
if [ -n "$(find $filestderr -prune -size +1000c)" ]; then
echo "Truncating $filestderr"
>$filestderr
fi
endscript
}
按esc退出编辑模式,然后输入:wq保存退出即可。