Using logrotate to implement log switching under Linux

The methods are as follows:
1. Create a rotation configuration file:

#vi /etc/logrotate.d/app_name
/home/admin/app_name/logs/access_log
{
daily
dateext
copytruncate
nocompress
rotate 15
}
// /home/admin/app_name/logs/access_log Indicates the absolute path of the log file
// daily means that the log is rotated once a day
// dateext means that the switched log file will be appended with a dash and a date in YYYYMMDD format, if there is no such configuration item, a decimal point and a numeric serial number will be appended
// copytruncate means empty the log file after copying the current log file; instead of renaming the current log file and creating a new one
// nocompress means not compressing the switched log file
// rotate 15 means saving 15 old logs File
// For more configuration, please refer to the man logrotate manual.


2. Restart the syslogd service (or syslog-ng)

service syslogd restart
/usr/bin/killall -HUP syslogd
service syslog-ng restart
/usr/bin/killall -HUP syslog-ng

3. Test (execute the configuration file to force a log rotation):

logrotate -f /etc/logrotate.d/app_name

4. Extend other log switching operations:

#ls /etc/logrotate.d/
acpid conman cups httpd mgetty ppp psacct rpm samba sa-update setroubleshoot snmpd syslog-ng tsar up2date
# Switch logs for a configuration:
logrotate -f config_name
# Force switch all configurations:
logrotate -f /etc/logrotate.conf

from the Internet

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327038365&siteId=291194637