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.
|
 |
11-09-2004, 01:49 PM
|
#1
|
LQ Newbie
Registered: Nov 2004
Posts: 4
Rep:
|
Correct configuration for Apache2 and logrotate
Hi all,
I have been asked to configure logrotate for a specific customer on our server. The server hosts many virtual hosts and most dont have logging enabled (dont ask me why - I am just doing as I am told).
Anyway, the one that does, happens to generate large logs which is causing a problem.
I have looked at the logrotate.d/httpd file and think this is where I need to start. I am however a bit lost and wondered if anyone can help.
From what I can gather, adding the following should be correct:
/home/ovpw/logs/* {
missingok
notifempty
sharedscripts
monthly
rotate 4
create
compress
postrotate
/usr/sbin/apachectl graceful
endscript
}
My questions are: is the /usr/sbin/apachectl graceful correct ? The other entry in there uses: /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
This looks a bit cumbersome to me.
Which of the two should I use ?
This should (If I have it right) keep 4 months of logs which will be compressed, rotating them monthly. It should also restart apache to ensure the logs are re-created..
Can I do this, and just add more blocks for each directory that I want to rotate (for example, if I need to do this for more Vhosts, do they go in this same file?) ?
Do I need to restart anything to make this lot work, or will it all just work as expected when cron.daily next kicks off logrotate ?
Thanks for any help
Rich
|
|
|
11-16-2004, 04:05 PM
|
#2
|
Member
Registered: Mar 2004
Posts: 41
Rep:
|
If you use a wildcard this way, make sure you rotate the logs into a different directory with the olddir option. Otherwise, you'll end up re-rotating old logs. Example:
Code:
olddir /home/archive
Quote:
My questions are: is the /usr/sbin/apachectl graceful correct ? The other entry in there uses: /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
|
Yes, use apachectl graceful. You do not need to send SIGHUP manually using kill. Apachectl graceful will properly send SIGUSR1, which will (among other things) cause httpd to re-open its log files.
Quote:
This should (If I have it right) keep 4 months of logs which will be compressed, rotating them monthly. It should also restart apache to ensure the logs are re-created
|
Correct. You will have, e.g.:
Code:
access_log <-- this month
access_log.1.gz <-- last month
access_log.2.gz <-- 2 months ago, etc...
access_log.3.gz
access_log.4.gz
Quote:
Can I do this, and just add more blocks for each directory that I want to rotate (for example, if I need to do this for more Vhosts, do they go in this same file?) ?
|
You can add more blocks to the same file, but if you are going to specify all the same options, you can just add more log files to the existing block:
Code:
/home/ovpw/logs/* /home/anotherdir/logs/* /var/log/apache2/access_log {
olddir /home/archive
missingok
notifempty
sharedscripts
monthly
rotate 4
create
compress
postrotate
/usr/sbin/apachectl graceful
endscript
}
Quote:
Do I need to restart anything to make this lot work, or will it all just work as expected when cron.daily next kicks off logrotate ?
|
As long as cron.daily kicks off logrotate, you're done. However, I would test your logrotate config first to make sure it runs as expected. Use debug mode to see what will happen without actually rotating any files or modifying internal logrotate state. E.g. If the script you made is /etc/logrotate.d/apache:
Code:
logrotate -d /etc/logrotate.d/apache
Last edited by mgatny; 11-16-2004 at 04:06 PM.
|
|
|
11-17-2004, 12:43 PM
|
#3
|
LQ Newbie
Registered: Nov 2004
Posts: 4
Original Poster
Rep:
|
Wow.
Thanks for such a comprehensive, and meaningful reply.
Everything is clear except one point which has me a bit lost.
Where you say I need the olddir entry to prevent re-rotating old logs.
If I look at the default config from /etc/logrotate.d/httpd, it has the following entry:
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}
This results in /var/log/httpd/ containing:
access_log
access_log.1
access_log.2
access_log.3
This setup works (as I would expect) without using "olddir"
What I am hoping for, is to have (after 4 months of rotations)
/home/ovpw/logs/access_log
/home/ovpw/logs/access_log.1.gz
/home/ovpw/logs/access_log.2.gz
/home/ovpw/logs/access_log.3.gz
Then after the next month, to have .1.gz moved to .2.gz, .2.gz moved to .3.gz and .3.gz removed.
If I am being stupid here, please point out where I am wrong.
Thanks for all input
|
|
|
11-17-2004, 02:51 PM
|
#4
|
Member
Registered: Mar 2004
Posts: 41
Rep:
|
Yes, this will work for standard apache log names, without 'olddir'.
The reason is that '*log' will not match your old log names, which end in .1, .2, .gz, and so on. However, the '*' that you specified in you original post will match your old log names, so you need to put your old logs in some other directory to prevent re-rotation.
So:
If '*log' sufficiently matches all log names in the log directory, go ahead and use it without 'olddir'.
However, if you need to use '*' to sufficiently match all log names (e.g. because some of them have names that end in something other than 'log'), use 'olddir' to put old logs into some other directory.
|
|
|
11-18-2004, 12:22 PM
|
#5
|
LQ Newbie
Registered: Nov 2004
Posts: 4
Original Poster
Rep:
|
Right that makes sense.
Thanks for the replies - all is as I wanted now.
Cheers
Rich
|
|
|
All times are GMT -5. The time now is 08:35 AM.
|
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
|
|