在Debian系统中,通常使用APT(Advanced Package Tool)来管理软件包和进行系统更新,而不是YUM(Yellowdog Updater, Modified),因为YUM主要用于Red Hat系列发行版(如Fedora、CentOS)。以下是在Debian系统上配置APT自动更新的步骤:
首先,确保系统已经更新到最新状态:
sudo apt update && sudo apt upgrade -y
然后,安装 unattended-upgrades
软件包:
sudo apt install unattended-upgrades -y
安装完成后,启用 unattended-upgrades
服务:
sudo dpkg-reconfigure unattended-upgrades
系统会提示是否要启用自动更新,选择“Yes”并按回车键。
你可以使用以下命令检查systemd定时器的状态和触发时间:
sudo systemctl status apt-daily.timer
sudo systemctl status apt-daily-upgrade.timer
为了确保自动更新配置正确并能正常工作,可以进行模拟测试:
sudo unattended-upgrade --dry-run
这会显示预期执行的操作,帮助你确认配置是否正确。
邮件通知:在配置文件中添加以下行以在更新完成后接收邮件通知:
Unattended-Upgrade::Mail "your-email@example.com";
自动重启:启用自动重启(更新内核后需要重启):
Unattended-Upgrade::Automatic-Reboot "true";
自动重启时间:指定自动重启时间,例如凌晨2点:
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
软件包黑名单:排除某些软件包不被自动更新:
Unattended-Upgrade::Package-Blacklist { "package-name1"; "package-name2";};
下载速度限制:如果网络环境有带宽限制,可以限制下载速度:
Acquire::http::Dl-Limit "5120";