LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-14-2010, 07:18 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Rep: Reputation: 30
how to i clear all my apache log files?


Hey guys i've had my dedicated server for about 16 months now and my log files are huge and I host a few small sites but one of them is quite large and can get a log file (access.log and error.log) of 1-2gb a month so over a year can take up almost 30gb just for that site so I clean them out regularly but I'm wanting a more automated way to do this

i've been thinking of using the find command using something like this but it isn't working

Code:
find /var/www -name "*.log" -type f -size +10M -exec echo > {} /;
any ideas?
 
Old 11-14-2010, 07:29 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You should be able to configure logrotate to maintain the log files.
 
Old 11-14-2010, 07:41 PM   #3
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
ahh... how do i do that?
 
Old 11-14-2010, 07:43 PM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Install the logrotate software from your distribution's software package repository. It will probably already have a default configuration. It generally runs from the system's (root's) crontab files located in the /etc directory. Once it's installed the startup files explain how to customize it.

Most distributions come with logrotate already installed and configured by default. What distribution and version are you using?
 
Old 11-14-2010, 07:46 PM   #5
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Ubuntu server 8.10
 
Old 11-14-2010, 07:48 PM   #6
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You should already have logrotate.
Code:
$ which logrotate
You should see
Code:
$ which logrotate
/usr/sbin/logrotate
Also
Code:
ls -ld /etc/log*
drwxr-xr-x 8 root root  4096 2010-11-04 10:31 /etc/logcheck
-rw-r--r-- 1 root root 10788 2010-01-26 12:09 /etc/login.defs
-rw-r--r-- 1 root root   599 2010-03-06 22:00 /etc/logrotate.conf
drwxr-xr-x 2 root root  4096 2010-11-14 08:33 /etc/logrotate.d
drwxr-xr-x 2 root root  4096 2010-11-04 10:31 /etc/logtool
Here the main configuration file is /etc/logrotate.conf but there are more files in /etc/logrotate.d to make fine tuning adjustments to logrotate's behavior.

Still. I'm surprised that it wasn't automatically running by default when you installed your OS.

Last edited by stress_junkie; 11-14-2010 at 07:51 PM.
 
Old 11-14-2010, 07:50 PM   #7
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
yeah that's the output i have... how do i change the options?
 
Old 11-14-2010, 07:56 PM   #8
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Check to see if logrotate is already in the system's crontab files.
Code:
$ find /etc/cron* -type f -exec grep -H logrotate {} \;
/etc/cron.daily/logrotate:test -x /usr/sbin/logrotate || exit 0
/etc/cron.daily/logrotate:/usr/sbin/logrotate /etc/logrotate.conf
/etc/cron.daily/exim4-base:        logrotate -f /etc/logrotate.d/exim4-paniclog
/etc/cron.monthly/standard:# rotation of wtmp and btmp taken over by logrotate
If it is then it should be running already. Then the question is why isn't it already rotating your http log files. You can see that these crontab files when logrotate will run. Look in /etc/logrotate.d and you will see that there is a separate file for each log file maintained by logrotate.
Code:
$ ls /etc/logrotate.d
apport      cups            jockey-common  rsyslog              wpa_supplicant
apt         dpkg            pm-utils       speech-dispatcher
aptitude    exim4-base      ppp            ufw
atop        exim4-paniclog  psaccs_atop    unattended-upgrades
consolekit  hobbit-client   psaccu_atop    wpa_action
Well, rsyslog has a lot of files listed in it. So each file in /etc/logrotate.d has a list of files for logrotate to maintain.

Last edited by stress_junkie; 11-14-2010 at 08:05 PM.
 
Old 11-14-2010, 08:07 PM   #9
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
my crontab has this:

Quote:
/etc/cron.daily/logrotate:test -x /usr/sbin/logrotate || exit 0
/etc/cron.daily/logrotate:/usr/sbin/logrotate /etc/logrotate.conf
/etc/cron.monthly/standard:# rotation of wtmp and btmp taken over by logrotate
and after looking in /etc/logrotate.d/apache2 i see this line at the top:

Quote:
/var/log/apache2/*.log
and my logs are like this PER site:

/var/www/web1/log/error.log
/var/www/web1/log/web.log

and the web.log is a symlink to year/month/web.log that changes every month so this month it's /var/www/web1/log/2010/11/web.log

and i have 18 sites on this server so web1, web2, web3 etc
 
Old 11-14-2010, 08:15 PM   #10
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I can see a light at the end of this tunnel.

Initially I would just add the full path to this year's web.logs. You can find out later if logrotate will follow a symlink. I imagine it will but I don't know. You could do two or three a day to make it more bearable and to make sure that logrotate doesn't have too much work to do the first time it processes each web site's logs.

I just noticed that you have your OS in your signature. Ooops.

Last edited by stress_junkie; 11-14-2010 at 08:20 PM.
 
Old 11-14-2010, 08:19 PM   #11
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by stress_junkie View Post
Initially I would just add the full path to this year's web.log. You can find out later if logrotate will follow a symlink. I imagine it will but I don't know.
well the problem is there monthly not yearly and there's 18 sites :/

Quote:
Originally Posted by stress_junkie View Post
I just noticed that you have your OS in your signature. Ooops.
hehe lol
 
Old 11-14-2010, 08:29 PM   #12
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by steve51184 View Post
well the problem is there monthly not yearly
Then test it tonight to see if it will follow the symlink. That at least will get this month's log files rotated and it will automatically move to each new month's log files.

Quote:
Originally Posted by steve51184 View Post
and there's 18 sites :/
That wouldn't be a problem if you had done this from the beginning.

I don't think there's any way around the fact that you have some manual maintenance to do for the old log files. Maybe you could do something like this for the old ones
Code:
find /var/www/web* -type f -name *log -exec gzip {} \;
Maybe add a condition in the find command to only do files that are older than 30 days so you don't mess up the current log files.

Mind you logrotate will normally delete old log files so you could just delete old ones yourself instead of compressing them. Log file retention is configurable on a per log basis just in case you never want log files deleted. You don't have to have the old logs compressed either if you'd rather keep them in readable format. You could just have a new log started each day and leave the old log in its normal format and never have any logs deleted.

The more I think about it the more I think that's what you want to do. But logrotate won't split up the old log files. You'd probably want to use something like sed to do that.

Last edited by stress_junkie; 11-14-2010 at 08:41 PM.
 
Old 11-21-2010, 05:46 PM   #13
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
hmm going back to my original idea is there a way i can just blank the log files and not use logrotate?
 
Old 01-12-2011, 01:40 AM   #14
mrhhug
LQ Newbie
 
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
you want to just completly remove log files?

steve51184,

sounds to me like you want to simply remove these log files to free up hard drive space and your running ubuntu with apache; it should be quite easy. I am running maverick and all my error and access logs are in "/var/log/apache2/" . Delete away if you don't want the history of your webserver and just want disk space. You are reporting some serious log sizes, you can change the way apache makes logs if you are interested... If you are deleting these files through some GUI or anything remember to empty the trash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reading apache log files fiona333 Linux - Newbie 1 06-28-2007 01:11 PM
Apache log files ikarus Linux - Server 2 04-21-2007 09:52 PM
script to clear log files kushalkoolwal Programming 8 01-24-2006 07:11 PM
Apache Browser Log Files soulestream Linux - Software 1 12-14-2005 02:59 AM
Help! Clear web.cache and log files on server DogByte Linux - Newbie 1 09-20-2005 06:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration