logrotate 不旋转 catalina.out [英] logrotate doesn't rotate catalina.out

查看:26
本文介绍了logrotate 不旋转 catalina.out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每天都在尝试使用 logrotate 自动轮换 tomcat 的 catalina.out,即使我可以手动调用 logrotate 并且它工作正常.我正在使用我已经尝试了所有解决方案,但我无法让它旋转.我使用的是 Oracle Linux 7.5,它基本上是 RHEL 7.

I am trying to use logrotate to rotate out tomcat's catalina.out automatically on a daily basis even though I can manually call logrotate and it works fine. I am using I have tried every solution out there, but I cannot get it to rotate. I am on Oracle Linux 7.5 which is basically RHEL 7.

以下是我采取的步骤:

我创建了一个文件/etc/logrotate.d/tomee.conf,如下所示:

I created a file /etc/logrotate.d/tomee.conf that looks like this:

    /apache-tomee-plus-7.0.4/logs/catalina.out
    {
        su opc opc
        daily
        rotate 7
        compress
        notifempty
        missingok
        copytruncate
    }

我可以手动执行 logrotate,使用 sudo/usr/sbin/logrotate/etc/logrotate.conf

I can manually execute the logrotate and it works just fine using sudo /usr/sbin/logrotate /etc/logrotate.conf

我也尝试使用 sudo/usr/sbin/logrotate -d/etc/logrotate.conf 进行调试,并且输出没有错误

I also attempt to debug using sudo /usr/sbin/logrotate -d /etc/logrotate.conf and the output has no errors

    ...
    rotating pattern: /apache-tomee-plus-7.0.4/logs/catalina.out
     after 1 days (7 rotations)
    empty log files are not rotated, old logs are removed
    switching euid to 1000 and egid to 1000
    considering log /apache-tomee-plus-7.0.4/logs/catalina.out
      log needs rotating
    rotating log /apache-tomee-plus-7.0.4/logs/catalina.out, log->rotateCount is 7
    dateext suffix '-20181211'
    glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    copying /apache-tomee-plus-7.0.4/logs/catalina.out to /apache-tomee-plus-7.0.4/logs/catalina.out-20181211
    truncating /apache-tomee-plus-7.0.4/logs/catalina.out
    compressing log with: /bin/gzip
    switching euid to 0 and egid to 0
    ...

但它仍然不会每天自动执行.

But it still doesn't do it automatically daily.

我也知道 logrotate 正在运行,因为根据 /var/lib/logrotate/logrotate.status,其他日志正在旋转,但没有 catalina.out

I also know that logrotate is running because according to /var/lib/logrotate/logrotate.status, other logs are being rotated, but not catalina.out

    cat /var/lib/logrotate/logrotate.status
    logrotate state -- version 2
    "/var/log/yum.log" 2018-11-29-18:44:14
    "/var/log/up2date" 2018-9-17-19:0:0
    "/apache-tomee-plus-7.0.4/logs/catalina.out" 2018-12-8-0:37:14
    "/var/log/chrony/*.log" 2018-9-17-19:0:0
    "/var/log/wtmp" 2018-12-3-17:48:49
    "/var/log/spooler" 2018-11-29-18:44:14
    "/var/log/btmp" 2018-12-3-17:48:49
    "/var/log/iscsiuio.log" 2018-9-17-19:0:0
    "/var/log/maillog" 2018-12-11-3:7:1
    "/var/log/secure" 2018-12-11-3:7:1
    "/var/log/messages" 2018-12-11-3:7:1
    "/var/account/pacct" 2018-9-17-19:0:0
    "/var/log/cron" 2018-12-11-3:7:1

请注意,有多个条目表示它在 12-11 日轮换,但 catalina.out 从 12-8 日起没有轮换,但仍然没有轮换.

notice that there are multiple entries that say it was rotated on 12-11, but catalina.out wasn't rotated since 12-8, but it still isn't rotating.

非常感谢任何帮助.谢谢.

Any help is greatly appreciated. Thanks.

推荐答案

由于这个问题获得了很多意见,我会告诉大家我找到的解决方案.

Since this is getting a lot of views, I will let you all know the solution I found.

我无法让 logrotate 在 catalina.out 上工作,很抱歉,如果这就是您要找的东西.

I could not get logrotate to work on catalina.out, so sorry if that's what you're looking for.

我能够做的是阻止 catalina.out 生成.为此,我在 apache-tomee-plus-7.0.4/bin 中创建了一个名为 setenv.sh 的文件,并将这一行放入其中

What I was able to do is stop catalina.out from ever getting generated. To do this, I created a file called setenv.sh in apache-tomee-plus-7.0.4/bin, and put this line in it

export CATALINA_OUT="/dev/null"

当 tomee 启动时,它在 catalina.sh 中看起来像这样

When tomee is started up, it looks something like this in catalina.sh

eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
  -classpath "\"$CLASSPATH\"" \
  -Djava.security.manager \
  -Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
  -Dcatalina.base="\"$CATALINA_BASE\"" \
  -Dcatalina.home="\"$CATALINA_HOME\"" \
  -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
  org.apache.catalina.startup.Bootstrap "$@" start \
  >> "$CATALINA_OUT" 2>&1 "&"

所以输出到文件似乎有必要在后台运行这个 tomee.输出到/dev/null 让它在某处输出,但它无处可去

so outputting to a file seems necessary to run this tomee in the background. outputting to /dev/null lets it output somewhere, but it just goes nowhere

这篇关于logrotate 不旋转 catalina.out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆