Logrotate is a log file management tool. Used to rotate, compress, delete, and create new log files for old files. We can be based on the size of log files, days, etc. to dump, easy to log file management, usually through Cron scheduled tasks to complete.
1. Configuring instances
/var/log/messages { rotate 5 weekly postrotate /sbin/killall -HUP syslogd endscript} "/var/log/httpd/access.log" /var/log/httpd/error.log { rotate 5 mail [email protected] size 100k sharedscripts postrotate /sbin/killall -hup httpd endscript} /var/log/ news/* { monthly rotate 2 olddir /var/log/news/old missingok postrotate kill -HUP ' Cat /var/run/inn.pid ' Endscript nOcompress}
2. Configuration option Description
Compress: Dumps old logs with gzip compression
Nocompress: When compression is not required, use this parameter
Copytruncate: For log files that are still open, back up and truncate the current log
Nocopytruncate: Backing up log files but not truncating
Create Mode owner group: Creates a new log file with the specified file mode
Nocreate: Do not create a new log file
Delaycompress: When used with compress, the dump log file is compressed until the next dump
Nodelaycompress: Overwrite delaycompress option, dump simultaneous compression.
Errors Address: Error message sent to the specified email address at the time of the special store
Ifempty: Even empty files are dumped, this is the default option for Logrotate.
Notifempty: If it is an empty file, do not dump
Mail address: Send dump log files to the specified e-mail addresses
Nomail: Do not send log files when dumping
Olddir directory: The dump log file is placed in the specified directory and must be in the same file system as the current log file
Noolddir: The dump log file and the current log file are placed in the same directory
Prerotate/endscript: Commands that need to be executed before dumping can be placed in this pair, these two keywords must be in a separate row
Postrotate/endscript: Commands that need to be executed after the dump can be placed in this pair, these two keywords must be taken separately
Sharedscripts: All log files are rotated once the script is executed uniformly
Daily: Specify a dump cycle of daily
Weekly: Specify a dump cycle of weekly
Monthly: Specify a staging period of monthly
Rotate count: Specifies the number of times a log file was dumped before it was deleted, 0 means no backup, 5 means reserved 5 backups
Size size: Dump when the log file reaches the specified size, size can specify bytes (default) and KB (Sizek) or MB
3. Command parameter Description
# logrotate--help
Usage:logrotate [OPTION ...] <configfile>-D,--debug debug mode, output debug results, do not execute. Implicit-v parameter-F,--force mandatory mode, rotate-m for all related files,--mail=command send mail (instead of '/bin/mail ')-S,--sta Te=statefile state file, useful for running in different user cases-V,--verbose display debug information
Logrotate Log Management tool