Logrotate about log Polling and segmentation

Source: Internet
Author: User
Tags apache log file apache log

If you are the source package installed services, then for some services on the Linux server in the running of the log is very important to determine if your service is abnormal, etc., but the source package installed log is no log polling or cutting capacity,

So you need to use a bash script to do it or in a different language, but I'm here to introduce the next Rhel series of tools Logrotate he can easily help you realize the polling of the logs. The service is installed by default, such as Rhel and CentOS. You can directly

Edit the/etc/logrotate.conf to enable polling for the corresponding log file:

For example, a typical Apache log,

Preferred me to say the following sub then in detail his parameters:

My compiled and installed Apache is in/usr/local/apache2/logs

Here is a record of all my Apache log files including the virtual host files.

[Email protected] logs]# vi/etc/logrotate.conf # See"Mans Logrotate"  fordetails# rotate log files weekly# see"Mans Logrotate"  fordetails# rotate log files weeklyweekly# keep4weeks worth of backlogsrotate4# CreateNew(empty) log files after rotating old onescreate# use date asa suffix of the rotated filedateext# uncomment This ifwant your log files compressed#compress# RPM packages drop log rotation information into ThisDirectoryinclude/etc/logrotate.d# No packages own wtmp and btmp--We'll rotate them here/var/log/wtmp {Monthly Create0664root utmp minsize 1M rotate1}/var/log/btmp {Missingok monthly Create0600root utmp rotate1}/usr/local/apache2/logs/*_log{daily Create rotate

I added below all the files that end with _log under my Apache log file

This will also take effect whenever I add a new virtual host in the future.

Of course we can use: Logrotate-v/etc/logrotate.conf to see the log configuration that we have in effect now, in which I can finally see I added the Apache log with my virtual host named log file information

If you want your current configuration to take effect, you can use: [[email protected] logs]# logrotate-f/etc/logrotate.conf This can enforce the information in the configuration file. The important note is to try not to use the online server

Configuration Description:

1. Naming rules for logs

If the Dateext parameter is in the configuration file, then the log will use the date as the suffix of the log file, for example: "mail-20150722" to ensure that the log does not overlap. You do not need to rename the log file. You only need to customize the number of files to delete the extra log files.

If the configuration file does not have the Dateext parameter, then the log file needs to be renamed, when the first log rotation, the current log file name will be modified to "log file name." 1 "then regenerate a new file name to record data for the log filename, and so on like a hand." Gun bullets are loaded like bombs, new joins will be the first one that will become the second one in the back and two into three

2. configuration file and the corresponding configuration parameters: (the figure from the network if there are copyright issues can be modified by the message)

Logrotate about log Polling and segmentation

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.