Detailed description of how to restrict the access. log Size of apache log Files

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

Today, I found that the disk D on my server is out of space. It's strange that there is no space of GB and I have installed an apache. How can I find that there is an access in the principle. the log file has a memory GB, Baidu access. log is an apache log File and is deleted decisively. In order to avoid such problems, I have summarized some methods to limit the size of apache log Files. Let's take a look.

Use the rotatelogs tool that comes with apache

Syntax:

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

Parameter description:

-L: Use the local time instead of the GMT time as the time benchmark. Note: Using-l in an environment that changes the GMT offset (for example, when the GMT offset is changed) may lead to unpredictable results.
Logfile: the benchmark name is the log file name. If logfile contains "%", it will be considered as a string in strftime () format; otherwise, it will be automatically added as a single

The suffix of ". nnnnnnnnnn. Both formats indicate the start time of the new log.
Rotationtime: The interval in seconds when the log file is rolled.
Offset: the minute of the time difference relative to UTC. If it is omitted, it is assumed to be "0" and UTC time is used. For example, to specify the local time of the area with the UTC time difference of "-5 hours", this parameter

-300 ″.

FilesizeM: Specifies to scroll by filesizeM file size, rather than by time or time difference.

Example:
1. Scroll log files by Time:

The Code is as follows: Copy code


Error Log: ErrorLog "|/data/apache/bin/rotatelogs log storage directory/% Y % m % d_error.log 86400 480 ″
Access log: CustomLog "|/data/apache/bin/rotatelogs log storage directory/% Y % m % d_access.log 86400 480" common

Where:

/Data/apache: the installation directory of apache, determined according to your actual situation;
86400: seconds, 24 hours, indicates that the generated log file is scrolled every day, that is, a log file is generated every day;
480: minute, Time Offset.
Similarly, you can scroll the log file by hour, every hour, several hours... Generate a log file.

Extension: you can write a script to delete log files on a regular basis. logs are retained for only a few days. If the website traffic volume is large, a log file containing dozens or even hundreds of MB is generated in a day, it occupies both hard disks and affects server performance.

2. Scroll the log file by size:

The Code is as follows: Copy code

Error Log: ErrorLog "|/data/apache/bin/rotatelogs-l log storage directory/% Y % m % d_error.log 5 MB"
Access log: CustomLog "|/data/apache/bin/rotatelogs-l log storage directory/% Y % m % d_access.log 5 m" common

When the log file reaches 5 MB, It is rolled.

An example of setting in Windows is as follows:

The Code is as follows: Copy code

 
# Restrict the error log file to 1 MB

ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 1 M"

# Generate an error log file every day

# ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400"

# Restrict access log files to 1 MB

CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1 M" common

# Generate an access log file every day

# CustomLog "| bin/rotatelogs.exe-l log/access-% Y-% m-% d. log 86400" common

An example of setting in Linux is as follows:

The Code is as follows: Copy code

# Restrict the error log file to 1 MB

ErrorLog "|/server/apache/bin/rotatelogs/server/apache/logs/error-% Y-% m-% d. log 1 M"

# Generate an error log file every day

ErrorLog "|/server/apache/bin/rotatelogs/server/apache/logs/error-% Y-% m-% d. log 86400"

# Restrict access log files to 1 MB

CustomLog "|/server/apache/bin/rotatelogs/server/apache/logs/access-% Y-% m-% d. log 1 M" common

# Generate an access log file every day

CustomLog "|/server/apache/bin/rotatelogs/server/apache/logs/access-% Y-% m-% d. log 86400" common

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.