Services on Linux server generally last long, so that the log files of services become larger over time, and if the log is poorly handled, it may even fill the disk. Fortunately found the Logrotate this program to deal with.
Here is the installation configuration process
zypper in -y logrotate# Although Logrotate is run by cron cat /etc/cron.daily/logrotate#!/bin/sh/usr/ sbin/logrotate /etc/logrotate.confexitvalue=$?if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "alert exited abnormally with [$EXITVALUE] "fiexit 0# and logrotate.conf will refer to/ETC/LOGROTATE.D directory cat /etc/logrotate.conf ... INCLUDE /ETC/LOGROTATE.D. Create a new configuration file to handle Nginx log files #在 the/ETC/LOGROTATE.D directory vim /etc/logrotate.d/nginx/opt/ nginx/logs/*.log { daily dateext compress rotate 3 sharedscripts Postrotate if [ -f /opt/nginx/logs/nginx.pid ]; then kill -USR1 ' Cat /opt/nginx/logs/nginx.pid ' &Nbsp; fi endscript}
You can also perform manual execution directly
Logrotate-d-f/etc/logrotate.d/nginx
Log segmentation and scrolling with logrotate