Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-21-2008, 02:48 AM
|
#1
|
LQ Newbie
Registered: Feb 2008
Posts: 2
Rep:
|
Rotating Apache logs and Webalizer
*edit* - Sorry, could a mod please move to the server forum?
Hi All,
I have a site whose "access_log" file is growing rapidly. I'd like to rotate the logs, but I'm not sure how to do so and still be able to run webalizer. I've googled but didn't find any clear instructions.
I looked at rotate logs (piped from apache), but rather then dumping the old log off as a renamed file and continuing with "access_log", it seems to start logging to the alternatively named file which stops webalizer from working.
I run webalizer once a night as a cron job. Could I simply enter a subsequent command to rename "access_log" and then let apache re-create it?
I'd like to run it past you guys first before I start messing about on a live server!
Cheers,
Andy
(For information, the server is CentOS 5 with Apache 2)
Last edited by xMeta4x; 02-21-2008 at 02:51 AM.
Reason: Posted in wrong forum
|
|
|
02-21-2008, 02:25 PM
|
#2
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
This is my logrotate script for an Apache web server. It runs at midnight, and I set up a cron job to run at 2 minutes after midnight to run webalizer. I just ignore any missed hits during that 2 minute interval. The logrotate script creates a datestamp filename, for which I have other parsers to further analyze the logs.
/etc/logrotate.d/httpd
Code:
/var/log/httpd/*_log {
daily
rotate 368
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
lastaction
yesterday=ac$(date -d yesterday +%y%m%d).log; logdir=/var/log/httpd; mv ${logdir}/access_log.1 ${logdir}/${yesterday}
endscript
}
This runs on a FC5 based host.
--- rod.
|
|
|
02-21-2008, 03:39 PM
|
#3
|
Member
Registered: Jan 2004
Location: East Central Illinois
Distribution: RHEL 4/5/6 and Fedora
Posts: 89
Rep:
|
Hi Andy.
I can't for sure answer the second part of your question, but I'll see if I can help with the first.
In my virtual host section for each of my hosts, I have this for the logging:
Code:
CustomLog "| /usr/sbin/rotatelogs /var/log/httpd/website-access_log.%B 2629800" combined
The %B appends a month name, and the 2629800 is around the normal number of seconds for a month.
This gets me:
website-access_log.January
website-access_log.February
website-access_log.March
Etc., etc.
I use Analog to do stats and in the configuration file when I tell it what log to look at I can use a wildcard and tell it to look in "path/to/logs/website-access_log.*" and it will analyze all of the logs that match as if they were one big file. Again, not sure about webalizer or how it is configured.
Hope that helps (partially, maybe, at least).
Good luck.
G.--
|
|
|
02-22-2008, 01:38 AM
|
#4
|
LQ Newbie
Registered: Feb 2008
Posts: 2
Original Poster
Rep:
|
Thanks for the replies!
I've gotten a little further by using logrotate (not rotatelogs). I run this cron job:
Code:
01 00 * * * root /usr/sbin/logrotate /etc/logrotate.d/httpd
The contents of httpd referenced above is:
Code:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}
This seems to have deleted a file called access_log.1 (which suggests that logrotate has run before) and created one called access_log.2 and emptied access_log.
Whilst this is good, I wouldn't mind saving the old logs! Could I prevent the historic logs from being deleted?
Cheers,
Andy
|
|
|
02-22-2008, 01:51 PM
|
#5
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
Logrotate will do a rolling rotation, moving access_log to access_log.1, access_log.1 to access_log.2, and so on. The good news is that you haven't lost any log files, yet. As soon as logrotate reaches its default depth of file retention, it will drop the oldest log files. The 'lastaction' clause that I put into my logrotate script for httpd renames the log files to a date stamped version outside the domain of logrotate, and are thus retained perpetually. I compress a years worth of log files into one zip file and save them.
--- rod.
|
|
|
03-20-2009, 12:42 AM
|
#6
|
LQ Newbie
Registered: Mar 2009
Posts: 2
Rep:
|
prerotate
add prerotate to the logrotate file
/var/log/httpd/*log {
missingok
rotate 12
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
monthly
mail *********@*****.***
prerotate
webalizer -c /etc/webalizer/webalizer.conf
endscript
}
prerotate will run webalizer then rotate collecting all the data. verify where your webalizer.conf file is... could be /etc/webalizer.conf . This snippet will also rotate them once a month and keep them up for to one year/12 months. it will then compress after the second log has been rotated. the 13th log is also emailed to you before deletion, just add your email address. compression can be important depending on how much traffic and errors. use what you can.
Cheers
|
|
|
All times are GMT -5. The time now is 12:14 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|