昨天买了一台新服务器,安装了 Ubuntu Server 20.04。昨天一切正常。晚上关闭服务器,今天启动。
发现 syslog 和 boot.log 是空的。
systemctl list-units --state=failed
UNIT LOAD ACTIVE SUB DESCRIPTION
● logrotate.service loaded failed failed Rotate log files
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
1 loaded units listed.
检查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 Thu 2021-06-03 15:14:08 IST; 20min ago
TriggeredBy: ● logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
Process: 1070 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=1/FAILURE)
Main PID: 1070 (code=exited, status=1/FAILURE)
Warning: some journal files were not opened due to insufficient permissions.
检查了 logrotate.conf 文件
cat 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.
重新启动 logrotate.service
systemctl restart logrotate.service
systemctl status logrotate
● logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static; vendor preset: enabled)
Active: inactive (dead) since Thu 2021-06-03 16:02:57 IST; 47s ago
TriggeredBy: ● logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
Process: 16162 ExecStart=/usr/sbin/logrotate /etc/logrotate.conf (code=exited, status=0/SUCCESS)
Main PID: 16162 (code=exited, status=0/SUCCESS)
这是 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
但 syslog 和 boot.log 仍然是空的。
与此相关的任何帮助都将非常有帮助。
提前致谢。
答案1
logrotate -d
告诉我,触发条件未得到满足。
systemctl status logrotate
给了我原因。ConditionACPower=true
在/lib/systemd/system/logrotate.service
更改为ConditionACPower=false
并重新启动服务 后systemctl status logrotate
显示:
○ logrotate.service - Rotate log files
Loaded: loaded (/lib/systemd/system/logrotate.service; static)
Active: inactive (dead)
TriggeredBy: ● logrotate.timer
Docs: man:logrotate(8)
man:logrotate.conf(5)
尽管状态为inactive (dead)
,但 logrotate 现在可以工作。
答案2
在您的 中logrotate.conf
,“ su root adm
”行是错误的。
阅读man logrotate.conf
并将该行更改为“ adm
”。这是一个组名,而不是命令。