LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 11-09-2004, 01:49 PM   #1
ricur
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Rep: Reputation: 0
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
 
Old 11-16-2004, 04:05 PM   #2
mgatny
Member
 
Registered: Mar 2004
Posts: 41

Rep: Reputation: 15
Quote:
/home/ovpw/logs/* {
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.
 
Old 11-17-2004, 12:43 PM   #3
ricur
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 11-17-2004, 02:51 PM   #4
mgatny
Member
 
Registered: Mar 2004
Posts: 41

Rep: Reputation: 15
Quote:
/var/log/httpd/*log {
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.
 
Old 11-18-2004, 12:22 PM   #5
ricur
LQ Newbie
 
Registered: Nov 2004
Posts: 4

Original Poster
Rep: Reputation: 0
Right that makes sense.

Thanks for the replies - all is as I wanted now.

Cheers

Rich
 
  


Reply



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
Apache2.0.52, t1lib-5.0.2, php-apache2-5.0.2 wizard7423 Slackware 2 04-04-2011 08:09 PM
Apache2 apache2-common WebDav timgerr Linux - Networking 1 08-25-2005 09:41 PM
selecting the correct chipset on kernel configuration ttilt Linux - Software 5 11-28-2004 03:28 PM
how to uninstall apache2 which is installed by emerge apache2 flybirdlong Linux - Software 1 07-17-2004 11:46 AM
apache2 configuration e1000 Linux - Networking 1 01-27-2004 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:13 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