我对轮换有两个问题/var/log/message
。以下是日志消息配置
# cat /etc/logrotate.d/logrotate-messages
/var/log/messages {
daily
rotate 7
create
dateext
dateformat -%Y%m%d
compress
delaycompress
notifempty
nomail
noolddir
postrotate
/bin/killall -HUP syslogd
endscript
}
由于某种原因,旋转后,/var/log/messages
没有任何后缀的文件没有消息,但最后一个日期的文件包含所有消息/var/log/messages-20200427
-rw-------. 1 root root 6.8M Apr 12 03:36 /var/log/messages-20200412.gz
-rw-------. 1 root root 41M Apr 19 03:30 /var/log/messages-20200417.gz
-rw-------. 1 root root 43M Apr 26 03:13 /var/log/messages-20200425.gz
-rw-------. 1 root root 0 Apr 27 03:47 /var/log/messages
-rw-------. 1 root root 3.6G Apr 30 13:15 /var/log/messages-20200427
当我手动运行时,我在旋转后只看到一个错误,如下所示。
#/sbin/logrotate -v /etc/logrotate.d/logrotate-messages
reading config file /etc/logrotate.d/logrotate-messages
Allocating hash table for state file, size 15360 B
Handling 1 logs
rotating pattern: /var/log/messages after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/messages
log needs rotating
rotating log /var/log/messages, log->rotateCount is 7
Converted ' -%Y%m%d' -> '-%Y%m%d'
dateext suffix '-20200430'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
fscreate context set to system_u:object_r:var_log_t:s0
renaming /var/log/messages to /var/log/messages-20200430
creating new /var/log/messages mode = 0600 uid = 0 gid = 0
running postrotate script
syslogd: no process found
error: error running non-shared postrotate script for /var/log/messages of '/var/log/messages '
set default create context
写入文件的过程是
#fuser /var/log/messages-20200427
/var/log/messages-20200427: 41809
# ps -aef | grep 41809 | grep -v grep
root 41809 1 0 Apr24 ? 00:20:18 /usr/sbin/rsyslogd -n
不确定如何修复,非常感谢任何帮助。
答案1
您正尝试将 SIGHUP 发送到错误的进程:
/bin/killall -HUP syslogd
但
/usr/sbin/rsyslogd
所以你必须将其更改为
/bin/killall -HUP rsyslogd