Logrotate

Logrotate 不旋轉

  • June 20, 2016

我已經為 logrotate 設置了新的 conf,但我無法讓它工作。

這是我的日誌旋轉:

/home/deployer/abc/shared/log/*.log {
 daily
 missingok
 rotate 30
 compress
 delaycompress
 size 5M
 copytruncate
}

這是我嘗試過的:

刪除狀態文件:

deployer@qapp01:~/abc/current/log$ cat /var/lib/logrotate/status 
logrotate state -- version 2

使用調試模式執行 logrotate

deployer@qapp01:~/abc/current/log$ /usr/sbin/logrotate -d /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file apt
reading config file aptitude
reading config file dpkg
reading config file fail2ban
reading config file monit
reading config file mysql-server
reading config file newrelic-sysmond
reading config file nginx
reading config file ppp
reading config file abc
reading config file rsyslog
reading config file ufw
reading config file unattended-upgrades
reading config file upstart

Handling 19 logs

rotating pattern: /var/log/apt/term.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/apt/history.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/aptitude  monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/dpkg.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/alternatives.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/fail2ban.log  weekly (4 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/monit.log  weekly (4 rotations)
empty log files are not rotated, only log files >= 1048576 bytes are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mariadb-slow.log  after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/newrelic/nrsysmond.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
empty log files are not rotated, old logs are removed
No logs found. Rotation not needed.

rotating pattern: /var/log/ppp-connect-errors  weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /home/deployer/abc/shared/log/*.log  5242880 bytes (30 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/syslog
after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /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
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/ufw.log
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/unattended-upgrades/unattended-upgrades.log 
/var/log/unattended-upgrades/unattended-upgrades-shutdown.log
monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/upstart/*.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/wtmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

rotating pattern: /var/log/btmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
error: error switching euid to 0 and egid to 104: Operation not permitted

嘗試使用 sudo 執行它

deployer@qapp01:~/abc/current/log$ sudo /usr/sbin/logrotate -d /etc/logrotate.conf
[sudo] password for deployer: 
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file apt
reading config file aptitude
reading config file dpkg
reading config file fail2ban
reading config file monit
reading config file mysql-server
reading config file newrelic-sysmond
reading config file nginx
reading config file ppp
reading config file abc
reading config file rsyslog
reading config file ufw
reading config file unattended-upgrades
reading config file upstart

Handling 19 logs

rotating pattern: /var/log/apt/term.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/apt/term.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/apt/history.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/apt/history.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/aptitude  monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/aptitude
 log /var/log/aptitude does not exist -- skipping
switching euid to 0 and egid to 0

rotating pattern: /var/log/dpkg.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/dpkg.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/alternatives.log  monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/alternatives.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/fail2ban.log  weekly (4 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/fail2ban.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/monit.log  weekly (4 rotations)
empty log files are not rotated, only log files >= 1048576 bytes are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/monit.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mariadb-slow.log  after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/mysql.log
 log does not need rotating
considering log /var/log/mysql/mysql.log
 log does not need rotating
considering log /var/log/mysql/mariadb-slow.log
 log /var/log/mysql/mariadb-slow.log does not exist -- skipping
not running postrotate script, since no logs were rotated
switching euid to 0 and egid to 0

rotating pattern: /var/log/newrelic/nrsysmond.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/newrelic/nrsysmond.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/nginx/*.log  after 1 days (14 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/nginx/access.log
 log does not need rotating
considering log /var/log/nginx/error.log
 log does not need rotating
not running prerotate script, since no logs will be rotated
not running postrotate script, since no logs were rotated
switching euid to 0 and egid to 0

rotating pattern: /var/log/ppp-connect-errors  weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/ppp-connect-errors
 log /var/log/ppp-connect-errors does not exist -- skipping
switching euid to 0 and egid to 0

rotating pattern: /home/deployer/abc/shared/log/*.log  5242880 bytes (30 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /home/deployer/abc/shared/log/newrelic_agent.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/nginx.access.log
 log needs rotating
considering log /home/deployer/abc/shared/log/nginx.error.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/production.delayed_job.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/production.log
 log needs rotating
considering log /home/deployer/abc/shared/log/production.searchd.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/production.searchd.query.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/puma_access.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/puma_error.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/rake_ean_geocode.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/rake_ean_min_rate.log
 log does not need rotating
considering log /home/deployer/abc/shared/log/rake_ean_update_spots.log
 log does not need rotating
rotating log /home/deployer/abc/shared/log/nginx.access.log, log->rotateCount is 30
dateext suffix '-20160618'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /home/deployer/abc/shared/log/nginx.access.log.1 does not exist
renaming /home/deployer/abc/shared/log/nginx.access.log.30.gz to /home/deployer/abc/shared/log/nginx.access.log.31.gz (rotatecount 30, logstart 1, i 30), 
renaming /home/deployer/abc/shared/log/nginx.access.log.29.gz to /home/deployer/abc/shared/log/nginx.access.log.30.gz (rotatecount 30, logstart 1, i 29), 
renaming /home/deployer/abc/shared/log/nginx.access.log.28.gz to /home/deployer/abc/shared/log/nginx.access.log.29.gz (rotatecount 30, logstart 1, i 28), 
renaming /home/deployer/abc/shared/log/nginx.access.log.27.gz to /home/deployer/abc/shared/log/nginx.access.log.28.gz (rotatecount 30, logstart 1, i 27), 
renaming /home/deployer/abc/shared/log/nginx.access.log.26.gz to /home/deployer/abc/shared/log/nginx.access.log.27.gz (rotatecount 30, logstart 1, i 26), 
renaming /home/deployer/abc/shared/log/nginx.access.log.25.gz to /home/deployer/abc/shared/log/nginx.access.log.26.gz (rotatecount 30, logstart 1, i 25), 
renaming /home/deployer/abc/shared/log/nginx.access.log.24.gz to /home/deployer/abc/shared/log/nginx.access.log.25.gz (rotatecount 30, logstart 1, i 24), 
renaming /home/deployer/abc/shared/log/nginx.access.log.23.gz to /home/deployer/abc/shared/log/nginx.access.log.24.gz (rotatecount 30, logstart 1, i 23), 
renaming /home/deployer/abc/shared/log/nginx.access.log.22.gz to /home/deployer/abc/shared/log/nginx.access.log.23.gz (rotatecount 30, logstart 1, i 22), 
renaming /home/deployer/abc/shared/log/nginx.access.log.21.gz to /home/deployer/abc/shared/log/nginx.access.log.22.gz (rotatecount 30, logstart 1, i 21), 
renaming /home/deployer/abc/shared/log/nginx.access.log.20.gz to /home/deployer/abc/shared/log/nginx.access.log.21.gz (rotatecount 30, logstart 1, i 20), 
renaming /home/deployer/abc/shared/log/nginx.access.log.19.gz to /home/deployer/abc/shared/log/nginx.access.log.20.gz (rotatecount 30, logstart 1, i 19), 
renaming /home/deployer/abc/shared/log/nginx.access.log.18.gz to /home/deployer/abc/shared/log/nginx.access.log.19.gz (rotatecount 30, logstart 1, i 18), 
renaming /home/deployer/abc/shared/log/nginx.access.log.17.gz to /home/deployer/abc/shared/log/nginx.access.log.18.gz (rotatecount 30, logstart 1, i 17), 
renaming /home/deployer/abc/shared/log/nginx.access.log.16.gz to /home/deployer/abc/shared/log/nginx.access.log.17.gz (rotatecount 30, logstart 1, i 16), 
renaming /home/deployer/abc/shared/log/nginx.access.log.15.gz to /home/deployer/abc/shared/log/nginx.access.log.16.gz (rotatecount 30, logstart 1, i 15), 
renaming /home/deployer/abc/shared/log/nginx.access.log.14.gz to /home/deployer/abc/shared/log/nginx.access.log.15.gz (rotatecount 30, logstart 1, i 14), 
renaming /home/deployer/abc/shared/log/nginx.access.log.13.gz to /home/deployer/abc/shared/log/nginx.access.log.14.gz (rotatecount 30, logstart 1, i 13), 
renaming /home/deployer/abc/shared/log/nginx.access.log.12.gz to /home/deployer/abc/shared/log/nginx.access.log.13.gz (rotatecount 30, logstart 1, i 12), 
renaming /home/deployer/abc/shared/log/nginx.access.log.11.gz to /home/deployer/abc/shared/log/nginx.access.log.12.gz (rotatecount 30, logstart 1, i 11), 
renaming /home/deployer/abc/shared/log/nginx.access.log.10.gz to /home/deployer/abc/shared/log/nginx.access.log.11.gz (rotatecount 30, logstart 1, i 10), 
renaming /home/deployer/abc/shared/log/nginx.access.log.9.gz to /home/deployer/abc/shared/log/nginx.access.log.10.gz (rotatecount 30, logstart 1, i 9), 
renaming /home/deployer/abc/shared/log/nginx.access.log.8.gz to /home/deployer/abc/shared/log/nginx.access.log.9.gz (rotatecount 30, logstart 1, i 8), 
renaming /home/deployer/abc/shared/log/nginx.access.log.7.gz to /home/deployer/abc/shared/log/nginx.access.log.8.gz (rotatecount 30, logstart 1, i 7), 
renaming /home/deployer/abc/shared/log/nginx.access.log.6.gz to /home/deployer/abc/shared/log/nginx.access.log.7.gz (rotatecount 30, logstart 1, i 6), 
renaming /home/deployer/abc/shared/log/nginx.access.log.5.gz to /home/deployer/abc/shared/log/nginx.access.log.6.gz (rotatecount 30, logstart 1, i 5), 
renaming /home/deployer/abc/shared/log/nginx.access.log.4.gz to /home/deployer/abc/shared/log/nginx.access.log.5.gz (rotatecount 30, logstart 1, i 4), 
renaming /home/deployer/abc/shared/log/nginx.access.log.3.gz to /home/deployer/abc/shared/log/nginx.access.log.4.gz (rotatecount 30, logstart 1, i 3), 
renaming /home/deployer/abc/shared/log/nginx.access.log.2.gz to /home/deployer/abc/shared/log/nginx.access.log.3.gz (rotatecount 30, logstart 1, i 2), 
renaming /home/deployer/abc/shared/log/nginx.access.log.1.gz to /home/deployer/abc/shared/log/nginx.access.log.2.gz (rotatecount 30, logstart 1, i 1), 
renaming /home/deployer/abc/shared/log/nginx.access.log.0.gz to /home/deployer/abc/shared/log/nginx.access.log.1.gz (rotatecount 30, logstart 1, i 0), 
copying /home/deployer/abc/shared/log/nginx.access.log to /home/deployer/abc/shared/log/nginx.access.log.1
truncating /home/deployer/abc/shared/log/nginx.access.log
removing old log /home/deployer/abc/shared/log/nginx.access.log.31.gz
error: error opening /home/deployer/abc/shared/log/nginx.access.log.31.gz: No such file or directory
rotating log /home/deployer/abc/shared/log/production.log, log->rotateCount is 30
dateext suffix '-20160618'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /home/deployer/abc/shared/log/production.log.1 does not exist
renaming /home/deployer/abc/shared/log/production.log.30.gz to /home/deployer/abc/shared/log/production.log.31.gz (rotatecount 30, logstart 1, i 30), 
renaming /home/deployer/abc/shared/log/production.log.29.gz to /home/deployer/abc/shared/log/production.log.30.gz (rotatecount 30, logstart 1, i 29), 
renaming /home/deployer/abc/shared/log/production.log.28.gz to /home/deployer/abc/shared/log/production.log.29.gz (rotatecount 30, logstart 1, i 28), 
renaming /home/deployer/abc/shared/log/production.log.27.gz to /home/deployer/abc/shared/log/production.log.28.gz (rotatecount 30, logstart 1, i 27), 
renaming /home/deployer/abc/shared/log/production.log.26.gz to /home/deployer/abc/shared/log/production.log.27.gz (rotatecount 30, logstart 1, i 26), 
renaming /home/deployer/abc/shared/log/production.log.25.gz to /home/deployer/abc/shared/log/production.log.26.gz (rotatecount 30, logstart 1, i 25), 
renaming /home/deployer/abc/shared/log/production.log.24.gz to /home/deployer/abc/shared/log/production.log.25.gz (rotatecount 30, logstart 1, i 24), 
renaming /home/deployer/abc/shared/log/production.log.23.gz to /home/deployer/abc/shared/log/production.log.24.gz (rotatecount 30, logstart 1, i 23), 
renaming /home/deployer/abc/shared/log/production.log.22.gz to /home/deployer/abc/shared/log/production.log.23.gz (rotatecount 30, logstart 1, i 22), 
renaming /home/deployer/abc/shared/log/production.log.21.gz to /home/deployer/abc/shared/log/production.log.22.gz (rotatecount 30, logstart 1, i 21), 
renaming /home/deployer/abc/shared/log/production.log.20.gz to /home/deployer/abc/shared/log/production.log.21.gz (rotatecount 30, logstart 1, i 20), 
renaming /home/deployer/abc/shared/log/production.log.19.gz to /home/deployer/abc/shared/log/production.log.20.gz (rotatecount 30, logstart 1, i 19), 
renaming /home/deployer/abc/shared/log/production.log.18.gz to /home/deployer/abc/shared/log/production.log.19.gz (rotatecount 30, logstart 1, i 18), 
renaming /home/deployer/abc/shared/log/production.log.17.gz to /home/deployer/abc/shared/log/production.log.18.gz (rotatecount 30, logstart 1, i 17), 
renaming /home/deployer/abc/shared/log/production.log.16.gz to /home/deployer/abc/shared/log/production.log.17.gz (rotatecount 30, logstart 1, i 16), 
renaming /home/deployer/abc/shared/log/production.log.15.gz to /home/deployer/abc/shared/log/production.log.16.gz (rotatecount 30, logstart 1, i 15), 
renaming /home/deployer/abc/shared/log/production.log.14.gz to /home/deployer/abc/shared/log/production.log.15.gz (rotatecount 30, logstart 1, i 14), 
renaming /home/deployer/abc/shared/log/production.log.13.gz to /home/deployer/abc/shared/log/production.log.14.gz (rotatecount 30, logstart 1, i 13), 
renaming /home/deployer/abc/shared/log/production.log.12.gz to /home/deployer/abc/shared/log/production.log.13.gz (rotatecount 30, logstart 1, i 12), 
renaming /home/deployer/abc/shared/log/production.log.11.gz to /home/deployer/abc/shared/log/production.log.12.gz (rotatecount 30, logstart 1, i 11), 
renaming /home/deployer/abc/shared/log/production.log.10.gz to /home/deployer/abc/shared/log/production.log.11.gz (rotatecount 30, logstart 1, i 10), 
renaming /home/deployer/abc/shared/log/production.log.9.gz to /home/deployer/abc/shared/log/production.log.10.gz (rotatecount 30, logstart 1, i 9), 
renaming /home/deployer/abc/shared/log/production.log.8.gz to /home/deployer/abc/shared/log/production.log.9.gz (rotatecount 30, logstart 1, i 8), 
renaming /home/deployer/abc/shared/log/production.log.7.gz to /home/deployer/abc/shared/log/production.log.8.gz (rotatecount 30, logstart 1, i 7), 
renaming /home/deployer/abc/shared/log/production.log.6.gz to /home/deployer/abc/shared/log/production.log.7.gz (rotatecount 30, logstart 1, i 6), 
renaming /home/deployer/abc/shared/log/production.log.5.gz to /home/deployer/abc/shared/log/production.log.6.gz (rotatecount 30, logstart 1, i 5), 
renaming /home/deployer/abc/shared/log/production.log.4.gz to /home/deployer/abc/shared/log/production.log.5.gz (rotatecount 30, logstart 1, i 4), 
renaming /home/deployer/abc/shared/log/production.log.3.gz to /home/deployer/abc/shared/log/production.log.4.gz (rotatecount 30, logstart 1, i 3), 
renaming /home/deployer/abc/shared/log/production.log.2.gz to /home/deployer/abc/shared/log/production.log.3.gz (rotatecount 30, logstart 1, i 2), 
renaming /home/deployer/abc/shared/log/production.log.1.gz to /home/deployer/abc/shared/log/production.log.2.gz (rotatecount 30, logstart 1, i 1), 
renaming /home/deployer/abc/shared/log/production.log.0.gz to /home/deployer/abc/shared/log/production.log.1.gz (rotatecount 30, logstart 1, i 0), 
copying /home/deployer/abc/shared/log/production.log to /home/deployer/abc/shared/log/production.log.1
truncating /home/deployer/abc/shared/log/production.log
removing old log /home/deployer/abc/shared/log/production.log.31.gz
error: error opening /home/deployer/abc/shared/log/production.log.31.gz: No such file or directory
switching euid to 0 and egid to 0

rotating pattern: /var/log/syslog
after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/syslog
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /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
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/mail.info
 log /var/log/mail.info does not exist -- skipping
considering log /var/log/mail.warn
 log /var/log/mail.warn does not exist -- skipping
considering log /var/log/mail.err
 log /var/log/mail.err does not exist -- skipping
considering log /var/log/mail.log
 log /var/log/mail.log does not exist -- skipping
considering log /var/log/daemon.log
 log /var/log/daemon.log does not exist -- skipping
considering log /var/log/kern.log
 log does not need rotating
considering log /var/log/auth.log
 log does not need rotating
considering log /var/log/user.log
 log /var/log/user.log does not exist -- skipping
considering log /var/log/lpr.log
 log /var/log/lpr.log does not exist -- skipping
considering log /var/log/cron.log
 log /var/log/cron.log does not exist -- skipping
considering log /var/log/debug
 log /var/log/debug does not exist -- skipping
considering log /var/log/messages
 log /var/log/messages does not exist -- skipping
not running postrotate script, since no logs were rotated
switching euid to 0 and egid to 0

rotating pattern: /var/log/ufw.log
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/ufw.log
 log /var/log/ufw.log does not exist -- skipping
not running postrotate script, since no logs were rotated
switching euid to 0 and egid to 0

rotating pattern: /var/log/unattended-upgrades/unattended-upgrades.log 
/var/log/unattended-upgrades/unattended-upgrades-shutdown.log
monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/unattended-upgrades/unattended-upgrades.log
 log /var/log/unattended-upgrades/unattended-upgrades.log does not exist -- skipping
considering log /var/log/unattended-upgrades/unattended-upgrades-shutdown.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/upstart/*.log  after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/upstart/acpid.log
 log does not need rotating
considering log /var/log/upstart/nginx.log
 log does not need rotating
considering log /var/log/upstart/rsyslog.log
 log does not need rotating
considering log /var/log/upstart/systemd-logind.log
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/wtmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/wtmp
 log does not need rotating
switching euid to 0 and egid to 0

rotating pattern: /var/log/btmp  monthly (1 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 104
considering log /var/log/btmp
 log does not need rotating
switching euid to 0 and egid to 0

但是我的應用程序日誌仍然沒有旋轉:

deployer@qapp01:~/abc/current/log$ ll
total 1227256
drwxrwxr-x  2 deployer deployer       4096 Jun 18 15:53 ./
drwxrwxr-x 11 deployer deployer       4096 Jun 18 11:18 ../
-rw-rw-r--  1 deployer deployer     574462 Jun 18 15:54 newrelic_agent.log
-rw-r--r--  1 root     root       25550727 Jun 18 15:55 nginx.access.log
-rw-r--r--  1 root     root              0 Jun 18 00:13 nginx.error.log
-rw-rw-r--  1 deployer deployer       4455 Jun 18 15:44 production.delayed_job.log
-rw-rw-r--  1 deployer deployer 1230525588 Jun 18 15:55 production.log
-rw-------  1 deployer deployer       6798 Jun 18 11:35 production.searchd.log
-rw-------  1 deployer deployer       6302 Jun 18 15:44 production.searchd.query.log
-rw-rw-r--  1 deployer deployer        120 Jun 18 00:30 puma_access.log
-rw-rw-r--  1 deployer deployer         48 Jun 18 00:30 puma_error.log
-rw-rw-r--  1 deployer deployer          0 Jun 17 12:16 rake_ean_geocode.log
-rw-rw-r--  1 deployer deployer          0 Jun 17 12:16 rake_ean_min_rate.log
-rw-rw-r--  1 deployer deployer          0 Jun 17 12:16 rake_ean_update_spots.log

即使在Google搜尋各種解決方案但無濟於事之後,我也已經沒有線索了。

這是我如何讓它工作的:

  1. 根據上面 Paul Haldane 的回答,確保它是sizeor daily
  2. 確保其中的文件/etc/logrotate.d/abcroot-擁有sudo chown root:root /etc/logrotate.d/abc
  3. 確保文件中的文件/etc/logrotate.d/abc至少具有 644 權限 - sudo chmod 644 /etc/logrotate.d/abc.
  4. 要使 logrotate 具有正確的工作權限,請將其添加到/etc/logrotate.d/abc具有正確使用者權限的 logrotate 文件中。例如,我的日誌文件由 擁有deployer:deployer,然後我添加su deployer deployer/etc/logrotate.d/abc.

您已經在配置中指定了size這些daily日誌文件。我的理解是,這size會導致任何基於時間的輪換(請參閱此處的類似問題 -例如這個)。

基於此,我現在唯一希望輪換的文件是production.logand nginx.access.log。使用sudo顯示的調試執行的輸出logrotate確實會旋轉這些文件。

請記住,執行時-d logrotate不會進行任何更改。如果您想了解更多有關正在發生的事情以及進行更改的資訊,請改為使用-v

請注意,(通常)logrotate期望以root. 請注意,在執行時您不會收到有關switching euidvia的警告sudo

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