I have discovered that my access_log is occupying most of my HDD. It’s over 200 GB in size. How can I reset it ?
I am using Apache 2.2.3 on a CentOS server with Plesk.
Thank you guys !
I have discovered that my access_log is occupying most of my HDD. It’s over 200 GB in size. How can I reset it ?
I am using Apache 2.2.3 on a CentOS server with Plesk.
Thank you guys !
8
Answers
Rename the file to different filename and create new file with the name access_log and restart apache (otherwise apache keeps the lock on the file and don’t “see” the file change)
Use the logrotate daemon in order to have a clean maintenance of your logs, specially, the apache related logs.
A brief info about logrotate: http://www.scriptinstallation.in/logrotate.html
Rename the file, create a new access_log, then restart Apache.
If you have access by SSH to the server, then you can:
1) Gzip the old file (text files compression ratios are really good). If we assume the file is named /var/log/apache/access.log then do this:
gzip -c /var/log/apache/access.log > /var/log/apache/access.log.gz
2) Clear the current file
echo > /var/log/apache/access.log
3) Restart apache
Also as Dez has suggested consider using logrotate for production grade apache log archiving.
knx’answer is good, but I would suggest to rename the log, and create a new one, so that you can restart apache without waiting for the access log to be compressed, which can take a while if it’s big.
needs access to ssh
First, rename the current log file:
Second, create a new log file and give the same permissions, owner/group and selinux context as the original one:
(probably need to be root to do that)
Next, restart apache
Then Gzip the old file (text files compression ratios are really good). If we assume the file is named
/var/log/apache/access.log
then do this:these 4 points are what logrotate do automatically.
If on Ubuntu do:
When creating that access log it magically starts the error log too.
I know this post is ages old, but I just had same problem and no answer covers it correctly.
The point is the apache creates the file as
access_log
, according to its configuration. However, logrotate only looks for*.log
, hence the name does not match the search pattern.Solutions: Either you add
*_log
to logrotate configuration, or change the apache configuration to make it create the log file namedaccess.log
. Changing apache configuration requires apache reload.A simple solution is to disable access_log, commenting only one line on the configuration file.
Source: https://www.mydigitallife.info/how-to-disable-and-turn-off-apache-httpd-access-and-error-log/
For Plesk users:
https://stackoverflow.com/a/41000240/1792240