系统相关
首页 > 系统相关> > linux 日志分割

linux 日志分割

作者:互联网

[root@clsn6 ~]# vim /etc/logrotate.d/host.access.log
/usr/local/nginx1.19.4/logs/host.access.log {
monthly
rotate 5
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
# /usr/bin/killall -HUP rsyslogd
if [ -f /usr/local/nginx1.19.4/logs/nginx.pid ]; then

kill -USR1 `cat /usr/local/nginx1.19.4/logs/nginx.pid`

fi
endscript
}

logrotate /etc/logrotate.conf
logrotate -vf /etc/logrotate.d/host.access.log

 

分割文件文件名为host.access.log

#!/bin/bash
dir=/usr/local/nginx1.19.4/logs/; #日志路径
file=host.access.log.1; #日志名称
date_file=host.access.log-`date +"%Y%m%d"`; #分割日志文件名称
cd $dir && mv -f $file $date_file; #进行分割

#find $dir -mtime +15 -name "$file-*.log" -exec rm -rf {} \;

 

修改分割文件的文件名

crontab -e
0 0 * * * logrotate -vf /etc/logrotate.d/host.access.log
0 1 * * * sh /usr/local/nginx1.19.4/logs/fenge.sh

跑定时任务

标签:分割,log,logrotate,access,host,usr,linux,日志,logs
来源: https://www.cnblogs.com/yizhibaiyang/p/15402936.html