Requirements: Split the nginx logs according to the current date every day, one file per day, and delete files that are more than 30 days old, that is, only one month of logs are retained.
Write the nginx log splitting shell script as follows:
thereintologs_pathandpid_pathThe path should be added according to your actual situation.
You can see the path to the pid file in the nginx.conf file, or you can find it with the following command:
The command is briefly introduced
USR1 is also commonly used to inform applications to overload configuration files; For example, sending a USR1 signal to the Apache HTTP server will cause the following steps to occur: stop accepting new connections, wait for the current connection to stop, reload the configuration file, reopen the log file, restart the server, and thus achieve a relatively smooth non-shutdown change.
Upload the script file to your own server (whatever directory you want)
Grant script execution permissions
Test scripts
If an error is reported, you can refer to the following fixes:
Finally, install the crontab service and add a scheduled task! Execute the log splitting script rule at 2 AM every day:
Attached is the sh script:
Tourists, if you want to see the hidden content of this post, please Reply
|