0

I have an Apache server (2.2) running in RHEL 6.3, with the following logrotate configuration:

# Rule for Apache logs
/var/opt/apache/logs/*log {
    compress
    missingok
    notifempty
    daily
    rotate 15
    create 0640 www_adm apache
    olddir /var/opt/apache/logs/rotated
    sharedscripts
    postrotate
         /bin/kill -HUP `cat /var/opt/apache/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

# Rule for Apache-Application logs
/var/opt/apache/logs/*/*log /var/opt/apache/logs/*/*/*log {
    daily
    copytruncate
    compress
    missingok
    dateext
    dateformat .%Y-%m-%d
    rotate 90
    create 0640 www_adm apache
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/opt/apache/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}

The cron job it's running daily without issues, but the file's rotation it's not working as expected. I'm getting files with several dates appended instead of just one per day:

mysite-ssl.2015-10-31.2015-11-02.2015-11-04.2015-11-06.2015-11-08.log
mysite-ssl.2015-10-31.2015-11-02.2015-11-04.2015-11-06.2015-11-08.2015-11-10.log
mysite-ssl.error.2015-10-21.2015-10-23.2015-10-25.2015-10-27.2015-10-29.2015-10-31.2015-11-02.2015-11-04.2015-11-06.2015-11-08.log
mysite-ssl.error.2015-10-21.2015-10-23.2015-10-25.2015-10-27.2015-10-29.2015-10-31.2015-11-02.2015-11-04.2015-11-06.2015-11-08.2015-11-10.log
mysite-ssl.2015-11-10.log.gz
mysite.2015-11-10.log.gz
mysite-ssl.2015-10-24.2015-10-26.2015-10-28.2015-10-30.2015-11-01.2015-11-03.2015-11-05.2015-11-07.2015-11-09.log
mysite-ssl.2015-10-24.2015-10-26.2015-10-28.2015-10-30.2015-11-01.2015-11-03.2015-11-05.2015-11-07.2015-11-09.2015-11-11.log
mysite-ssl.2015-11-11.log.gz
mysite.2015-11-11.log.gz

Also it seems the logrotate isn't doing anything more, in the log files (see head/tail):

[user@host mysite]$ head mysite.log ; echo "----------------" ; tail mysite.log
145.245.114.238 - - [11/Nov/2015:03:25:30 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [11/Nov/2015:03:28:07 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [11/Nov/2015:03:30:03 +0100] "HEAD / HTTP/1.1" 301 -
145.245.114.237 - - [11/Nov/2015:03:31:15 +0100] "HEAD / HTTP/1.1" 301 -
145.245.114.237 - - [11/Nov/2015:03:31:15 +0100] "HEAD /mysite HTTP/1.1" 302 -
145.245.114.238 - - [11/Nov/2015:03:31:15 +0100] "HEAD /mysite/index.html HTTP/1.1" 200 -
145.245.114.238 - - [11/Nov/2015:03:31:36 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [11/Nov/2015:03:31:48 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [11/Nov/2015:03:35:28 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [11/Nov/2015:03:38:07 +0100] "GET / HTTP/1.1" 301 306
----------------
145.245.114.238 - - [07/Jan/2016:15:41:36 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [07/Jan/2016:15:44:12 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [07/Jan/2016:15:47:41 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [07/Jan/2016:15:47:57 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [07/Jan/2016:15:51:36 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [07/Jan/2016:15:54:12 +0100] "GET / HTTP/1.1" 301 306
145.245.114.238 - - [07/Jan/2016:15:55:04 +0100] "HEAD / HTTP/1.1" 301 -
145.245.114.237 - - [07/Jan/2016:15:57:41 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [07/Jan/2016:15:57:57 +0100] "GET / HTTP/1.1" 301 306
145.245.114.237 - - [07/Jan/2016:16:01:36 +0100] "GET / HTTP/1.1" 301 306

Any idea what could be the cause of this behaviour? Is my configuration missing something?

2 Answers 2

1

The first line of second block in logrotate config matches files ending with "log".

/var/opt/apache/logs/*/*log /var/opt/apache/logs/*/*/*log {

Normally when you rotate your files and compress them, the extension becomes .gz. This means that the above line will not match any more.

However, you are changing the file extension in the line:

extension .log

This causes your files to be rotated again. You need to remove this line to prevent extension change, or move your rotated files to another folder using olddir as you are doing in the first config block.

1
  • I had that line indeed in one of the nodes, but not in the second one. I've removed it from the main question, but in my case both nodes behave the same (despite one having that line and not the other)
    – Peter
    Jan 7, 2016 at 16:20
0

You are rotating old logfiles to files that have a date and .log appended to the end.

The pattern matching what files to rotate hence also matches the old log files, which get rotated again (so a new date is added, and again .log is appended).

You need to ensure that the old already rotated log files aren't rotated again. You already use a separate directory for rotated log files, but that gets matched by the /var/opt/apache/logs/*/*log pattern in the second stanza.

Usually rotated log files have the date at the very end, to prevent such problems.

1
  • I had that line indeed in one of the nodes, but not in the second one. I've removed it from the main question, but in my case both nodes behave the same (despite one having that line and not the other)
    – Peter
    Jan 7, 2016 at 16:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .