
看來這個主題很受歡迎......所以我想我的 logrotate 無法旋轉 tomcat 日誌有問題。 Logrotate 設定設定/etc/logrotate.d/tomcat
為
/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out
{
daily
missingok
copytruncate
rotate 15
}
logrotate.conf 是:
> cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 12
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
... skipped ...
}
/var/log/btmp {
... skipped ...
}
報告的問題audit.log
是
type=AVC msg=audit(1580286181.904:9833967): avc: denied { write } for pid=25982 comm="logrotate" name="catalina.out-20191228.gz" dev="dm-3" ino=16889774 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:usr_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1580286181.904:9833967): arch=c000003e syscall=2 success=no exit=-13 a0=b392b0 a1=20002 a2=b392b0 a3=b39580 items=2 ppid=25980 pid=25982 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=72358 comm="logrotate" exe="/usr/sbin/logrotate" subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
type=CWD msg=audit(1580286181.904:9833967): cwd="/"
type=PATH msg=audit(1580286181.904:9833967): item=0 name="/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out-20191228.gz" inode=16889774 dev=fd:03 mode=0100640 ouid=1008 ogid=1009 rdev=00:00 obj=unconfined_u:object_r:usr_t:s0 objtype=NORMAL cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1580286181.904:9833967): item=1 name="/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out-20191228.gz" inode=16889774 dev=fd:03 mode=0100640 ouid=1008 ogid=1009 rdev=00:00 obj=unconfined_u:object_r:usr_t:s0 objtype=NORMAL cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PROCTITLE msg=audit(1580286181.904:9833967): proctitle=2F7573722F7362696E2F6C6F67726F74617465002D73002F7661722F6C69622F6C6F67726F746174652F6C6F67726F746174652E737461747573002F6574632F6C6F67726F746174652E636F6E66
usr_t
所以對我來說很神秘的是,如果其中的目錄和檔案var_log_t
根據策略標記為,為什麼 logrotate 會嘗試建立帶有上下文的檔案:
> semanage fcontext -l | grep logs
... skipped ...
/opt/tomcat/apache-tomcat-8.5.37/logs/ all files system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs all files system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out all files system_u:object_r:var_log_t:s0
可以採取哪些步驟來進一步排除故障?
(這是我在 Unix & Linux 部分發布的問題的副本)
答案1
於是問題就來了。問題出在上下文定義。相反,所有這 3 個定義
> semanage fcontext -l | grep logs
... skipped ...
/opt/tomcat/apache-tomcat-8.5.37/logs/ all files system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs all files system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out all files system_u:object_r:var_log_t:s0
已經引入了適當的替代品
/opt/tomcat/apache-tomcat-8.5.37/logs(/.*)?