由于 suspend.target,auth.log 变得非常大

由于 suspend.target,auth.log 变得非常大

几天之内,我的 Ubuntu 16.4.4 服务器上的 auth.log 就增长到了 28 GB,一遍又一遍地写入以下几行

Apr 14 21:31:29 Cloud systemd-logind[924]: Suspending...
Apr 14 21:31:29 Cloud systemd-logind[924]: Failed to execute operation: $

我知道这个输出是我遵循的结果这里的第二个答案是为了防止安装服务器的笔记本电脑进入睡眠状态。我使用命令sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target来完成这个任务。我现在问自己的问题是:

  • 有没有更好的方法来实现我的目标,即完全基于 CLI 防止系统休眠?
  • 我如何防止该消息被反复记录?

答案1

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

建议通过以下方式防止休眠和睡眠德比安。为了解决/var/lib/auth.log尺寸增长过大的问题,请编辑/etc/logrotate.d/rsyslog以添加maxsize 10M

/var/log/syslog
{
    rotate 7
    daily
    missingok
    notifempty
    delaycompress
    compress
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
 }

/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
    maxsize 10M
    rotate 4
    weekly
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

您可能还想添加一个logrotate.timer/etc/systemd/system覆盖默认的每小时运行一次而不是每天运行一次:

# /var/lib/auth.log was being filled to 7 GB due to hibernate.target being masked,
# which created a log entry very, very frequently. So /etc/logrotate.d/rsyslog was edited to set a
# maxsize of 10M for that log, and here we are going to run logrotate hourly
[Unit]
Description=Hourly rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnBootSec=30s
OnUnitActiveSec=60m

[Install]
WantedBy=timers.target

相关内容