Common configuration parameters for log rotation (logrotate)

Source: Internet
Author: User

Recently just to rearrange the log server, just need to reconfigure the system logrotate, so simply write some basic configuration parameters of Logrotate, for easy access.

Logrotate The main configuration parameter file is/etc/logrotate.conf, and/etc/logrotate.d/directory in the write configuration is for the usual management convenience written inside, it will eventually be/etc/ Logrotate.conf, which is then executed by wtmp. So if it is some common configuration can be written in the/etc/logrotate.conf file, but if it is not recommended to make the default/etc/logrotate.conf file too big changes, as for the configuration syntax in logrotate.conf is very simple:

The Jedi path of the log file name (if multiple spaces are separated) {parameters to be configured}

The most important thing about the Logrotate feature is its configuration parameters, which are listed here for some common parameters:

Parameters
Description
Compress Enable compression, refers to the old log after rotation, where the default is gzip compressed
Compressoptions Compress in gzip-9 mode
Uncompresscmd Unzip the log, default is Gunzip
Daily Rotation options per day
Dateext The rotation log file is appended with the timestamp of the previous dash and YYYYMMDD format
Delaycompress
Defer the previous log file compression until the next rotation
Ifempty Even if the log file is empty, it also turns
Mail Send the post-rotation file to the specified e-mail address
Copytruncate
for log files that are still open, back up and truncate the current log , and start the rotation
Mailfirst/maillast Send a carousel/Post history file to a message (default)
Monthly One-month round-trip
Nocompress If compression is enabled in logrotate.conf, this is done without compressing the parameters
Nomail
Do not send mail to any address
Ifempty If the log time and space is not round
Olddir Directory The post-rotation log file is placed in the specified directory and must be in the same file system as the current log file
Postrotate/endscript
After the rotation of the command, two keywords must be in a separate row, the operation used in 2 is equivalent to grouping "{}", note the use of external directives with absolute path
Prerotate/endscript The order before the rotation, ibid.
Rotate Count The rotation is retained up to the previous data several times, the excess will be deleted or the message received, set to 0 does not save
Size size When the log grows to a specified size, it starts rotation, and it does not consider
Start Count The rotation file name is based on this number.
For example, specify 0 o'clock, the original log file rotation of the backup file with. 0 as the extension, if you specify 9, you skip 0-8 directly from. 9.
The number of times that is specified for rotate is then resumed.
Weekly If the current day of the week is less than the last day of rotation, or after one weeks, the rotation usually takes place on the first days of the week, and if the logrotate is not running daily, it will be replaced on the first occasion.
Yearly Journal rotation If the current year differs from the year of the last rotation
Create Mode owner Group After the Postrotate script executes, the log file is created immediately using the log filename of the new rotation.
MODE Specifies the permissions of the log file (0660, etc.)
Owner Specifies the master of the log file
Group specifies the genus of log files
Extension ext The log file can use the specified ext extension after rotation. If compression is used, the extension of the compressed file is usually added after ext, usually. gz. For example, to convert the Mylog.foo wheel to mylog.1.foo.gz instead of mylog.foo.1.gz.

The common parameters of basic logrotate are these, if you want to know more parameter use method can refer to man 8 logrotate. Of course, now a lot of software has its own logrotate, such as Apache Rotatelogs, and so on, mostly based on the system's logrotate to implement the rotation of the journal, the specific use of the kind to be based on the actual situation, However, the logrotate in the system can almost satisfy most of the scenes

This article from the "Technical essay" blog, reproduced please contact the author!

Common configuration parameters for log rotation (logrotate)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.