gpt4 book ai didi

nginx - 我陷入了 logrotate 之谜

转载 作者:太空宇宙 更新时间:2023-11-03 17:14:37 25 4
gpt4 key购买 nike

我有两个 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-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-daily 上的相同(正常)输出..

如果我从 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_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 )

那个东西有什么问题?.. 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).

关于nginx - 我陷入了 logrotate 之谜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27297024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com