Logrotate configuration automation log management in linux

Source: Internet
Author: User
Logrotate is Logrotate as its name implies, that is, log rotation. Logrotate is a log loop program in the Linux system. Its execution program is located in the directory usrsbinlogrotate. It is a program dedicated to the round robin of various system logs (syslogd, mail. This program is run by the itinerary

LogrotateConfiguration

Logrotate, as its name implies, is log rotate, that is, log rotation. Logrotate is a log loop program in the Linux system. Its execution program is located in the directory/usr/sbin/logrotate, which is dedicated to various system logs (syslogd, mail) the Program for Round Robin. The program is run by the program running service crond at every day (you can look back and see that the start time of some logs in the second above is, Sorry, here we test server in Shenzhen earlier than the actual time, ^ _ ^), can be in/etc/cron. the logrotate file is displayed in the daily directory.

Logrotate is used to delete the old log file and create a new log file, called a "dump ".

We can dump logs based on the log file size or the number of days (for example, the previous example is a one-week dump ). The logrotate program can also be usedCompressionLog File, and send the log to the specified email.

 

The logrotate configuration file is/etc/logrotate. conf. The main parameters are as follows:
CompressGZipCompressing logs after dumping
This parameter is used when nocompress does not require compression.
CopyTrUNcAte is used to back up and truncate the current log file that is still being opened.
NocopytrunCatE. Back up log files without Truncation
Create mode owner group dump file, create a new log file using the specified file mode
Nocreate does not create a new Log File
When delaycompress and compress are used together, the dumped log files are compressed only when they are transferred to the next dump.
Nodelaycompress overwrites the delaycompress option, and the dump is compressed at the same time.
ErrorsDdThe error message sent to the specified Email address during ress special storage
Ifempty dumps even empty files. This is the default logrotate option.
Notifempty is not dumped if it is an empty file
Mail address sends the dumped log file to the specified E-mail address
Do not send log files when nomail dump
The log file after the olddir directory is dumped is placed in the specified directory and must be in the same file system as the current log file.
The log file after noolddir dumping and the current log file are placed in the same directory
Prerotate/endscript to be executed before dumpingCommandYou can put this pair. These two keywords must be entered separately.
Postrotate/endscript can be placed into this pair of commands to be executed after the dump. These two keywords must be entered separately.
Daily indicates that the dump cycle is daily.
Weekly indicates that the dump cycle is weekly.
Monthly specifies the dump cycle as per month
Rotate count indicates the number of dump times before the log file is deleted. 0 indicates no backup, and 5 indicates five backups are retained.
TabootExT [+] list so that logrotate does not dump files with the specified extension. The default extension is. rpm-orig,. rpmsave, v, and ~
Size: dump a log file only when it reaches the specified Size. size can specify bytes (default), KB (sizek), or MB (sizem ).

 

 

 

 

 

4. DefaultLogrotateConfiguration .
The default logrotate configuration file/etc/logrotate. conf.
REdBy default, the following files are installed on Hat Linux:

 

 

The default configuration is generally placed at the beginning of the logrotate. conf file, affecting the entire system. In this example, the first 12 rows are displayed.

WeeklySpecifies that all log files are dumped once a week.Rotate 4Specify four copies of the dump file.
Errors rootSend the specified error message to the root user.
CreateSpecify logrotate to automatically create a new log file. The new log file has the same permissions as the original file.
# CompressSpecifies not to compress the dump file. If compression is required, remove the comment.

Include /Etc/logrotate. dTell logrotate to read the log dump parameters stored in the/etc/logrotate. d directory. It is very useful to use the include option when the RPM package is installed in the system. The log dump parameters of the RPM package are generally stored in the/etc/logrotate. d directory. The include option is very important. Some applications store the log dump parameter in/etc/logrotate. d. Typical applications include apache, linuxconf, samba, cron, and syslog. In this way, the system administrator only needs to manage a/etc/logrotate. conf file.

 

 

 

 

 

5.LogrotateRunning .

 

1. Determine the System Log File, establish the dump plan and parameters, and run the following code through cron daemon: Red Hat Linux defaultCrontabTo run logrotate every day.

#/Etc/cron. daily/logrotate (that is, the daily running content of/etc/cron. daily/logrotate is as follows)

#! /Bin/sh

/Usr/sbin/logrotate/etc/logrotate. conf

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.