AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[logrotate](ubuntu)

Martin Hope
ThinkHard
Asked: 2022-09-16 13:03:28 +0800 CST

Ubuntu 22.04:升级到 Ubuntu 22.04 后,Logrotate 无法正常工作

  • 0

我刚刚意识到,自从升级到 22.04.1 后,logrotate 无法正常工作。Syslog 已经很多天没有轮换过了。它应该由 systemd 计时器运行,并激活相关计时器:

# systemctl list-timers
NEXT                         LEFT               LAST                         PA>
Thu 2022-09-15 23:09:00 CEST 20min left         Thu 2022-09-15 22:39:22 CEST 9m>
Thu 2022-09-15 23:30:42 CEST 42min left         Thu 2022-09-15 22:33:38 CEST 14>
Thu 2022-09-15 23:55:00 CEST 1h 6min left       Wed 2022-09-14 23:55:05 CEST 22>
Fri 2022-09-16 00:00:00 CEST 1h 11min left      n/a                          n/>
Fri 2022-09-16 00:00:00 CEST 1h 11min left      Thu 2022-09-15 00:00:01 CEST 22>
Fri 2022-09-16 02:35:57 CEST 3h 47min left      Thu 2022-09-15 02:35:57 CEST 20>
Fri 2022-09-16 02:46:01 CEST 3h 57min left      Thu 2022-09-15 02:46:01 CEST 20>
Fri 2022-09-16 03:22:12 CEST 4h 33min left      Thu 2022-09-15 10:43:31 CEST 12>
Fri 2022-09-16 04:26:17 CEST 5h 37min left      Thu 2022-09-15 22:04:50 CEST 43>
Fri 2022-09-16 06:28:52 CEST 7h left            Thu 2022-09-15 06:39:52 CEST 16>
Fri 2022-09-16 06:54:45 CEST 8h left            Thu 2022-09-15 00:59:05 CEST 21>
Fri 2022-09-16 07:27:18 CEST 8h left            Thu 2022-09-15 20:08:18 CEST 2h>
Fri 2022-09-16 10:23:45 CEST 11h left           Thu 2022-09-15 19:41:01 CEST 3h>
Sun 2022-09-18 03:10:01 CEST 2 days left        Sun 2022-09-11 03:11:05 CEST 4 >
Mon 2022-09-19 00:14:45 CEST 3 days left        Mon 2022-09-12 00:40:35 CEST 3 >
Sun 2022-09-25 02:14:00 CEST 1 week 2 days left Sun 2022-09-11 10:56:49 CEST 4 >

16 timers listed.

根据系统日志,logrotate 也在运行:

Sep 14 00:00:08 server1 systemd[1]: logrotate.service: Deactivated successfully.
Sep 14 02:30:41 server1 systemd[1]: logrotate.timer: Deactivated successfully.
Sep 15 00:00:01 server1 systemd[1]: logrotate.service: Deactivated successfully.
Sep 15 02:30:42 server1 systemd[1]: logrotate.timer: Deactivated successfully.

systemd 也确认了:

# systemctl status logrotate.timer
● logrotate.timer - Daily rotation of log files
     Loaded: loaded (/lib/systemd/system/logrotate.timer; enabled; vendor prese>
     Active: active (waiting) since Thu 2022-09-15 02:30:57 CEST; 20h ago
    Trigger: Fri 2022-09-16 00:00:00 CEST; 1h 8min left
   Triggers: ● logrotate.service
       Docs: man:logrotate(8)
             man:logrotate.conf(5)

Sep 15 02:30:57 server1 systemd[1]: Started Daily rotation of log fil

但是没有轮换日志。当我按照 logrotate.service 中的指定手动启动 logrotate 时,没有任何反应(没有输出,没有旋转日志):

root@server1:/usr/lib/systemd/system# /usr/sbin/logrotate /etc/logrotate.conf
root@server1:/usr/lib/systemd/system#

然后,当我使用 -vf 启动 logrotate 以查看问题所在时,日志确实已旋转:

root@server1:/usr/lib/systemd/system# /usr/sbin/logrotate -vf /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d

请问我应该如何调试它并让 logrotate 定期运行?

logrotate
  • 1 个回答
  • 91 Views
Martin Hope
AjayC
Asked: 2020-12-13 00:06:10 +0800 CST

/var/log/syslog 没有得到轮换

  • 1

我全新安装了 ubuntu 20.04。我在 /etc/logrotate.d/rsyslog 文件中设置了每日轮换,最大大小为 1M,但 /var/log/syslog 和 kern.log 文件不断增加。这是 rsyslog 和 /etc/logrotate.conf 配置。


rsyslog 文件

/var/log/syslog
{
    rotate 4
    maxsize 1M
    daily
    missingok
    notifempty
    compress
    delaycompress
#   create 640 root adm
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
#       reload rsyslog >/dev/null 2>&1 || true
    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
{
    rotate 4
    daily
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

Logrotate.conf 文件

rotate log files weekly
#weekly
daily

# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
# su root syslog
# size 3M
# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
#dateext

# uncomment this if you want your log files compressed
#compress
# compress
# packages drop log rotation information into this directory
include /etc/logrotate.d

# system-specific logs may be also be configured here.
#/var/log/syslog {
#   size 1M
#   rotate 4
#   daily
#   missingok
#   notifempty
#   delaycompress
#   compress
#   postrotate
#       invoke-rc.d rsyslog reload > /dev/null
#   endscript   
#}

任何帮助,将不胜感激。

编辑:谢谢。这是输出。

$ logrotate --debug /etc/logrotate.conf
WARNING: logrotate in debug mode does nothing except printing debug messages!  Consider using verbose mode (-v) instead if this is not what you want.

reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file alternatives
reading config file apport
reading config file apt
reading config file bootlog
reading config file btmp
reading config file cups-daemon
reading config file dpkg
reading config file ppp
reading config file rsyslog
reading config file speech-dispatcher
reading config file ubuntu-advantage-tools
reading config file ufw
reading config file unattended-upgrades
reading config file wtmp
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state

Handling 17 logs

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 4
error: error switching euid to 0 and egid to 4: Operation not permitted

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

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 4
error: error switching euid to 0 and egid to 4: 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 4
error: error switching euid to 0 and egid to 4: Operation not permitted

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

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

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 4
error: error switching euid to 0 and egid to 4: Operation not permitted

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

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

rotating pattern: /var/log/speech-dispatcher/debug-epos-generic /var/log/speech-dispatcher/debug-festival /var/log/speech-dispatcher/debug-flite  after 1 days (2 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted

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

rotating pattern: /var/log/unattended-upgrades/unattended-upgrades.log 
/var/log/unattended-upgrades/unattended-upgrades-dpkg.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 4
error: error switching euid to 0 and egid to 4: Operation not permitted

rotating pattern: /var/log/wtmp  monthly (1 rotations)
empty log files are rotated, only log files >= 1048576 bytes are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
log rsyslog logrotate
  • 1 个回答
  • 1686 Views
Martin Hope
Philipp Claßen
Asked: 2020-09-17 12:38:57 +0800 CST

logrotate 在以 root 身份手动运行时成功,但在由 logrotate.service 运行时失败并显示“只读文件系统”

  • 3

我从以前的 Ubuntu 18.04 安装中获取了 OpenResty 的(以前工作的)logrotate 设置。然而 logrotate.service 现在失败并出现此错误......

error: error renaming /usr/local/openresty/nginx/logs/access.log.60.zst
to /usr/local/openresty/nginx/logs/access.log.61.zst: Read-only file system

...我很难理解为什么。新机器运行的是 Ubuntu 20.04,但我不明白为什么在这种情况下会有所作为。

首先,这是配置:

$ cat /etc/logrotate.d/custom-openresty

/usr/local/openresty/nginx/logs/access.log
/usr/local/openresty/nginx/logs/error.log
{
  daily
  rotate 60
  maxsize 1G
  missingok
  notifempty
  compress
  compresscmd /usr/bin/zstd
  uncompresscmd /usr/bin/unzstd
  compressoptions -9 --long -T1
  compressext .zst
  delaycompress
  sharedscripts
  postrotate
    test ! -f /usr/local/openresty/nginx/logs/nginx.pid || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
 endscript
}

/etc/logrotate.conf没有改变,看起来像这样:


# see "man logrotate" for details
# rotate log files weekly
weekly

# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
#dateext

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# system-specific logs may be also be configured here.

这是我的文件的状态(我希望access.log.1在 logrotate 运行后得到):

$ ls -alhg /usr/local/openresty/nginx/logs/
total 10G
drwxr-xr-x  2 root 4.0K Sep 16 20:04 .
drwxr-xr-x 18 root 4.0K Sep 16 19:42 ..
-rw-r--r--  1 root  10G Sep 16 19:56 access.log
-rw-r--r--  1 root 5.5K Sep 16 19:56 error.log

但是,logrotate.service 失败并出现以下错误:

~$ systemctl status logrotate.service 
● logrotate.service - Rotate log files
     Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2020-09-16 20:11:32 UTC; 4min 32s ago
TriggeredBy: ● logrotate.timer
       Docs: man:logrotate(8)
             man:logrotate.conf(5)
    Process: 27403 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=1/FAILURE)
   Main PID: 27403 (code=exited, status=1/FAILURE)

$ sudo journalctl --unit logrotate.service

Sep 16 20:11:32 fetcher-scheduler systemd[1]: Starting Rotate log files...
Sep 16 20:11:32 fetcher-scheduler logrotate[27403]: error: error renaming /usr/local/openresty/nginx/logs/access.log.60.zst to /usr/local/openresty/nginx/logs/access.log.61.zst: Read-only file system
Sep 16 20:11:32 fetcher-scheduler systemd[1]: logrotate.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 20:11:32 fetcher-scheduler systemd[1]: logrotate.service: Failed with result 'exit-code'.
Sep 16 20:11:32 fetcher-scheduler systemd[1]: Failed to start Rotate log files.

当我以 root 身份在调试模式下运行它(没有 systemd)时,我得到以下输出:

# logrotate -v -d /etc/logrotate.d/custom-openresty

reading config file /etc/logrotate.d/custom-openresty
compress_prog is now /usr/bin/zstd
uncompress_prog is now /usr/bin/unzstd
compress_options is now  -9 --long -T1
compress_ext is now .zst
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
...
Creating new state

Handling 1 logs

rotating pattern: /usr/local/openresty/nginx/logs/access.log
/usr/local/openresty/nginx/logs/error.log
 after 1 days (60 rotations)
empty log files are not rotated, log files >= 1073741824 are rotated earlier, old logs are removed
considering log /usr/local/openresty/nginx/logs/access.log
  Now: 2020-09-16 20:24
  Last rotated at 2020-09-16 20:11
  log needs rotating
considering log /usr/local/openresty/nginx/logs/error.log
  Now: 2020-09-16 20:24
  Last rotated at 2020-09-16 19:00
  log does not need rotating (log has been rotated at 2020-9-16 19:0, that is not day ago yet)
rotating log /usr/local/openresty/nginx/logs/access.log, log->rotateCount is 60
dateext suffix '-20200916'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /usr/local/openresty/nginx/logs/access.log.1 does not exist
renaming /usr/local/openresty/nginx/logs/access.log.60.zst to /usr/local/openresty/nginx/logs/access.log.61.zst (rotatecount 60, logstart 1, i 60), 
renaming /usr/local/openresty/nginx/logs/access.log.59.zst to /usr/local/openresty/nginx/logs/access.log.60.zst (rotatecount 60, logstart 1, i 59), 
...
/logs/access.log.3.zst (rotatecount 60, logstart 1, i 2), 
renaming /usr/local/openresty/nginx/logs/access.log.1.zst to /usr/local/openresty/nginx/logs/access.log.2.zst (rotatecount 60, logstart 1, i 1), 
renaming /usr/local/openresty/nginx/logs/access.log.0.zst to /usr/local/openresty/nginx/logs/access.log.1.zst (rotatecount 60, logstart 1, i 0), 
log /usr/local/openresty/nginx/logs/access.log.61.zst doesn't exist -- won't try to dispose of it
renaming /usr/local/openresty/nginx/logs/access.log to /usr/local/openresty/nginx/logs/access.log.1
running postrotate script
running script with arg /usr/local/openresty/nginx/logs/access.log
/usr/local/openresty/nginx/logs/error.log
: "
    test ! -f /usr/local/openresty/nginx/logs/nginx.pid || kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
"

对我来说,一切看起来都很正常。如果我运行它,它也可以工作:

# logrotate -v /etc/logrotate.d/custom-openresty
reading config file /etc/logrotate.d/custom-openresty
compress_prog is now /usr/bin/zstd
uncompress_prog is now /usr/bin/unzstd
compress_options is now  -9 --long -T1
compress_ext is now .zst
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
...
Creating new state

Handling 1 logs

rotating pattern: /usr/local/openresty/nginx/logs/access.log
/usr/local/openresty/nginx/logs/error.log
 after 1 days (60 rotations)
empty log files are not rotated, log files >= 1073741824 are rotated earlier, old logs are removed
considering log /usr/local/openresty/nginx/logs/access.log
  Now: 2020-09-16 20:26
  Last rotated at 2020-09-16 20:11
  log needs rotating
considering log /usr/local/openresty/nginx/logs/error.log
  Now: 2020-09-16 20:26
  Last rotated at 2020-09-16 19:00
  log does not need rotating (log has been rotated at 2020-9-16 19:0, that is not day ago yet)
rotating log /usr/local/openresty/nginx/logs/access.log, log->rotateCount is 60
dateext suffix '-20200916'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /usr/local/openresty/nginx/logs/access.log.1 does not exist
renaming /usr/local/openresty/nginx/logs/access.log.60.zst to /usr/local/openresty/nginx/logs/access.log.61.zst (rotatecount 60, logstart 1, i 60), 
old log /usr/local/openresty/nginx/logs/access.log.60.zst does not exist
...
old log /usr/local/openresty/nginx/logs/access.log.2.zst does not exist
renaming /usr/local/openresty/nginx/logs/access.log.1.zst to /usr/local/openresty/nginx/logs/access.log.2.zst (rotatecount 60, logstart 1, i 1), 
old log /usr/local/openresty/nginx/logs/access.log.1.zst does not exist
renaming /usr/local/openresty/nginx/logs/access.log.0.zst to /usr/local/openresty/nginx/logs/access.log.1.zst (rotatecount 60, logstart 1, i 0), 
old log /usr/local/openresty/nginx/logs/access.log.0.zst does not exist
log /usr/local/openresty/nginx/logs/access.log.61.zst doesn't exist -- won't try to dispose of it
renaming /usr/local/openresty/nginx/logs/access.log to /usr/local/openresty/nginx/logs/access.log.1
running postrotate script

没有错误,最终access.log.1按预期创建:

# ls -algh /usr/local/openresty/nginx/logs/
total 10G
drwxr-xr-x  2 root 4.0K Sep 16 20:26 .
drwxr-xr-x 18 root 4.0K Sep 16 19:42 ..
-rw-r--r--  1 root  10G Sep 16 19:56 access.log.1
-rw-r--r--  1 root 5.5K Sep 16 19:56 error.log

请注意,它说...

log /usr/local/openresty/nginx/logs/access.log.61.zst
doesn't exist -- won't try to dispose of it

...而不是error renaming ... Read-only file system(就像logrotate.service那样)

为什么以root身份手动运行时它可以工作,但是当它被logrotate.service执行时却失败了?

我没有对logrotate.service. 为了完整起见,这里是单元文件:

$ systemctl cat logrotate.service
# /lib/systemd/system/logrotate.service
[Unit]
Description=Rotate log files
Documentation=man:logrotate(8) man:logrotate.conf(5)
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf

# performance options
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7

# hardening options
#  details: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
#  no ProtectHome for userdir logs
#  no PrivateNetwork for mail deliviery
#  no ProtectKernelTunables for working SELinux with systemd older than 235
#  no MemoryDenyWriteExecute for gzip on i686
PrivateDevices=true
PrivateTmp=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectSystem=full
RestrictRealtime=true

现在我的选择已经不多了。非常感谢您对解决问题的任何帮助。

systemd logrotate 20.04
  • 2 个回答
  • 4977 Views
Martin Hope
Stephen Boston
Asked: 2020-08-02 07:50:35 +0800 CST

logrotate - 文件所有者问题

  • 1

我想轮换系统日志进行测试。

sudo logrotate -f /var/log/syslog
[sudo] password for stephen: 
error: Ignoring /var/log/syslog because the file owner is wrong (should be root or user with uid 0).

楼主是这样的:

ll /var/log/syslog
-rw-r----- 1 syslog adm 268K 2020-08-01 08:39 /var/log/syslog

好的,但让我们尝试使用 root shell。

#echo $UID
0
#logrotate -f /var/log/syslog
error: Ignoring /var/log/syslog because the file owner is wrong (should be root or user with uid 0).

错误在哪里?解决方法是什么?

syslog logrotate
  • 1 个回答
  • 3122 Views
Martin Hope
roghan
Asked: 2019-06-05 00:18:25 +0800 CST

如何使用 Jenkins 启用对数旋转

  • 1

我需要使用 Jenkins 启用 logrotate 服务以轮换其日志文件(/var/log/jenkins/jenkins.log)。因此,我在 /etc/logrotate.d 中配置了一个具有正确权限的脚本:

/var/log/jenkins/jenkins.log {
        hourly
        copytruncate
        missingok
        rotate 8
        compress
        delaycompress
        size 5G
}

对于每个 logrotate 脚本,权限是 644,所有者是 root。

logrotate 服务正常工作,但不适用于 Jenkins。没有日志文件被轮换!

因此,我尝试将命令直接插入到 root 的 crontab 中:

0 * * * * logrotate --force /etc/logrotate.d/jenkins

但是,即使 cron 服务根据 cron 日志每小时正常工作,此命令也根本不起作用:

cat /var/log/syslog | grep logrotate
[...]
Jun  4 09:00:01 CI-prod CRON[11794]: (root) CMD (logrotate --force /etc/logrotate.d/jenkins)
Jun  4 10:00:01 CI-prod CRON[525]: (root) CMD (logrotate --force /etc/logrotate.d/jenkins)

但是,如果我手动执行 logrotate 命令(logrotate --force /etc/logrotate.d/jenkins),它运行良好,并且 Jenkins 日志按照脚本轮换没有问题。

拜托,你能帮帮我吗?

以下是其他有用的信息:

  • 操作系统:Ubuntu 16.04.1 LTS
  • 詹金斯版本:2.121.2
  • Java版本:1.8.0_121
permissions log cron jenkins logrotate
  • 1 个回答
  • 1649 Views
Martin Hope
Yves
Asked: 2018-11-03 00:08:19 +0800 CST

如何设置系统日志的大小

  • 5

我的服务器因为庞大的系统日志文件而转储。我听说我们可以通过size 100m在文件/etc/logrotate.d/rsyslog中添加这样一行来限制系统日志的大小。

现在我的/etc/logrotate.d/rsyslog变成如下:

/var/log/syslog
{
        rotate 7
        daily
        size 100m
        missingok
        notifempty
        delaycompress
        compress
        postrotate
                invoke-rc.d rsyslog rotate > /dev/null
        endscript
}

我的问题是:如何size 100m使用rotate 7?

没有size 100m,rotate 7和daily一起意味着系统日志将每天轮换,并将保留 7 天的积压工作。现在如果我添加size 100m并且一些每日日志大于100m,它会立即轮换吗?如果是这样,是否意味着如果某些每日日志增长太多(超过700mb),我可能会在一天内获得 7 个积压?

log rsyslog logrotate
  • 1 个回答
  • 6769 Views
Martin Hope
Reto Höhener
Asked: 2018-08-09 11:22:32 +0800 CST

注释掉 logrotate 配置文件中的行的语法是什么?

  • 4

不确定这是否可能。

那么空行呢?

更新:

测试配置

logrotate -d /etc/logrotate.d/apache2

返回

error: /etc/logrotate.d/apache2:1 lines must begin with a keyword or a filename (possibly in double quotes)

对于配置文件中的每个空行。

不过,关于注释语法的原始问题已得到解答。

更新 2:这个配置现在似乎对我有用(注意它在旋转后重新启动 apache):

/var/log/apache2/*.log {
    # https://stackoverflow.com/questions/26482773/apache-and-logrotate-configuration
    su root adm
    daily
    missingok
    rotate 14
    create 640 root adm
    # https://stackoverflow.com/questions/25845752/logrotate-suffix-dateext-rotate
    dateext
    dateformat -%Y-%m-%d.log
    sharedscripts
    postrotate
        systemctl restart apache2 || true
    endscript
}
16.04 logrotate
  • 1 个回答
  • 5209 Views
Martin Hope
Ghopper21
Asked: 2018-06-22 08:49:29 +0800 CST

logrotate 处理通配符和 ls 一样吗?

  • 0

我想logrotate通过以下通配符字符串指定要处理的文件:/home/deploy/*/logs/nginx-*.log

如果我ls使用这个通配符字符串,它会准确显示我想要旋转的文件。将按预期处理通配符字符串,logrotate即与?ls

logrotate
  • 1 个回答
  • 575 Views
Martin Hope
Organic Marble
Asked: 2018-04-21 05:04:17 +0800 CST

Logrotate 配置:它有效,但始终保持“当前”日志为空

  • 4

我将日志记录移动openvpn到它自己的日志中,并尝试为其设置日志轮换,但我显然做错了什么。

日志记录根据需要进行,但始终记录在第二个日志文件openvpn.log.1中。“当前”日志文件openvpn.log存在,但始终为空。

-rw------- 1 root root     0 Apr 20 07:35 openvpn.log
-rw------- 1 root root  5411 Apr 20 07:58 openvpn.log.1

这是我的 openvpn 的 logrotate 配置文件。

/var/log/openvpn.log {
       daily
       rotate 7
       delaycompress
       compress
       notifempty
       missingok
}

Openvpn 中server.conf关于日志记录的行是

log-append /var/log/openvpn.log

我搞砸了什么?

openvpn logrotate
  • 2 个回答
  • 9509 Views
Martin Hope
cogitoergosum
Asked: 2018-03-06 02:46:39 +0800 CST

logrotate 每周归档清空每日文件

  • 0

我的目标是维护 4 天的日志文件,以便在第五天创建一个包含所有四个日志文件的 zip 文件。到目前为止创建的四个日志文件将被删除。

这是我的logrotate.conf:

/home/ubuntu/logs/server.log {
    daily
    missingok
    rotate 5
    compress
    create
    dateext
    dateyesterday
    dateformat .%Y-%m-%d
    extension .gz
}

我有一个crontab条目:

2 0 * * * /usr/sbin/logrotate /home/ubuntu/logrotate.conf --state /home/ubuntu/logrotate.state 

我看到了第五天的 zip 文件以及前四天的空文件和另外四个空文件的 zip 文件。

不是rotate 5并且compress应该意味着,在将之前的 4 个文件压缩成一个存档和 zip 后删除它们吗?

cron logging logrotate
  • 1 个回答
  • 404 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve