我的日志旋转服务失败了。它抱怨modsecurity有一个重复条目。
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-06-08 14:22:07 CST; 2h 54min ago
Docs: man:logrotate(8)
man:logrotate.conf(5)
Main PID: 15370 (code=exited, status=1/FAILURE)
Jun 08 14:22:07 server1.example.com systemd[1]: Starting Rotate log files...
Jun 08 14:22:07 server1.example.com logrotate[15370]: error: modsecurity:1 duplicate log entry for /var/log/apache2/modsec_audit.log
Jun 08 14:22:07 server1.example.com logrotate[15370]: error: found error in file modsecurity, skipping
Jun 08 14:22:07 server1.example.com systemd[1]: logrotate.service: Main process exited, code=exited, status=1/FAILURE
Jun 08 14:22:07 server1.example.com systemd[1]: logrotate.service: Failed with result 'exit-code'.
Jun 08 14:22:07 server1.example.com systemd[1]: Failed to start Rotate log files.但是,/etc/logrotate.d/modsecurity不包含任何重复项:
/var/log/apache2/modsec_audit.log
{
rotate 14
daily
missingok
compress
delaycompress
notifempty
}有什么想法吗?
更新:
#grep -r 'modsec_audit.log' /etc/
/etc/logrotate.d/modsecurity:/var/log/apache2/modsec_audit.log
/etc/modsecurity/modsecurity.conf:SecAuditLog /var/log/apache2/modsec_audit.log
/etc/modsecurity/modsecurity.conf-recommended:SecAuditLog /var/log/apache2/modsec_audit.log所以我经历了:
/etc/modsecurity/modsecurity.conf:SecAuditLog /var/log/apache2/modsec_audit.log
/etc/modsecurity/modsecurity.conf-recommended:SecAuditLog /var/log/apache2/modsec_audit.log并对modsec_audit.log值进行散列,如下所示
#SecAuditLogType Serial
#SecAuditLog /var/log/apache2/modsec_audit.log然后ran:systemctl restart logrotate
相同误差
<#>UPDATE 2:
按照@Nikita的建议,我彻底地散列了/etc/logrotate.d/modsecurity,现在日志旋转成功执行(所有mdosec日志散列):
#systemctl status logrotate
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: inactive (dead) since Thu 2021-06-10 09:36:53 CST; 52s ago
Docs: man:logrotate(8)
man:logrotate.conf(5)
Process: 20308 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=0/SUCCESS)
Main PID: 20308 (code=exited, status=0/SUCCESS)
Jun 10 09:36:52 tester1.example.com systemd[1]: Starting Rotate log files...
Jun 10 09:36:53 tester1.example.com systemd[1]: logrotate.service: Succeeded.
Jun 10 09:36:53 tester1.example.com systemd[1]: Started Rotate log files.因此,我启用了位于/etc/modsecurity/modsecuirty.conf的原始D8,以查看会发生什么。再一次,事情似乎是正确的。
# systemctl status logrotate
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: inactive (dead) since Thu 2021-06-10 09:54:05 CST; 4s ago
Docs: man:logrotate(8)
man:logrotate.conf(5)
Process: 21452 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=0/SUCCESS)
Main PID: 21452 (code=exited, status=0/SUCCESS)
Jun 10 09:54:05 tester1.example.com systemd[1]: Starting Rotate log files...
Jun 10 09:54:05 tester1.example.com systemd[1]: logrotate.service: Succeeded.
Jun 10 09:54:05 tester1.example.com systemd[1]: Started Rotate log files.对于/etc/modsecurity/modsecurity-recommended也是如此,这意味着当我使用/etc/logrotate.d/modsecuirty时,日志旋转服务只有失败,冲突必须是@Nikita建议的通配符。
发布于 2021-06-10 07:43:37
因此,文件/var/log/apache2/modsec_audit.log被设置为由/etc/logrotate.d/modsecurity和其他文件旋转,该文件用通配符覆盖它。例如,可以将其定义为/var/log/apache2/*log,当然也包括此文件。我不知道您还有哪些日志旋转配置文件,但是很有可能是/etc/logrotate.d/apache2或者类似的文件有通配符。
因此,即使删除了/var/log/apache2/modsec_audit.log,也会旋转/etc/logrotate.d/modsecurity。或者更好的方法是,用一个空文件替换它(或者用一个只包含这个SF问题和答案的链接的注释来代替它,以便于记住发生了什么)。这是一个问题的最简单的近时解决方案.另外,您可能想要从通配符中删除/var/log/apache2/modsec_audit.log;在logrotate中没有方法将“排除”设置为通配符,因此您最终会重写通配符(S),因此它将包含除此文件之外的所有文件。我认为这很麻烦。
还请记住,/etc/logrotate.d/modsecurity和其他日志旋转配置可能是由一些OS包安装的。更新这些包时,将重新安装这些文件。虽然删除的文件将被重新放置,但编辑的文件不会。配置文件保护会启动,至少您会收到更新的配置和手动解决提示的通知。因此,“创建一个空文件”被算作一个编辑,并将为您节省一些头发。
而且,要彻底和永久地解决这个问题,您应该发现这些冲突文件属于哪个包,并将一个bug提交到发行版的bug跟踪器中。您可以说服他们修复包,这样更新就不会包含这些文件,或者这些文件不会冲突,所以更新后不会中断。
发布于 2021-06-08 13:01:07
很可能在另一个文件中定义了重复条目。如果没有此文件问题,请检查/etc/logrotate.conf文件是否有副本。
grep -rnw '/etc/logrotate.d/' -e 'modsec_audit.log'要在其他文件中查找副本,请执行以下操作。
您还可以尝试查看/etc/logrotate.d/rsyslog文件:
grep 'modsec_audit.log' /etc/logrotate.d/rsyslog你可以在那里找到副本。
https://serverfault.com/questions/1066047
复制相似问题