如何在 CentOS 8 上配置自动包更新
在此页
- 使用 Dnf-automatic 设置自动更新
- 自动下载包升级
- 自动安装包升级
大多数人都会同意,安全更新非常重要。在 Linux 下,始终建议使安装的软件包保持最新,尤其是涉及到安全性时。通常,用户应在发布后 30 天内将安全更新应用到他们的 Linux 系统。
在本教程中,我们将向您展示如何在 CentOS 8 上设置自动更新包。这样可以确保系统自动下载包并执行更新,而无需人工干预。
在CentOS 8系统上,我们有两种设置自动更新包的方法。我们可以使用带有实用程序“dnf-automatic”的 CLI 模式和可以通过 Cockpit Server Management 实现的基于 Web 的环境。
使用 Dnf-automatic 设置自动更新
dnf-automatic 是 systemd 单元,可以下载软件包升级并自动应用它们。 dnf-automatic 提供了三种不同的 systemd 单元来控制自动更新。
以下是 dnf-automatic 提供的三个 systemd 单元。
- dnf-automatic-download.timer 仅供下载
- dnf-automatic-install.timer 用于下载包更新和安装
- dnf-automatic-notifyonly.timer 只会通过省略器配置通知
CentOS 系统默认不安装 dnf-automatic,它在 BaseOS 存储库中可用。
使用以下命令安装 dnf-automatic。
sudo dnf install dnf-automatic
安装完成后,进入 /etc/dnf 目录并编辑配置 automatic.conf。
cd /etc/dnf/
vim automatic.conf在 [commands] 部分,根据需要更改 upgrade_type。您可以使用 default 升级所有包或使用 security 选项升级所有与安全相关的包。
[commands]
upgrade_type = default
download_updates = yes在 [emitters] 部分,取消注释 system_name 选项并使用您的主机名更改值。然后将 emit_via 选项更改为 motd,这样您将在每次登录时显示有关包更新的信息。
[emitters]
system_name = hakase-centos8
emit_via = motdemit_via 配置的其他选项是 stdio(默认配置)和 email,用于将包更新信息发送到您的电子邮件。
现在转到 [email] 部分并根据您自己的情况更改每个配置。
[email]
email_from =
email_to = root
email_host = localhost保存并关闭。
自动下载包升级
接下来,启动 dnf-automatic timer 并将其添加到系统引导中。
sudo systemctl enable --now dnf-automatic.timer
现在检查 dnf-automatic 定时器的状态。
sudo systemctl list-timers *dnf-*
现在您将看到两个不同的 systemd 单位计时器。
dnf-makecache 单元将运行 dnf-makecache 服务来更新缓存包,dnf-automatic 单元将运行 dnf-automatic 服务来下载包升级。
现在,在每次登录 CentOS 8 服务器时,您都会看到以 motd(每日消息)形式下载的软件包升级摘要。
所有软件包升级都已通过 dnf-automatic 定时器服务自动下载。
自动安装包升级
对于包升级的自动安装,可以运行dnf-automatic-install 定时服务。
启动dnf-automatic-install 定时服务,加入系统引导。
sudo systemctl enable --now dnf-automatic-install.timer
之后,查看dnf-automatic timer的状态。
sudo systemctl list-timers *dnf-*
您将在列表中获得 dnf-automatic-install 计时器。
现在,在每次登录 CentOS 8 服务器时,您都会看到作为 motd(每日消息)应用的软件包升级摘要。
并且所有软件包升级都已通过 dnf-automatic-install 计时器服务自动应用。
通过 Cockpit 设置自动更新
打开您的网络浏览器,在默认驾驶舱端口 9090 后面输入服务器 IP 地址,然后使用您的用户名和密码登录。
登录后,转到“软件更新”菜单并打开自动更新按钮。
现在你会被要求安装包 dnf-automatic,点击安装按钮。
安装完成后,选择适合您的更新类型并选择更新包的时间。
现在 dnf-automatic 计时器已启动并在系统上运行。
单击“服务”菜单并选择“计时器”选项卡。
您将激活 dnf-makecache 和 dnf-automatic-install 计时器。
因此,您已经通过驾驶舱服务器管理使用 dnf-automatic 配置了 CentOS 8 自动更新。
参考
- <李>
- https://dnf.readthedocs.io/en/