Nginx I';我陷入了困境

Nginx I';我陷入了困境,nginx,cron,centos,logrotate,Nginx,Cron,Centos,Logrotate,我有两个日志文件: /etc/logrotate.d/nginx大小 /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/b

我有两个日志文件:

/etc/logrotate.d/nginx大小

/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 size
输出:

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 
手动,它可以完成所有的事情。但是它不会自动运行它

续:

*/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\u daily和/tmp/logrotate\u 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   )
这东西怎么了?。。Centos 6.5 x86_64,Logrotate版本3.8.7(源代码外)+Logrotate版本3.7.8(通过rpm)


Thx提前

这些cron行中的重定向不正确。它们不会向这些文件输出错误信息

重定向命令很重要。您希望
/tmp/logrotate\u size 2>&1
获得您想要的

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

即“对环境做出假设”

对环境做出假设

众所周知,图形程序(X11应用程序)、java程序、ssh和sudo作为cron作业运行存在问题。这是因为它们依赖于交互环境中可能不在cron环境中的东西

要以交互方式更紧密地建模cron的环境,请运行

env-i sh-c“yourcommand”

这将清除所有环境变量并运行sh,它可能比您当前shell的功能更加贫乏

通过这种方式发现的常见问题:

未找到foo:命令或仅找到foo:未找到

最有可能的$PATH是在.bashrc或类似的交互式init文件中设置的。尝试按完整路径指定所有命令(或将source~/.bashrc放在您尝试运行的脚本的开头)


这些行中的重定向不正确。它们不会向这些文件输出错误信息。重定向命令很重要。您需要
/tmp/logrotate\u size 2>&1
。你在cron条目中尝试过logrotate的完整路径吗?不,我不,我现在就做ffs,m8,u r我的saver)thx很多,我甚至不认为用那种方式添加你的答案,所以我会把它标记为正确的,plz