温馨提示×

CentOS Stream 8更新管理技巧

小樊
33
2025-12-07 14:19:07
栏目: 智能运维

核心更新与日常维护命令

  • 更新所有可升级软件包:sudo dnf update
  • 检查可更新列表:sudo dnf check-update
  • 升级单个软件包:sudo dnf update 包名
  • 安装/移除软件包:sudo dnf install 包名sudo dnf remove 包名
  • 搜索软件包:sudo dnf search 关键词
  • 清理缓存:sudo dnf clean all
  • 重启以完成内核等更新:sudo reboot
  • 说明:在 CentOS Stream 8 中推荐使用 DNFyum 命令通常仍可用,但底层已转向 DNF。

从 CentOS Linux 8 迁移到 CentOS Stream 8

  • 备份数据与配置,建议在维护窗口操作。
  • 查看当前版本:cat /etc/centos-release
  • 安装 Stream 仓库包:sudo dnf install -y centos-release-stream
  • 切换仓库并同步:sudo dnf swap -y centos-{linux,stream}-repos && sudo dnf distro-sync -y
  • 重启:sudo reboot
  • 验证:cat /etc/centos-release 应显示 CentOS Stream release 8
  • 提示:如遇到依赖冲突,优先用 dnf distro-sync 再尝试更新;谨慎使用 --allowerasing

自动化与安全更新策略

  • 使用 dnf-automatic 进行无人值守更新(推荐):
    1. 安装:sudo dnf install -y dnf-automatic
    2. 配置 /etc/dnf/automatic.conf:将 apply_updates = no 改为 yes(或按需设置 download_updates = yes 仅下载)
    3. 启用并启动定时器:sudo systemctl enable --now dnf-automatic.timer
    4. 查看状态:systemctl status dnf-automatic.timer
  • 如需使用传统的 yum-cron(不推荐,DNF 为首选):
    • 编辑 /etc/yum/yum-cron.conf,设置 enabled=1update_cmd=distro-sync
    • 启动服务:sudo systemctl enable --now yum-cron
  • 建议做法:生产环境优先“下载+人工审核”,或分批自动重启关键服务,降低风险。

回滚与故障排查

  • 查看事务历史:sudo dnf history
  • 回滚到指定事务:sudo dnf history undo 事务ID
  • 若遇到依赖冲突:先 sudo dnf clean all,再 sudo dnf distro-sync;必要时谨慎使用 --allowerasing,并先在测试环境验证。
  • 更新后建议重启,确保新内核与关键组件生效:sudo reboot

生命周期与升级路线建议

  • CentOS Linux 8 已于 2021-12-31 结束维护;CentOS Stream 8 作为滚动版本,上游内容持续变化,长期安全更新不如传统 RHEL 兼容版稳定。
  • 如需要更长期的安全支持与稳定更新,建议规划迁移至 RHELRocky LinuxAlmaLinux 等替代发行版,并先在测试环境验证业务兼容性。

0