我已经为 logrotate 设置了新的 conf,但我无法让它工作。
这是我的 logrotate:
/home/deployer/abc/shared/log/*.log {
daily
missingok
rotate 30
compress
delaycompress
size 5M
copytruncate
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
删除状态文件:
deployer@qapp01:~/abc/current/log$ cat /var/lib/logrotate/status
logrotate state -- version 2
Run Code Online (Sandbox Code Playgroud)
使用调试模式运行 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
Run Code Online (Sandbox Code Playgroud)
尝试使用 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/ab
这是我如何让它工作的:
size
或daily
。/etc/logrotate.d/abc
属于root
- sudo chown root:root /etc/logrotate.d/abc
。/etc/logrotate.d/abc
至少具有 644 权限 - sudo chmod 644 /etc/logrotate.d/abc
。/etc/logrotate.d/abc
使用正确的用户权限将其添加到 logrotate 文件中。例如,我的日志文件属于deployer:deployer
,然后我添加su deployer deployer
到/etc/logrotate.d/abc
.