說明
logrotate命令是一個日志分割命令
用法
這里以 nginx日志為例
- 開啟日志功能
$ vi /usr/local/nginx/conf/vhost/test.com.conf
server {
......
access_log /home/wwwlogs/test.com.log;
}
- 配置日志分割規(guī)則
$ vi /etc/logrotate.d/nginx # 添加一個配置文件
/home/wwwlogs/test.com.log {
daily
dateext
compress
rotate 7
sharedscripts
postrotate
kill -USR1 `cat /var/run/nginx.pid`
endscript
}
相關(guān)
$ logrotate -f /etc/logrotate.d/nginx # 手動執(zhí)行日志分割
$ logrotate -d -f /etc/logrotate.d/nginx # 啟用調(diào)試模式
參考
http://www.thegeekstuff.com/2010/07/logrotate-examples/
https://huoding.com/2013/04/21/246
http://www.lightxue.com/how-logrotate-works