我在“logrotate.d”目录中增加了两个脚本进行旋转我的应用程序日志。 这是其中的一种配置:
<myLogFilePath> {
compress
copytruncate
delaycompress
dateext
missingok
notifempty
daily
rotate 30
}
有一个在“cron.daily”目录下的“logrotate的”脚本(这似乎是按照cron的日志,每天运行):
#!/bin/sh
echo "logrotate_test" >>/tmp/logrotate_test
#/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
/usr/sbin/logrotate -v /etc/logrotate.conf &>>/root/logrotate_error
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
第一个echo语句工作。
但我发现我的应用程序单独的日志没有得到旋转,而其他日志像httpd越来越旋转**
**而且我也没有看到在提到“logrotate_error”文件中的任何输出 (有写权限的所有用户)。
然而,系统日志说:“日志轮播:警惕以异常退出[1]”
但是,当我手动运行在“cron.daily”脚本相同的“logrotate的”,一切似乎都工作正常。
为什么不是每天cron日程表中旋转? 难道我做错了什么吗?
如果我得到这么多需要帮助这将是巨大的。
更新:它看起来像,这是因为的SELinux的-在我的用户主目录中的日志文件已经通过限制施加了SELinux和当logrotate的脚本运行:
SELinux is preventing /usr/sbin/logrotate from getattr access on the file /home/user/logs/application.log
SELinux的被限制访问日志轮播在目录中的日志文件不具有所需的SELinux的文件类型。 “在/ var / log”中有“var_log_t”文件上下文,logrotate的是能够做要紧。 因此,解决办法是设置这个对我的应用程序日志文件和它的父目录:
semanage fcontext -a -t var_log_t <directory/logfile>
restorecon -v <directory/logfile>
我有一个类似的问题。 要解决这个问题,我首先使用sestatus命令检查的SELinux的状态:
# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
然后,检查适用于使用LS --scontext文件和目录的SELinux安全环境。 检查要logrotate的进行操作,并检查正在文件,如在/ var /日志/ maillog中的文件:
# ls --scontext /var/log/maillog*
system_u:object_r:var_log_t:s0 /var/log/maillog
system_u:object_r:var_log_t:s0 /var/log/maillog-20140713
system_u:object_r:var_log_t:s0 /var/log/maillog-20140720
system_u:object_r:var_log_t:s0 /var/log/maillog-20140727
system_u:object_r:var_log_t:s0 /var/log/maillog-20140803
使用semanage的更改文件内容。
semanage fcontext -a -t var_log_t <directory/logfile>
restorecon -v <directory/logfile>
只是概括以上,并确保同样的SELinux正确以后所有文件设置:
semanage fcontext -a -t var_log_t "<directory>(/.*)?"
restorecon -v <directory>
SELinux的是防止/ usr / sbin目录/ logrotate的从目录中的站点读取访问。
*****插件包罗万象(100度)表明***************************
如果您认为logrotate的应允许读取默认站点目录的访问。 那么你应该作为一个bug报告这一情况。 您可以生成本地策略模块允许这种访问。
做
允许该访问现在通过执行:
# grep logrotate /var/log/audit/audit.log | audit2allow -M mypol # semodule -i mypol.pp
我最近遇到了类似的SELinux的相关问题logrotate
没有如预期的文件,当要旋转的日志是NFS共享上发生操作。
在这种情况下设置logrotate_use_nfs
seboolean似乎解决这个问题,如
$ setsebool logrotate_use_nfs 1
$ getsebool logrotate_use_nfs
logrotate_use_nfs --> on
我已经看到了SELINUX这个问题禁用,这是因为旋转日志文件的父目录具有不logrotate的欢迎全球的写权限
error: skipping "/xxx/yyy/log/logfile.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
搭配chmod父目录,755解决问题
# logrotate --version
logrotate 3.8.6