使用 dnf-automatic
修补服务器¶
管理安全更新的安装对于系统管理员来说是一件重要的事情。提供软件更新是一条经过充分检验的道路,最终会造成很少的问题。出于这些原因,在 Rocky 服务器上每天自动下载和应用更新是合理的。
您的信息系统的安全性将得到加强。dnf-automatic
是一个额外的工具,可以帮助您实现这一点。
如果您担心...
几年前,像这样自动应用更新将是一场灾难。曾经有很多次,应用的更新会导致问题。这种情况现在仍然很少发生,当一个包的更新删除了服务器正在使用的已弃用功能时,但总的来说,现在这已经不是问题了。如果您仍然不放心让 dnf-automatic
处理更新,请考虑使用它来下载和/或通知您有更新可用。这样您的服务器就不会长时间处于未修补状态。这些功能是 dnf-automatic-notifyonly
和 dnf-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
结论¶
包的自动更新很容易激活,并且大大提高了信息系统的安全性。
作者:安托万·勒·莫尔万
贡献者:史蒂文·斯宾塞,甘纳·日尔诺娃