How to limit the Apache log file size (error. log, access. log)

Source: Internet
Author: User
Tags apache error log apache log file mongodb postgresql redis apache log mysql database

How to delete error. log, access. log files and methods to limit the size of Apache log files. log and error. the log file has never been moved. Today, a MYSQL database connection error occurs in wordpress, and error 2003 is returned. log, access. the log is too big, and the file has 30 GB. The following is the deletion error found on the Internet. log, access. log File method.

Delete the error. log and access. log files in Windows:

Delete the error. log and access. log files in the Apache2/logs/directory.

Open the httpd. conf configuration file of Apache and find the following two configurations:

ErrorLog logs/error. log
CustomLog logs/access. log common

Directly Comment out and replace it with the following configuration file.
# Restrict Apache error log files to 1 MB
ErrorLog "| bin/rotatelogs.exe-l logs/www.111cn.net _ error-% Y-% m-% d. log 1 MB"

# Generating error log files every day
# ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400 & Prime;

# Restrict access log file size to 1 MB
CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1M 1M" common

# Generate an access log file every day
# CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 86400 & Prime; common

Refer:

Solutions for access. log and error. log files under Apache

Two log files under Apache2 are very large, and the total size is MB.
They are access. log and error. log.

I found access. log and error. log methods to lose weight on the internet. This method allows the two files to be generated on a daily basis. In this way, you can delete the old file.

In the httpd. conf configuration file under Apache, find the following:

ErrorLog logs/error. log

CustomLog logs/access. log common

Change the two sentences as follows:

CustomLog "| D:/apache2/bin/rotatelogs.exe D:/apache2/logs/access _ % Y _ % m _ % d. log 86400 480 & Prime; common

ErrorLog "| D:/apache2/bin/rotatelogs.exe D:/apache2/logs/error _ % Y _ % m _ % d. log 86400 480 & Prime;

Everything is so simple, so that these two log files will start a new file every day, so that a single file will not be too large and cannot be opened, and the log information cannot be seen. you can also delete the preceding log file.

Access. after running log on the WEB server for a long time, it may reach dozens or hundreds of megabytes. If an error occurs during Apache running, the error occurs. the log size will also increase to dozens of megabytes. It is very memory-consuming for the system to read and write a large text file. Therefore, it is necessary to limit the log file size. By referring to the http://httpd.apache.org/docs/2.0/programs/rotatelogs.html, you can use apache's own program rotatelogs.exe (located under the {$ apache}/bin/directory) to limit the size of the log file.
Usage: rotatelogs [-l] [offset minutes from UTC] or
Add this:
TransferLog "| rotatelogs/some/where 86400 & Prime;
Or
TransferLog "| rotatelogs/some/where 5M"
To httpd. conf. the generated name will www.111cn.net be/some/where. nnnn where nnnn is the system time at which the log nominally starts (N. b. if using a rotation time, the time will always be a multiple of the rotation time, so you can synchronizecron scripts with it ). at the end of each rotation time or when the file size is reached a new log is started.
An example of setting in Windows is as follows:
# Restrict the error log file to 1 MB
ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 1M"
# Generate an error log file every day
# ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400 & Prime;
# Restrict access log files to 1 MB
CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1M 1M" common
# Generate an access log file every day
# CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 86400 & Prime; common
It should be similar in linux/Unix.
How to clear apache access. log

The server was built using apache. Recently, the website was always very slow, the server was very slow, and sometimes even the website could not be opened. After investigation and analysis, it turned out to be access in it. log and error. log files should be read and cleared frequently. If you are busy and forget to read and clean them up, the two files will expand very large in a short time, it cannot be opened. The following describes how to clean the access. log and error. log files. I suspect there are other crawlers. I will be crawling several of my websites tomorrow.
The methods to optimize access. log and error. log are as follows:
CustomLog "| D:/thridparty-system/java/apache2/bin/rotatelogs.exe D: /thridparty-system/java/apache2/logs/access _ % Y _ % m _ % d. log 86400 480 & Prime; common
ErrorLog "| D:/thridparty-system/java/apache2/bin/rotatelogs.exe D: /thridparty-system/java/apache2/logs/error _ % Y _ % m _ % d. log 86400 480 & Prime;
Everything is so simple, so that these two log files will start a new file every day, so that a single file will not be too large and cannot be opened, and the log information cannot be seen.

A solution to the increasingly expanding ACCESS. LOG of Apache LOG files

Change customlog logs/access. log common in httpd. conf

Customlog "| c:/apache/bin/rotatelogs c:/apache/logs/% y _ % m _ % d. access. log 86400 480 & Prime; common

Restart apache

C:/apache/is the path to install apache.
In this way, a log file is generated every day.

A solution to the increasingly expanding ACCESS. LOG of Apache LOG files

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.