In the Nginx log cutting aspect, my method and other people's methods have some different, but for me this method, if someone feels bad, can give me, thank you
nginx Log Cutting , I was directly written by a simple shell implementation, the contents are as follows:
The code is as follows |
Copy Code |
Mv/usr/local/nginx/logs/abc.log/www/logbak/abc ' Date +%y%m%d%h%m '. Log /usr/local/nginx/sbin/nginx-s Reload |
After this execution, you will generate the log file in the/www/logbak directory, you can write the task of executing this shell in/etc/crontab, you can do it once in one hour, or you can perform it once a day, or you can perform it once a week, which depends on your own needs.
I am here every morning at 8 o ' Day, the resulting file format is this: Abc201111090801.log
So I found a way to delete the log file according to the rules of the file.
The code is as follows |
Copy Code |
Rm-f/www/logbak/abc ' Date ' +%y%m%d '-d ' -10 Day ' *.log |
This is also written in the shell script, and then every day to go back to/www/logbak directory to find the current time before the 10 days of files, and delete
Add one more example
1. Define Log roll Policy
code is as follows |
copy code |
Vim Nginx-log-rotate /data/weblogs/*.log { nocompress Daily copytruncate Create notifempty Rotate 7 olddir/data/weblogs/old_log Missingok & nbsp Dateext postrotate /bin/kill-hup ' Cat/var/run /nginx.pid 2>/dev/null ' 2>/dev/null | | True endscript } |
[Warning]/data/weblogs/*.log uses wildcard characters, all matching log files in the/data/weblogs/directory are cut. If you want to cut a particular log file, you specify the file. [/warning]
2. Set up Scheduled Tasks
The code is as follows |
Copy Code |
# Vim/etc/crontab * * * Root (/usr/sbin/logrotate-f/path/to/nginx-log-rotate) |
This makes the log cut 23 59 minutes a day.