Logrotate

fail2ban 的 Logrotate 錯誤

  • March 4, 2014

執行 cron 作業時出現以下錯誤,我不太確定如何修復。這是在 Ubuntu 12.04 LTS 上。

test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

/etc/cron.daily/logrotate:
error: error running non-shared postrotate script for /var/log/fail2ban.log of '/var/log/fail2ban.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

這是 /etc/logrotate.d/fail2ban 的內容

/var/log/fail2ban.log {

   weekly
   rotate 4
   compress

   delaycompress
   missingok
   postrotate
   fail2ban-client set logtarget /var/log/fail2ban.log >/dev/null
   endscript

   # If fail2ban runs as non-root it still needs to have write access
   # to logfiles.
   # create 640 fail2ban adm
   create 640 root adm
}

這是 /etc/cron.daily/logrotate 文件

#!/bin/sh

# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
   [ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

錯誤無法聯繫伺服器。它在執行嗎?

您的 fail2ban 服務沒有執行啟動它!

service fail2ban start

或者在你的 Ubuntu 上啟動它。

將“notifempty”添加到 /etc/logrotate.d/fail2ban。如果安裝了 fail2ban 但未執行,則日誌將為空且不會輪換。

引用自:https://serverfault.com/questions/509095