Kiw*_*iwy 186
logrotate使用crontab工作。它是预定的工作,而不是守护进程,因此无需重新加载其配置。
当crontab执行logrotate时,会自动使用新的配置文件。
如果您需要测试您的配置,您也可以logrotate使用以下命令自行执行:
logrotate /etc/logrotate.d/your-logrotate-config
Run Code Online (Sandbox Code Playgroud)
或者如评论中所述,识别参考slm 的答案以获得精确的 cron.daily 解释logrotate命令输出中的crontab -l行并执行命令行
slm*_*slm 46
logrotate我在各种发行版上看到的大多数设置都用完了/etc/cron.daily. 那里有一个名为logrotate.
$ ls -l /etc/cron.daily/logrotate
-rwxr-xr-x 1 root root 180 May 18 2011 /etc/cron.daily/logrotate
Run Code Online (Sandbox Code Playgroud)
如果你想让它手动运行,只需以 root 身份运行脚本:
$ sudo /etc/cron.daily/logrotate
Run Code Online (Sandbox Code Playgroud)
如果您查看通常存在的脚本,它会向您展示如何logrotate手动运行,只需运行logrotate+ 其配置文件的路径即可。
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
Run Code Online (Sandbox Code Playgroud)
小智 40
它应该是通过 cron 自动完成的。您可以强制它测试您的更改。
对于全局 logrotate:
sudo logrotate -v -f /etc/logrotate.conf
Run Code Online (Sandbox Code Playgroud)
对于单个 conf 文件:
sudo logrotate -v -f /etc/logrotate.d/someapp.conf
Run Code Online (Sandbox Code Playgroud)
小智 6
在我的 CentOS 6.5 机器上为 nginx 设置 logrotate 我必须这样做:
logrotate /etc/logrotate.d/nginx
Run Code Online (Sandbox Code Playgroud)
然后我检查 logrotate 是否像这样处理我的新 nginx 配置:
cat /var/lib/logrotate.status
Run Code Online (Sandbox Code Playgroud)