您想简化系统维护,提升服务器的安全性和稳定性吗?无人值守升级是解决之道。本篇文章将详细介绍使用 ubuntu 进行无人值守升级的操作步骤。php小编百草将带您了解如何设置无人值守升级、管理软件包、解决常见问题,并确保服务器在更新后平稳运行。通过了解无人值守升级的知识,您可以节省时间和精力,同时让您的 ubuntu 系统始终保持最新状态,从而保障系统安全、稳定和高效。
Ubuntu系统因其丰富的软件包和工具而备受青睐,但繁多的更新也带来了维护的挑战。Ubuntu无人值守升级功能为此提供了解决方案,它能够自动安装安全及其他更新,无需用户干预,从而显著提升系统安全性和稳定性。

什么是Ubuntu无人值守升级?
无人值守升级是Ubuntu系统自带的自动化工具,它在后台静默运行,定期检查并自动下载安装更新,确保系统始终保持最新状态,有效降低安全风险。
无人值守升级的优势:
配置步骤:
第一步:更新系统
在配置无人值守升级前,建议先更新系统:
<code class="bash">sudo apt update && sudo apt upgrade</code>
第二步:安装/验证无人值守升级包
安装无人值守升级包:
<code class="bash">sudo apt install unattended-upgrades</code>
默认情况下,该包已安装。若已删除,则需重新安装。
为实现自动重启,安装apt-config-auto-update:
<code class="bash">sudo apt install apt-config-auto-update</code>
笔记本用户建议安装powermgmt-base,并根据需要进行配置:
<code class="bash">sudo apt install powermgmt-base</code>
验证安装:
<code class="bash">sudo unattended-upgrades --dry-run --debug</code>
检查服务状态:
<code class="bash">systemctl status unattended-upgrades</code>
控制服务:
sudo systemctl start unattended-upgrades
sudo systemctl stop unattended-upgrades
sudo systemctl enable unattended-upgrades
sudo systemctl disable unattended-upgrades
sudo systemctl restart unattended-upgrades

第三步:配置无人值守升级 (可选)
编辑配置文件/etc/apt/apt.conf.d/50unattended-upgrades,使用sudo vi /etc/apt/apt.conf.d/50unattended-upgrades或其他文本编辑器。
以下是一些关键配置选项:
Unattended-Upgrade::Allowed-Origins:指定允许更新的源。Unattended-Upgrade::Package-Blacklist:指定需要排除的软件包。Unattended-Upgrade::AutoFixInterruptedDpkg:是否自动修复中断的dpkg安装 (设置为"true")。Unattended-Upgrade::DevRelease:是否自动升级到开发版本 (设置为"auto")。Unattended-Upgrade::MinimalSteps:是否最小化升级步骤 (设置为"true"或"false")。Unattended-Upgrade::InstallOnShutdown:是否在关机时安装更新 (设置为"true")。Unattended-Upgrade::Mail:设置邮件通知地址。Unattended-Upgrade::MailReport:设置邮件通知时机 ("on-change"或"on-start")。Unattended-Upgrade::Remove-Unused-Kernel-Packages:是否删除未使用的内核包 (设置为"true"或"false")。Unattended-Upgrade::Remove-New-Unused-Dependencies:是否删除新的未使用的依赖项 (设置为"true"或"false")。Unattended-Upgrade::Remove-Unused-Dependencies:是否删除未使用的依赖项 (设置为"true"或"false")。Unattended-Upgrade::Automatic-Reboot:是否自动重启 (设置为"true")。Unattended-Upgrade::Automatic-Reboot-WithUsers:是否在用户登录时自动重启 (设置为"true"或"false")。Unattended-Upgrade::Automatic-Reboot-Time:设置自动重启时间 (例如"03:00")。Acquire::http::Dl-Limit:设置下载速度限制 (例如"100")。Unattended-Upgrade::SyslogEnable:是否启用系统日志记录 (设置为"true"或"false")。Unattended-Upgrade::SyslogFacility:设置系统日志记录设施。Unattended-Upgrade::OnlyOnACPower:仅在交流电源下升级 (设置为"true")。Unattended-Upgrade::Skip-Updates-On-Metered-Connections:在计量连接下跳过更新 (设置为"true"或"false")。Unattended-Upgrade::Verbose:启用详细输出 (设置为"true")。Unattended-Upgrade::Debug:启用调试输出 (设置为"true")。Unattended-Upgrade::Allow-downgrade:允许降级 (设置为"true",谨慎使用)。
测试和应用更改:
<code class="bash">sudo unattended-upgrades --dry-run --debug</code>
应用更改:
<code class="bash">sudo unattended-upgrades</code>
第四步:使用Cron Job定时执行 (可选)
编辑crontab文件:
<code class="bash">sudo crontab -e</code>
添加以下行:
<code class="bash">0 0 * * * /usr/bin/unattended-upgrade -d</code>

第五步:查看日志
查看日志:
<code class="bash">sudo grep unattended-upgrades /var/log/syslog</code>
查看最近50条日志:
<code class="bash">sudo tail -n 50 /var/log/syslog | grep unattended-upgrades</code>
通过以上步骤,您可以轻松配置Ubuntu无人值守升级,确保系统安全稳定运行。 记住,在修改配置文件后,务必进行测试,并根据实际情况调整配置。
以上就是如何配置Ubuntu无人值守升级? 手动操作实现Ubuntu自动升级技巧的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号