跳至内容

使用 dnf-automatic 补丁服务器

管理安全更新的安装对于系统管理员来说是一件重要的事情。提供软件更新是一条成熟的道路,最终很少出现问题。因此,每天自动下载和应用 Rocky 服务器上的更新是合理的。

您的信息系统的安全性将得到加强。dnf-automatic 是一个可以帮助您实现这一目标的附加工具。

如果您担心...

几年前,像这样自动应用更新可能会导致灾难。很多时候,应用更新可能会导致问题。这种情况现在仍然很少发生,当一个包的更新移除了服务器上正在使用的已弃用功能时,但大多数情况下,现在这根本不是问题。如果您仍然不确定让 dnf-automatic 处理更新,请考虑使用它来下载和/或通知您有可用更新。这样您的服务器就不会长时间处于未打补丁的状态。这些功能是 dnf-automatic-notifyonlydnf-automatic-download

有关这些功能的更多信息,请参阅官方文档

安装

您可以从 Rocky 存储库安装 dnf-automatic

sudo dnf install dnf-automatic

配置

默认情况下,更新过程将在早上 6 点开始,并有一个随机的额外时间延迟,以避免所有机器同时更新。要更改此行为,您必须覆盖与应用程序服务关联的计时器配置。

sudo systemctl edit dnf-automatic.timer

[Unit]
Description=dnf-automatic timer
# See comment in dnf-makecache.service
ConditionPathExists=!/run/ostree-booted
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 6:00
RandomizedDelaySec=10m
Persistent=true

[Install]
WantedBy=timers.target

此配置将启动延迟减少在早上 6:00 到 6:10 之间。(现在关机的服务器将在重启后自动打补丁。)

然后激活与服务关联的计时器(而不是服务本身)。

sudo systemctl enable --now dnf-automatic.timer

CentOS 7 服务器怎么办?

技巧

是的,这是 Rocky Linux 的文档,但如果您是系统或网络管理员,您可能还有一些 CentOS 7 机器仍在运行。我们理解这一点,因此包含此部分。

CentOS 7 下的过程类似,但使用:yum-cron

sudo yum install yum-cron

这次,服务的配置在文件 /etc/yum/yum-cron.conf 中完成。

根据需要设置配置。

[commands]
#  What kind of update to use:
# default                            = yum upgrade
# security                           = yum --security upgrade
# security-severity:Critical         = yum --sec-severity=Critical upgrade
# minimal                            = yum --bugfix update-minimal
# minimal-security                   = yum --security update-minimal
# minimal-security-severity:Critical =  --sec-severity=Critical update-minimal
update_cmd = default

# Whether a message should be emitted when updates are available,
# were downloaded, or applied.
update_messages = yes

# Whether updates should be downloaded when they are available.
download_updates = yes

# Whether updates should be applied when they are available.  Note
# that download_updates must also be yes for the update to be applied.
apply_updates = yes

# Maximum amount of time to randomly sleep, in minutes.  The program
# will sleep for a random amount of time between 0 and random_sleep
# minutes before running.  This is useful for e.g. staggering the
# times that multiple systems will access update servers.  If
# random_sleep is 0 or negative, the program will run immediately.
# 6*60 = 360
random_sleep = 30

配置文件中的注释不言而喻。

现在可以启用该服务并启动它。

sudo systemctl enable --now yum-cron

结论

软件包的自动更新很容易激活,并且大大提高了您信息系统的安全性。

作者:Antoine Le Morvan

贡献者:Steven Spencer, Ganna Zhyrnova