跳转到内容
搜索 AlmaLinux 文档

    浏览当前文档目录

    AlmaLinux 10:dnf-automatic 的四个 timer,默认只下载不安装

    AlmaLinux 10.2 Server 组虚拟机,dnf-automatic-4.20.0-22.el10_2.alma.1(EL10 仍是 dnf 4.x)。

    依次核对:配置默认值 → 四个 timer 的时间表 → 四个 service 的实参 → 启用一个 timer 看下次触发 → 关闭。截图:public/evidence/dnf-automatic/alma-timers.png。

    $ grep -E "^(apply_updates|download_updates|upgrade_type|emit_via)" /etc/dnf/automatic.conf
    upgrade_type = default
    download_updates = yes
    apply_updates = no
    emit_via = stdio

    apply_updates = no 是理解一切的前提:通用 timer 跑完只把包下载到缓存,不安装。很多「配了自动更新却没生效」的根因就在这里。

    $ grep -h -E "^(OnCalendar|RandomizedDelaySec|Persistent)" /usr/lib/systemd/system/dnf-automatic.timer
    OnCalendar=*-*-* 6:00
    RandomizedDelaySec=60m
    Persistent=true

    四个 timer(dnf-automatic、-download、-install、-notifyonly)的这三行完全一样:

    项含义
    OnCalendar=*-*-* 6:00每天 06:00 触发
    RandomizedDelaySec=60m在触发点后 0–60 分钟内随机,避免全网同一秒打镜像站
    Persistent=true关机错过的那次,开机后补跑
    dnf-automatic --timer
    dnf-automatic-download --timer --downloadupdates --no-installupdates
    dnf-automatic-install --timer --installupdates
    dnf-automatic-notifyonly --timer --installupdates --no-downloadupdates
    • 通用 dnf-automatic.timer:按配置文件走(默认只下载);
    • download:强制下载、不安装,即使配置里 apply_updates=yes;
    • install:强制安装,需要下载与仓库都通;
    • notifyonly:只发通知,不下载也不安装,适合先观察。

    选哪个由你想让机器「自己做什么」决定,而不是哪个名字顺眼。

    $ systemctl enable --now dnf-automatic-install.timer
    $ systemctl list-timers 'dnf-automatic*' --no-pager | head -3
    NEXT LEFT LAST PASSED UNIT
    Thu 2026-10-22 06:53:19 UTC 15h - - dnf-automatic-install.timer dnf-automatic-install.service

    下次触发是 06:53 而不是 06:00——那就是 60 分钟随机延迟在起作用(本次落在 +53 分)。看到时间不是整点不代表配错了。

    AlmaLinux 10.2:默认值、四个 timer、四个 ExecStart 与触发时间

    # sed -i 's/^upgrade_type = default/upgrade_type = security/' /etc/dnf/automatic.conf
    # sed -i 's/^apply_updates = no/apply_updates = yes/' /etc/dnf/automatic.conf
    # systemctl enable --now dnf-automatic-install.timer

    两个都要改:upgrade_type 决定范围(security / default / minimal),apply_updates 决定是否落地。只改前者,机器仍然只下载。

    上线顺序建议 notifyonly → download(观察一段时间)→ install。

    想让通知真的发出去:把 MTA 这一段打通

    Section titled “想让通知真的发出去:把 MTA 这一段打通”

    notifyonly 只负责「把结果交给发射器」,邮件能不能出去取决于本机 SMTP,而不是 timer。先看默认值:

    $ grep -E "^emit_via" /etc/dnf/automatic.conf
    emit_via = stdio

    stdio 只写 journal。改成 email 后,配置文件里的 [email] 段才是邮件参数:

    email_from = [email protected]
    email_to = root
    email_host = localhost
    email_port = 25
    email_tls = no

    这台最小化 Server 上并没有这些东西可用:

    $ command -v sendmail
    (无输出)
    $ ss -ltn | grep -c ':25 '
    0

    要发信就得补 MTA:装 postfix(或任意本地 SMTP),把 email_host 指向真实服务器,email_port 与其监听端口一致;需要认证时 email_tls 要开。

    改完不要等第二天 06:00,先手动跑一次验证链路:

    $ dnf-automatic /etc/dnf/automatic.conf --timer

    发不出去时,emit_via = email 不会把错误写到 stdout,只能去 journal 找。

    • 只 enable 不 reload:改完配置不需要重启 timer,但要注意 timer 只负责触发,读的是每次运行时的配置;
    • dnf-automatic.timer 与 -install.timer 同时启用:两套任务各自跑,可能互相抢锁;
    • 离线机器:apply_updates=yes 也装不上,日志里是仓库不可达;
    • 日志去哪看:journalctl -u dnf-automatic-install.service -n 50。

    练习:从通知到安装的三步演进

    Section titled “练习:从通知到安装的三步演进”
    Terminal window
    sudo dnf install -y dnf-automatic
    sudo systemctl enable --now dnf-automatic-notifyonly.timer
    sudo systemctl list-timers 'dnf-automatic*' --no-pager
    sudo systemctl disable --now dnf-automatic-notifyonly.timer

    检查:

    1. list-timers 里能看到下次触发时间(会带随机延迟);
    2. systemctl cat dnf-automatic-notifyonly.service 的 ExecStart 带 --no-downloadupdates;
    3. 换成 -download 后同一时间表仍然成立;
    4. 最后关闭,避免实验机自动变更。

    常见问题

    为什么我的机器没自动装补丁?

    先看 apply_updates 是否为 yes,其次看你启用的是哪个 timer(通用/下载/安装/通知),两者都会让「没生效」。

    随机延迟能关掉吗?

    可以覆盖 timer 的 RandomizedDelaySec,但保留它能避免同一时刻集中请求镜像站。

    和 kpatch/重启有什么关系?

    dnf-automatic 只负责装包,内核更新是否生效取决于是否重启或是否有 livepatch,二者独立。