arm-linux平台通过syslog + logrotate + 脚本实现日志管理

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 查看结果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值