Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access_log is huge, not being archived. how to reset it?

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 !

like image 699
user290367 Avatar asked May 14 '10 08:05

user290367


People also ask

Can I delete Apache access log?

If in use, deleting the log will make apache reload to re-open the just deleted file. What you can try is indeed logrotate, or try to empty the file.


1 Answers

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:

mv /var/log/apache/access.log /var/log/apache/access.log.1

Second, create a new log file and give the same permissions, owner/group and selinux context as the original one:

touch /var/log/apache/access.log
chown --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
chmod --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
restorecon --reference=/var/log/apache/access.log.1 /var/log/apache/access.log

(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:

gzip -c /var/log/apache/access.log.1 > /var/log/apache/access.log.1.gz

these 4 points are what logrotate do automatically.

like image 198
Thomas B in BDX Avatar answered Sep 29 '22 12:09

Thomas B in BDX