syslog:实时接收,存储系统产生的日志
logrotate:定期对已生成的日志文件进行切割、压缩、删除,避免日志无限增长
脚本:周期60秒,执行一次/usr/bin/logrotate -s /data/logrotate.status /etc/logrotate.conf
可以简单实现磁盘管理:统计压缩后文件大小,然后保留文件个数,将日志文件大小控制在300M以内
/etc/logrotate.conf配置文件:
su root root
# create new (empty) log files after rotating old ones
create
/data/log/messages
{
rotate 200
size 20M
missingok
notifempty
# delaycompress
compress
sharedscripts
postrotate
/bin/kill -HUP $(/bin/cat /var/run/syslogd.pid 2>/dev/null) 2>/dev/null || true
endscript
}
/data/log/wpa_sup_log.txt
{
rotate 5
size 10k
missingok
notifempty
# delaycompress
compress
sharedscripts
postrotate
PID=$(ps -ef | grep wpa_supplicant | grep -v grep | awk '{print $1}')
if [ -n "$PID" ]; then
kill -HUP $(PID) 2>/dev/null || true
fi
endscript
}
# system-specific logs may be configured here
4 系统启动后,启动运行脚本logrotate.sh
while :
sleep 60
/usr/bin/logrotate -s /data/logrotate.status /etc/logrotate.conf
done
5 查看结果