Detailed Introduction http://blog.csdn.net/hepeng597/article/details/7768615
Reference http://www.linuxidc.com/Linux/2011-04/34116.htm
1 For example we want to cut Nginx log, first we enter/etc/logrotate.d/this directory, and then build nginx this file
VI Nginx
/data/wwwlogs/*nginx.log {# #日志所在的目录dailyrotate 5missingokdateextcompressnotifemptysharedscriptspostrotate [-E/ Var/run/nginx.pid] && kill-usr1 ' cat/var/run/nginx.pid ' Endscript}
Parameter description:
Monthly specify a dump cycle of monthly
Daily Specify a dump cycle of daily
Weekly specify the dump cycle as weekly
Rotate count Specifies the number of times the log file was dumped before it was deleted, 0 means no backup, 5 means 5 backups reserved (this means a 5-day backup is reserved)
Compress post-dump log after gzip compression
Copytruncate The log file is emptied after the current log file is copied, instead of renaming the current log file to create a new
Notifempty if it's an empty file, don't dump it.
Dateext the log file after switching appends the date of the previous dash and YYYYMMDD format.
[-e/var/run/nginx.pid] && kill-usr1 ' cat/var/run/nginx.pid ' endscript This parameter is for Nginx to regenerate the log
2. Restart the SYSLOGD service
Service Rsyslog Restart
3 Testing
#强制执行某个日志的切换, Nginx is the filename of the file under/ETC/LOGROTATE.D
Logrotate-f/etc/logrotate.d/nginx
#如果在存放日志的目录下发现了切换的日志文件, the switch is successful
This article is from the "Drifting Away" blog, make sure to keep this source http://825536458.blog.51cto.com/4417836/1812252
Periodically generate logs with logrotate and delete them periodically for all logs on the system