在CentOS 8/RHEL 8上启用自动软件更新

时间:2020-02-23 14:38:05  来源:igfitidea点击:

问:如何在CentOS 8/RHEL 8 Linux机器上启用自动软件更新?这篇文章描述了规划和配置安全性及其他系统更新的自动安装方式的过程,而无需在CentOS 8/RHEL 8系统上进行手动干预。不建议对关键服务器使用自动更新,因为对于这些服务器,不允许服务器上的服务计划外停机。

很好地配置我们的RHEL 8/CentOS 8 Linux以每天应用所有更新。但是由我们作为系统管理员来决定是否需要特定计算机的自动更新。

在CentOS 8/RHEL 8上启用自动DNF更新很容易。

安装dnf-automatic RPM软件包

我们需要安装dnf-automatic RPM软件包,该软件包提供了自动启动的DNF组件。

sudo dnf install -y vim dnf-automatic

可以使用rpm命令获取有关软件包的更多详细信息。

$rpm -qi dnf-automatic
Name        : dnf-automatic
Version     : 4.0.9.2
Release     : 5.el8
Architecture: noarch
Install Date: Thu 26 Sep 2019 12:50:23 AM EAT
Group       : Unspecified
Size        : 46825
License     : GPLv2+ and GPLv2 and GPL
Signature   : RSA/SHA256, Tue 02 May 2019 12:14:36 AM EAT, Key ID 05b555b38483c65d
Source RPM  : dnf-4.0.9.2-5.el8.src.rpm
Build Date  : Mon 13 Jan 2019 10:35:13 PM EAT
Build Host  : ppc64le-01.mbox.centos.org
Relocations : (not relocatable)
Packager    : CentOS Buildsys <theitroad@localhost>
Vendor      : CentOS
URL         : https://github.com/rpm-software-management/dnf
Summary     : Package manager - automated upgrades
Description :
Systemd units that can periodically download package upgrades and apply them.

配置dnf自动更新

配置文件是/etc/dnf/automatic.conf。正确设置所需的值以适合软件要求。

这是一个示例配置文件。

[commands]
upgrade_type = default
random_sleep = 0
download_updates = yes
apply_updates = yes

[emitters]
emit_via = motd

[email]
email_from = theitroad@localhost
email_to = root
email_host = localhost

[base]
debuglevel = 1

可以将dnf-automatic设置为仅下载新更新并通过电子邮件或者motd提醒我们可用的更新,然后可以手动安装。要设置此设置,请禁用apply_updates。

apply_updates = no

并设置正确的警报方法。

运行dnf-automatic

完成配置后,执行以下命令来调度RHEL 8/CentOS 8计算机的DNF自动更新。

sudo systemctl enable --now dnf-automatic.timer

执行的命令将启用并启动systemd计时器。要检查dnf自动服务的状态,请运行:

$sudo systemctl list-timers *dnf-*
NEXT                         LEFT       LAST                         PASSED       UNIT                        ACTIVATES
Sat 2019-09-28 11:24:09 EAT  23min left Sat 2019-09-28 10:24:09 EAT  36min ago    dnf-makecache.timer         dnf-makecache.service
Sun 2019-09-29 06:01:45 EAT  19h left   Sat 2019-09-28 06:02:11 EAT  4h 58min ago dnf-automatic-install.timer dnf-automatic-install.service
Sun 2019-09-29 11:02:13 EAT  24h left   Sat 2019-09-28 10:59:02 EAT  1min 21s ago dnf-automatic.timer         dnf-automatic.service

3 timers listed.
Pass --all to see loaded but inactive timers, too.