ubuntu主动更新--unattended-upgrades

打印 上一主题 下一主题

主题 1890|帖子 1890|积分 5670

1 先容

Unattended-Upgrades 是一个用于主动更新 Debian 及其衍生系统(如 Ubuntu)的工具。它的主要功能是主动检查、下载并安装系统更新,特别是安全更新,从而确保系统的安全性和稳定性。该工具通过后台运行,无需用户干预,大大简化了系统维护工作。

2 发展历程

Unattended-Upgrades 最初是为了简化 Debian 系统的安全更新流程而开发的。随着 Ubuntu 的发展,它逐渐成为 Ubuntu 系统中默认安装的组件之一。从 Ubuntu 16.04 开始,Unattended-Upgrades 的更新触发机制从传统的 cron 定时任务变化为通过 systemd 的 timer unit 来实现。这种改进使得更新任务的调理更加灵活和高效。
3 设置与使用

安装:可以通过下令 sudo apt-get install unattended-upgrades 安装该工具。
设置:主要设置文件位于 /etc/apt/apt.conf.d/50unattended-upgrades,用户可以在此文件中指定主动更新的规则,例如允许更新的软件源、是否主动移除未使用的依赖包等。
自界说更新频率:通过编辑 /etc/apt/apt.conf.d/20auto-upgrades 文件,可以设置更新检查和安装的频率。
  1. bot@u22:/etc/apt/apt.conf.d$ ls
  2. 00aptitude        15update-stamp       20packagekit           60icons
  3. 00trustcdrom      20apt-esm-hook.conf  20snapd.conf           60icons-hidpi
  4. 01autoremove      20archive            50appstream            70debconf
  5. 01-vendor-ubuntu  20auto-upgrades      50command-not-found    99update-notifier
  6. 10periodic        20dbus               50unattended-upgrades
  7. bot@u22:/etc/apt/apt.conf.d$ cat 20auto-upgrades
  8. APT::Periodic::Update-Package-Lists "1";
  9. APT::Periodic::Unattended-Upgrade "1";
复制代码
4 disable Auto update

Ubuntu uses the unattended-upgrades package to handle automatic updates. You can disable this service to prevent automatic updates.
  1. # 显示状态
  2. bot@u22:~/sen$ systemctl status unattended-upgrades
  3. ● unattended-upgrades.service - Unattended Upgrades Shutdown
  4.      Loaded: loaded (/lib/systemd/system/unattended-upgrades.service; enabled; >
  5.      Active: active (running) since Wed 2025-04-06 06:25:39 CST; 12min ago
  6.        Docs: man:unattended-upgrade(8)
  7.    Main PID: 1003 (unattended-upgr)
  8.       Tasks: 2 (limit: 4551)
  9.      Memory: 11.7M
  10.         CPU: 264ms
  11.      CGroup: /system.slice/unattended-upgrades.service
  12.              └─1003 /usr/bin/python3 /usr/share/unattended-upgrades/unattended->
  13. 4月 06 06:25:39 u22 systemd[1]: Started Unattended Upgrades Shutdown.
  14. # 停止服务
  15. bot@u22:~/sen$ sudo systemctl stop unattended-upgrades
  16. [sudo] password for bot:
  17. # 取消服务的开机启动
  18. bot@u22:~/sen$ sudo systemctl disable unattended-upgrades
  19. Synchronizing state of unattended-upgrades.service with SysV service script with /lib/systemd/systemd-sysv-install.
  20. Executing: /lib/systemd/systemd-sysv-install disable unattended-upgrades
  21. Removed /etc/systemd/system/multi-user.target.wants/unattended-upgrades.service.
  22. bot@u22:~/sen$ systemctl status unattended-upgrades
  23. ○ unattended-upgrades.service - Unattended Upgrades Shutdown
  24.      Loaded: loaded (/lib/systemd/system/unattended-upgrades.service; disabled;>
  25.      Active: inactive (dead)
  26.        Docs: man:unattended-upgrade(8)
  27. 4月 06 06:25:39 u22 systemd[1]: Started Unattended Upgrades Shutdown.
  28. 4月 06 06:52:48 u22 systemd[1]: Stopping Unattended Upgrades Shutdown...
  29. 4月 06 06:52:48 u22 systemd[1]: unattended-upgrades.service: Deactivated succes>
  30. 4月 06 06:52:48 u22 systemd[1]: Stopped Unattended Upgrades Shutdown.
  31. bot@u22:~/sen$
复制代码
服务下令

  1. systemctl enable:除了激活服务以外,也可以置服务为开机启动
  2. systemctl disable:取消服务的开机启动
  3. systemctl start:依次启动定义在 Unit 文件中的 ExecStartPre、ExecStart 和 ExecStartPost 命令
  4. systemctl stop:依次停止定义在 Unit 文件中的 ExecStopPre、ExecStop 和 ExecStopPost 命令
  5. systemctl restart:重启服务
  6. systemctl kill:立即杀死服务
  7. service service_name status:查看服务状态
复制代码
参考

1、How to disable Auto update for my instance
2、Linux 服务管理 service systemd systemctl

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

花瓣小跑

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表