nginx-我陷入了logrotate之谜

我有两个logrotate文件:

/etc/logrotate.d/nginx-size

/var/log/nginx/*.log 
/var/log/www/nginx/50x.log

{
    missingok
    rotate 3
    size 2G
    dateext
    compress
    compresscmd /usr/bin/bzip2
    compressoptions -6
    compressext .bz2
    uncompresscmd /usr/bin/bunzip2
    notifempty
    create 640 nginx nginx
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

/etc/logrotate.d/nginx-daily

/var/log/nginx/*.log 
/var/log/www/nginx/50x.log

{
    missingok
    rotate 3
    dateext
    compress
    compresscmd /usr/bin/bzip2
    compressoptions -6
    compressext .bz2
    uncompresscmd /usr/bin/bunzip2
    notifempty
    create 640 nginx nginx
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

命令logrotate -d -v /etc/logrotate.d/nginx-sizeoutput:

reading config file /etc/logrotate.d/nginx-size
compress_prog is now /usr/bin/bzip2
compress_options is now  -6
compress_ext is now .bz2
uncompress_prog is now /usr/bin/bunzip2

Handling 1 logs

rotating pattern: /var/log/nginx/*.log 
/var/log/www/nginx/50x.log

 2147483648 bytes (3 rotations)
empty log files are not rotated,old logs are removed
considering log /var/log/nginx/access.log
  log does not need rotating
considering log /var/log/nginx/error.log
  log does not need rotating
considering log /var/log/nginx/get.access.log
  log does not need rotating
considering log /var/log/nginx/post.access.log
  log needs rotating
considering log /var/log/www/nginx/50x.log
  log does not need rotating
rotating log /var/log/nginx/post.access.log,log->rotateCount is 3
dateext suffix '-20141204'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/log/nginx/post.access.log to /var/log/nginx/post.access.log-20141204
creating new /var/log/nginx/post.access.log mode = 0640 uid = 497 gid = 497
running postrotate script
running script with arg /var/log/nginx/*.log 
/var/log/www/nginx/50x.log

: "
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
"
compressing log with: /usr/bin/bzip2

每天在ngnix上输出相同(正常)的输出.

如果我从root命令运行

logrotate -f /etc/logrotate.d/nginx-size 

手动完成所有事情.但!它不会自动运行!

contab:

*/5 5-23 * * * root logrotate -f -v /etc/logrotate.d/nginx-size 2>&1 > /tmp/logrotate_size   
00 04 * * * root logrotate -f -v /etc/logrotate.d/nginx-daily 2>&1 > /tmp/logrotate_daily

另外,文件/ tmp / logrotate_daily& / tmp / logrotate_size始终为空.

Cron在/ var / log / cron中没有给我任何错误

Dec  4 14:45:01 (root) CMD (logrotate -f -v /etc/logrotate.d/nginx-rz-size 2>&1 > /tmp/logrotate_size   )
Dec  4 14:50:01 (root) CMD (logrotate -f -v /etc/logrotate.d/nginx-rz-size 2>&1 > /tmp/logrotate_size   )

dat事情怎么了?.. Centos 6.5 x86_64,Logrotate版本3.8.7(源代码外)logrotate版本3.7.8(通过rpm).

提前谢谢.

最佳答案
您的重定向在这些cron行中不正确.他们不会将错误信息输出到那些文件.

重定向顺序很重要.您想要> / tmp / logrotate_size 2>& 1获得所需的内容.

这里的根本问题是信息页面的“调试crontab”部分涵盖的内容之一.

即“对环境做出假设”.

Making assumptions about the environment

Graphical programs (X11 apps),java programs,ssh and sudo are notoriously problematic to run as cron jobs. This is because they rely on things from interactive environments that may not be present in cron’s environment.

To more closely model cron’s environment interactively,run

env -i sh -c ‘yourcommand’

This will clear all environment variables and run sh which may be more meager in features that your current shell.

Common problems uncovered this way:

foo: Command not found or just foo: not found.

Most likely $PATH is set in your .bashrc or similar interactive init file. Try specifying all commands by full path (or put source ~/.bashrc at the start of the script you’re trying to run).

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...