Resolve Apache log file too large

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

When configuring a Web server, we generally record the requested information and the information about the error.

ErrorLog "/home/zhangy/apache/www.test.com-error.log"
Customlog "/home/zhangy/apache/www.test.com-access.log" common

With the above configuration, if you do not delete it regularly, I think these log files can reach several g sizes over time. It is not good for us to view the log information. In fact, access to information, as well as error errors just to help us understand the server access, the operation of the situation, the individual feel as long as the latest on the OK.

Here are 2 ways to solve this problem

1,rotatelogs such log rollback tool

Usage

Rotatelogs [-l] logfile [rotationtime [offset]] | [Filesizem]

- L use local time instead of GMT time as the time datum. Note: using-l in an environment that changes the GMT offset (such as daylight saving time) can lead to unpredictable results.

logfile It plus the reference name is the log file name. If logfile contains "%", it is treated as a format string for strftime (), otherwise it is automatically appended with the ". nnnnnnnnnn" suffix in seconds. Both of these formats indicate when the new log is to be used.

Rotationtime The time interval in seconds that the log file scrolls.

The number of minutes that offset is slack relative to UTC. If omitted, "0" is assumed and UTC time is used. For example, to specify local time for a region that has a UTC difference of "-5 hours", this argument should be "-300".

Filesizem Specifies scrolling in filesizem file size, rather than by time or slack.

Workaround:

ErrorLog "|/usr/local/apache2/bin/rotatelogs/home/zhangy/apache/www.test.com-error.log.%y-%m-%d-%h_%m_%s 10M"
Customlog "|/usr/local/apache/bin/rotatelogs/home/zhangy/apache/www.test.com-access.log 10M" commom

When the log size reaches 10M, the logs are scrolled and new logs are generated. Of course, you can scroll according to time, the 10M to 36000, the table log 10 hours to scroll once.

[Zhangy@blackghost apache]$ ls-tr |grep test
Www.test.com-error.log
Www.test.com-access.log
Www.test.com-error.log.2010-11-05-14_50_00
www.test.com-access.log.1288968528
Www.test.com-error.log.2010-11-05-14_48_20
www.test.com-access.log.1288968677
Www.test.com-error.log.2010-11-05-14_56_40
Www.test.com-error.log.2010-11-05-15_55_00
www.test.com-access.log.1288969444

2, using graceful to start

Restarting with an elegant (graceful) method enables the server to enable new log files without losing information that was not previously written. To do this, it is necessary to wait a period of time for the server to complete the request being processed and to write the record to the original log file. The following is an example of log scrolling and the compression of old logs to conserve storage space, but these logs are also not available to look at individual needs

[Zhangy@blackghost apache]$ Find. -name "*51yip*" |xargs-i mv {} {}.bak
[Zhangy@blackghost apache]$ Sudo/etc/init.d/apache2 Graceful
[Zhangy@blackghost apache]$ sudo sleep 100
[Zhangy@blackghost apache]$ Find. -name "*.bak" |xargs-i tar czvf logbak.tar.gz {}
./www.51yip.com-access.log.bak
./www.51yip.com-error.log.bak

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.