我正在使用CentOS,NGINX和Passenger来服务Rails应用程序。 我有SELinux激活,并有一系列与logrotate的问题。 我已经能够通过在线提供各种build议来解决大部分问题。 不幸的是,logrotate没有成功的旋转我的NGINX日志文件。 NGINX安装在/ opt / nginx中
这是我的logrotateconfiguration文件:
/opt/nginx/logs/*log { daily rotate 30 missingok notifempty sharedscripts delaycompress postrotate [ ! -f /opt/nginx/logs/nginx.pid ] || kill -USR1 `cat /opt/nginx/logs/nginx.pid` endscript }
这些是我在/ var / log / messages中收到的消息
Mar 9 03:49:14 localhost setroubleshoot: SELinux is preventing /usr/sbin/logrotate from rename access on the file logrotate_temp.RTg4y3. For complete SELinux messages. run sealert -l 8c5238cd-3e95-4af6-b150-498080c862b8 Mar 9 03:49:14 localhost setroubleshoot: SELinux is preventing /usr/sbin/logrotate from rename access on the file logrotate_temp.OjvGsG. For complete SELinux messages. run sealert -l 8c5238cd-3e95-4af6-b150-498080c862b8 Mar 10 03:55:46 localhost logrotate: ALERT exited abnormally with [1]
我已经尝试使用sealert来更新策略作为消息推荐,但是这不能解决问题(我怀疑这可能是因为临时文件总是有不同的名称)。
任何人都可以build议如何解决这个日志文件成功旋转。
– 编辑 – 增加了输出
sudo sealert -l 8c5238cd-3e95-4af6-b150-498080c862b8
:
SELinux is preventing /usr/sbin/logrotate from rename access on the file logrotate_temp.NuwGkX. ***** Plugin catchall (100. confidence) suggests *************************** If you believe that logrotate should be allowed rename access on the logrotate_temp.NuwGkX file by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # grep logrotate /var/log/audit/audit.log | audit2allow -M mypol # semodule -i mypol.pp
我发现问题在于一些较旧的(旋转的)日志文件。
在日志所在的目录中运行ls --scontext ,表明其中的2个日志没有var_log_t上下文。
我通过删除这些特定的文件(他们几个月大)来解决这个问题。
在下一次计划的运行中,日志正确旋转。
它可能有一些事实,你是不是这样的声明Logrotate控制文件的权限。 (注意创build0644 ….行)
/var/log/nginx/*log { create 0644 nginx nginx daily rotate 10 missingok notifempty compress sharedscripts postrotate /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true endscript }