為什麼logrotate不自動輪替?

為什麼logrotate不自動輪替?

我已經為你設定了每天輪換,但你沒有。

但當我手動執行時,它確實有效。

logrotate -vf /etc/logrotate.conf

這是我要輪換的日誌檔案。 /mylogs/log(-rwxrwxrwxrwx 1 管理員管理員)

這是系統配置。

/etc/logrotate.conf (-rw-r--r-- 1 root root)

/mylogs/log {
create 0640 root utmp
missingok
daily
copytruncate
rotate 10
dateext
}

/etc/logrotate.d/syslog (-rw-r--r-- 1 root root)

/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || 
true
endscript
}

/etc/cron.daily/logrotate (-rwx------ 1 root root)

#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with 
[$EXITVALUE]"
fi
exit 0

/etc/crontab (-rw-r--r--. 1 root root)

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR 
sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

附加資訊。 CentOS作業系統

我怎樣才能讓它正確旋轉。


更新

我認為問題在於分配三件事的所有者、群組和權限。 /mylogs/ 資料夾 (root root) /mylogs/log 檔案 (admin admin)
logrotate.conf 的建立選項 (create 0640 root utmp)

logrotate 運行正確的人。請告訴我您如何分配前 3 個值。資料夾 - 檔案 - logrotate.conf 中的建立配置

答案1

在這裡連接兩個字串

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status 
/etc/logrotate.conf

對於像這樣的一個字串:

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf

或在第一個字串後面加上反斜杠,如下所示:

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status \
/etc/logrotate.conf

ps 有一個很好的選項-x可以/bin/sh從 shell 進行調試輸出,我想如果您下次嘗試運行,您將能夠找到這個錯誤類型/bin/sh -x /etc/cron.daily/logrotate

答案2

經過幾次測試,我設法讓它再次正確旋轉。

為此,我分配了日誌檔案的使用者(root)和群組(root)。

同時將您的權限改為 666。

對於包含該檔案的資料夾,它被分配了群組(root)的使用者(root)和755權限。

最後,在 logrotate.conf 的設定中,指派給此屬性「create」的設定是使用者(root)、群組(utmp)和權限(644)

我希望這些資訊對遇到類似問題的人有用。

問候並謝謝你。

相關內容