linux内置的日志管理工具,可以按时间、按大小归档、删除
logrotate的主配置文件/etc/logrotate.conf,其中include /etc/logrotate.d 将此目录上的配置纳入
logrotate基于cron定时任务,默认执行周期为1天

实例:
以nginx日志为例
如果nginx日志目录为/usr/local/nginx/logs
在/etc/logrotate.d/中新建nginx_log

/usr/local/nginx/*.log {
su root root
daily
rotate 10
missingok
notifempty
nocompress
# dateext
sharedscripts
postrotate
if [ -f /usr/local/nginx/logs/nginx.pid ]; then
    kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
fi
endscript
}

su root root 这一行可以不添加,如果因为父目录权限问题不能执行,则需要添加

重启logrotate:
systemctl restart rsyslog

强制执行一次日志切割,验证配置是否正确
logrotate -vf /etc/logrotate.d/nginx_log

在/etc/logrotate.d下的脚本会被每天执行一次,如果想以其他时间或者周期执行的话,需要用crontable
设置定时任务时间
输入 crontab –e
添加 59 23 * * * /usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.d/nginx_log >/dev/null 2>&1
保存退出
crontab –l 可以查看定时任务列表

可以查询cron执行的日志,通常位于/var/log/cron