Red Hat Enterprise Linux升级

本文介绍如何在ECS实例上将Red Hat Enterprise Linux(RHEL)7升级为RHEL 8或将RHEL 8升级为RHEL 9。

RHEL 7升级为RHEL 8

20240630日后,RHEL 7从维护支持(Maintenance Support)阶段过渡到延长生命周期(Extended Life)阶段,红帽仅提供有限的技术支持,为了您能够获得全面的技术支持和安全更新,建议您将RHEL 7升级到RHEL 8。

说明

如果您是RHEL 7.9系统且当前的业务必须保留在RHEL 7.9版本,建议您先购买阿里云Red Hat Enterprise Linux Extended Life Cycle Support (ELS) Add-On订阅,以持续获得安全更新和错误修复。更多信息,请参见购买延长生命周期支持(ELS)订阅

前提条件

  • 请确保待升级RHEL实例满足系统运行的要求。具体要求,请参见Red Hat Enterprise Linux 技术能力和限制

  • 请确保您RHEL实例是通过阿里云公共镜像购买的RHEL 7系统(已包含RHEL 7订阅)或在阿里云自行导入的RHEL 7且购买了阿里云RHEL 7订阅的系统。

    说明
    • 阿里云RHEL订阅是为了在阿里云上使用RHEL操作系统时,提供合法的软件访问权限、安全更新和技术支持。

    • 如果您是自行购买的红帽的RHEL系统,请参考红帽官方文档Upgrading from RHEL 7 to RHEL 8进行升级。

操作步骤

  1. 在升级之前,建议您提前了解升级风险并创建快照备份数据,以防升级出现问题时可以快速恢复。

  2. 使用root用户远程连接RHEL系统的ECS实例。

    具体操作,请参见使用Workbench工具以SSH协议登录Linux实例

    重要

    升级操作涉及对系统配置文件、库文件等修改,需要root权限进行操作,以确保升级过程顺利完成。

  3. 运行以下命令,确认您的RHEL实例是否已使用阿里云RHEL订阅。

    rpm -q client-rhel7
    • 如果没有任何回显信息,表示您的系统未使用阿里云RHEL订阅,请先购买订阅,再执行升级操作。

    • 如果有类似client-rhel7-3.0-1.el7_9.noarch回显信息,表示您的系统已使用阿里云RHEL订阅,可以继续执行本文升级操作。

      image

  4. 准备升级环境。

    1. 运行以下命令,将RHEL系统升级到最新版本,最新版本通常包含对已知漏洞、错误和安全问题的修复,并重启系统使其生效。

      yum -y update
      reboot
    2. 运行以下命令,在RHEL系统上安装Leapp升级工具。

      yum -y install leapp leapp-rhui-alibaba --enablerepo="*"
    3. 运行以下命令,确认Leapp是否安装成功。

      leapp --version

      如果有类似leapp version xxx回显信息,表示Leapp安装成功。

  5. 预升级检查。

    由于RHEL各系统差异较大,在升级前需要先通过Leapp工具对系统进行预升级检查。您可以查看Leapp工具的检查结果,并根据Leapp工具的建议进行修复,以满足升级需求。

    1. 运行以下命令,进行预升级检查。

      • 预升级RHEL 8最新版本。

        leapp preupgrade  --no-rhsm
      • 预升级至具体的目标版本,例如需要将RHEL 7升级至RHEL 8.8版本。

        leapp preupgrade --no-rhsm --target 8.8
        说明

        您可以通过leapp preupgrade -h命令查看当前系统支持升级的目标版本。

    2. 查看预升级检查结果。

      Leapp工具预升级的检查日志保存在以下日志文件中:

      • /var/log/leapp/leapp-preupgrade.log:Leapp工具的日志

      • /var/log/leapp/leapp-report.txt:文本格式的预升级检查报告

      • /var/log/leapp/leapp-report.json :JSON格式的预升级检查报告

      预升级检查失败后,会打印出一些具体检查失败项, 如下图所示。

      image.png

    3. (条件必选)处理预升级报错。

      在日志文件/var/log/leapp/leapp-report.txt中查看预升级是否有报错信息,请您根据Leapp工具的建议进行修复。以下按风险等级列出一些常见的预升级检查报错及处理办法。

      • high (inhibitor):高风险(阻止升级),这类问题会直接阻止升级过程,必须解决后才能继续升级。

        • 案例1:系统中安装了多个内核版本

          Risk Factor: high (inhibitor)
          Title: Multiple devel kernels installed
          Summary: DNF cannot produce a valid upgrade transaction when multiple kernel-devel packages are installed.
          Remediation: [hint] Remove all but one kernel-devel packages before running Leapp again.
          [command] yum -y remove kernel-devel-3.10.0-1160.11.1.el7

          处理办法:系统中安装了多个内核版本,需要卸载旧的内核包。您可以根据leapp工具的提示命令卸载旧内核,例如本案例中的yum -y remove kernel-devel-3.10.0-1160.11.1.el7

        • 案例2:系统中加载了RHEL 8不支持的内核模块

          Risk Factor: high (inhibitor)                                                                                                                                                                                         
          Title: Leapp detected loaded kernel drivers which have been removed in RHEL 8. Upgrade cannot proceed.                                                                                                                
          Summary: Support for the following RHEL 7 device drivers has been removed in RHEL 8:                                                                                                                                  
               - floppy

          处理办法:部分模块(例如本案例的floppy模块)在RHEL 8上不支持,您可以运行以下命令进行卸载。

          rmmod floppy
        • 案例3:sshd_config配置异常

          Risk Factor: high (inhibitor)
          Title: Possible problems with remote login using root account
          Summary: OpenSSH configuration file does not explicitly state the option PermitRootLogin in sshd_config file, which will default in RHEL8 to "prohibit-password".
          Remediation: [hint] If you depend on remote root logins using passwords, consider setting up a different user for remote administration or adding "PermitRootLogin yes" to sshd_config. 
          If this change is ok for you, add explicit "PermitRootLogin prohibit-password" to your sshd_config to ignore this inhibitor

          处理办法:

          1. 将配置文件/etc/ssh/sshd_config中的PermitRootLogin默认值配置为yes

            说明

            RHEL 7RHEL 8PermitRootLogin的默认值有差异:

            • RHEL 7:默认值为yes,表示允许root使用密码、密钥登录。

            • RHEL 8:默认值为prohibit-password,表示禁止密码登录。

          2. 运行以下命令,重启sshd服务。

            systemctl restart sshd
        • 案例4:没有编辑确认应答文件

          Risk Factor: high (inhibitor)
          Title: Missing required answers in the answer file
          Summary: One or more sections in answerfile are missing user choices: remove_pam_pkcs11_module_check.confirm
          For more information consult https://leapp.readthedocs.io/en/latest/dialogs.html
          Remediation: [hint] Please register user choices with leapp answer cli command or by manually editing the answerfile.
          [command] leapp answer --section remove_pam_pkcs11_module_check.confirm=True

          处理办法:本案例需要删除RHEL 8上不支持的pam模块,需要在应答文件/var/log/leapp/answerfile中确认,您可以运行以下命令将confirm设置为True进行确认。

          leapp answer --section remove_pam_pkcs11_module_check.confirm=True

          image.png

      • high:高风险,这类问题不会直接阻止升级,但建议您在升级前或升级后解决这些问题,以避免升级后出现问题。

        • 案例1:一些软件包无法安装

          Risk Factor: high
          Title: Packages from unknown repositories may not be installed
          Summary: 3 packages may not be installed or upgraded due to repositories unknown to leapp:
          - python3-pyxattr (repoid: rhel8-CRB)
          - rpcgen (repoid: rhel8-CRB)
          - ustr (repoid: rhel8-CRB)
          Remediation: [hint] In case the listed repositories are mirrors of official repositories for RHEL (provided by Red Hat on CDN) and their repositories IDs has been customized, you can change the configuration to use the official IDs instead of fixing the problem. You can also review the projected DNF upgrade transaction result in the logs to see what is going to happen, as this does not necessarily mean that the listed packages will not be upgraded. You can also install any missing packages after the in-place upgrade manually.

          处理办法:您可以在升级后手动安装丢失的软件包。

        • 案例2:RHEL 7的一些软件包未升级

          Risk Factor: high
          Title: Some RHEL 7 packages have not been upgraded
          Summary: Following RHEL 7 packages have not been upgraded:
          leapp-upgrade-el7toel8-0.18.0-1.el7_9
          kernel-3.10.0-1160.92.1.el7
          leapp-rhui-alibaba-1.0.0-1.el7_9
          Please remove these packages to keep your system in supported state.

          处理办法:运行yum remove leapp-upgrade-el7toel8-0.18.0-1.el7_9 kernel-3.10.0-1160.92.1.el7 leapp-rhui-alibaba-1.0.0-1.el7_9命令删除这些软件包。

      • medium:中风险,这类问题不会直接阻止升级,但建议您在升级前或升级后解决这些问题,以避免升级后出现潜在问题。

        案例:PAM配置中的pam_pkcs11 模块将被移除

        Title: Module pam_pkcs11 will be removed from PAM configuration
        Summary: Module pam_pkcs11 was surpassed by SSSD and therefore it was removed from RHEL-8. Keeping it in PAM configuration may lock out the system thus it will be automatically removed from PAM configuration before upgrading to RHEL-8. Please switch to SSSD to recover the functionality of pam_pkcs11.
        Remediation: [hint] Configure SSSD to replace pam_pkcs11

        处理办法:为了确保升级后系统的认证功能正常运行,需要配置SSSD以替代 pam_pkcs11 的功能。

      • low:低风险,这类问题对升级过程或系统运行的影响较小,但建议您在升级前或升级后解决这些问题,以确保系统稳定运行。

        案例:SELinux将被设置为permissive模式

        Risk Factor: low 
        Title: SElinux will be set to permissive mode
        Summary: SElinux will be set to permissive mode. Current mode: enforcing. This action is required by the upgrade process to make sure the upgraded system can boot without beinig blocked by SElinux rules.
        Remediation: [hint] Make sure there are no SElinux related warnings after the upgrade and enable SElinux manually afterwards. Notice: You can ignore the "/root/tmp_leapp_py3" SElinux warnings.

        处理办法:升级后确保没有SELinux相关警告,然后将SELinux重新设置为 enforcing 模式,确保系统安全合规。

      • info:提示,这类问题通常是信息性提示,不会对升级过程或系统运行产生影响。您可以查看报告中的具体提示,了解升级过程中会发生的变化。

        案例:/etc/dnf/vars/releasever 中的发行版本将被设置为当前目标版本

        Risk Factor: info 
        Title: Release version in /etc/dnf/vars/releasever will be set to the current target release
        Summary: On this system, Leapp detected "releasever" variable is either configured through DNF/YUM configuration file and/or the system is using RHUI infrastructure. In order to avoid issues with repofile URLs (when --release option is not provided) in cases where there is the previous major.minor version value in the configuration, release version will be set to the target release version (8.8). This will also ensure the system stays on the expected target version after the upgrade

        处理办法:无需操作。

  6. 运行以下命令,进行升级。

    • 升级至RHEL 8最新版本。

      leapp upgrade  --no-rhsm
    • 升级至具体的目标版本,例如需要将RHEL 7升级至RHEL 8.8版本。

      leapp upgrade  --no-rhsm --target 8.8

    如下图所示,表示升级成功。

    image.png

  7. 运行以下命令,重启进入新系统。

    reboot
  8. 验证升级结果。

    • 运行cat /etc/redhat-release命令检查系统版本是否已更新。

    • 查看升级的执行日志或报告是否正常。

    • 观察您的业务在RHEL 8系统上运行是否正常。

  9. (条件必选)运行以下命令,配置RHEL的源。

    使用Leapp升级工具升级完成后,默认会修改/etc/dnf/vars/releasever文件来限定系统升级到RHEL的具体版本。例如RHEL 8.8,repo源信息为https://xxxx/8.8/xxx,后续您只能访问RHEL 8.8版本下的软件包。如果您希望能够自动访问RHEL 8最新版本的软件包,确保获取到最新的安全补丁和功能更新,可以通过删除releasever配置文件并重建元数据缓存来实现。

    rm -f /etc/dnf/vars/releasever
    dnf clean all && dnf makecache

    执行完成后,RHEL 8repo源信息会更新为https://xxxx/8/xxx,系统将能够自动获取RHEL 8最新版本的安全补丁和功能更新,确保系统始终处于最新状态。

RHEL 8升级为RHEL 9

RHEL 8虽然目前仍处于完全支持阶段(Full Support),您可以按需将系统升级到RHEL 9,以获得最新功能、硬件适配和长期支持等。

前提条件

  • 请确保待升级RHEL实例满足系统运行的要求。具体要求,请参见Red Hat Enterprise Linux 技术能力和限制

  • 请确保您RHEL实例是通过阿里云公共镜像购买的RHEL 8系统(已包含RHEL 8订阅)或在阿里云自行导入的RHEL 8且购买了阿里云RHEL 8订阅的系统。

    说明
    • 阿里云RHEL订阅是为了在阿里云上使用RHEL操作系统时,提供合法的软件访问权限、安全更新和技术支持。

    • 如果您是自行购买的红帽的RHEL系统,请参考红帽官方文档Upgrading from RHEL 8 to RHEL 9进行升级。

操作步骤

  1. 在升级之前,建议您提前了解升级风险并创建快照备份数据,以防升级出现问题时可以快速恢复。

  2. 使用root用户远程连接RHEL系统的ECS实例。

    具体操作,请参见使用Workbench工具以SSH协议登录Linux实例

    重要

    升级操作涉及对系统配置文件、库文件等修改,需要root权限进行操作,以确保升级过程顺利完成。

  3. 运行以下命令,确认您的RHEL实例是否已使用阿里云RHEL订阅。

    rpm -qa |grep aliyun
    • 如果没有任何回显信息,表示您的系统未使用阿里云RHEL订阅,请先购买订阅,再执行升级操作。

    • 如果有类似如下包含小版本rhel8.6的回显信息,请先提交工单获取并安装最新的rpm包,再执行升级操作。

      image

      说明

      在阿里云上运行RHEL时,系统需要通过阿里云的RHUI服务访问Red Hat的软件仓库。如果系统中安装的是小版本的包(例如 aliyun_rhel8.6-2.0-1.noarch),系统可能无法正确连接到 RHUI,导致无法获取软件更新或无法升级到新版本。

    • 如果有类似aliyun_rhui_rhel8-2.0-3.x86_64订阅包回显信息,表示您的系统已使用阿里云RHEL订阅,可以继续执行本文升级操作。

      image

  4. 准备升级环境。

    1. 运行以下命令,将RHEL系统升级到最新版本,最新版本通常包含对已知漏洞、错误和安全问题的修复,并重启系统使其生效。

      yum -y update
      reboot
    2. 运行以下命令,在RHEL系统上安装Leapp升级工具。

      yum -y install leapp leapp-rhui-alibaba --enablerepo="*"
    3. 运行以下命令,确认Leapp是否安装成功。

      leapp --version

      如果有类似leapp version xxx回显信息,表示Leapp安装成功。

  5. 预升级检查。

    由于RHEL各系统差异较大,在升级前需要先通过Leapp工具对系统进行预升级检查。您可以查看Leapp工具的检查结果,并根据Leapp工具的建议进行修复,以满足升级需求。

    1. 运行以下命令,进行预升级检查。

      • 预升级至RHEL 9最新版本。

        leapp preupgrade  --no-rhsm
      • 预升级至具体的目标版本,例如需要将RHEL 8升级至RHEL 9.4版本。

        leapp preupgrade --no-rhsm --target 9.4
        说明

        您可以通过leapp preupgrade -h命令查看当前系统支持升级的目标版本。

    2. 查看预升级检查结果。

      Leapp工具预升级的检查日志保存在以下日志文件中:

      • /var/log/leapp/leapp-preupgrade.log:Leapp工具的日志

      • /var/log/leapp/leapp-report.txt:文本格式的预升级检查报告

      • /var/log/leapp/leapp-report.json :JSON格式的预升级检查报告

      预升级检查失败后,会打印出一些具体检查失败项, 如下图所示。

      image

    3. (条件必选)处理预升级报错。

      在日志文件/var/log/leapp/leapp-report.txt中查看预升级是否有报错信息,您可以根据Leapp工具的建议进行修复。以下按风险等级列出一些常见的预升级检查报错及处理办法。

      • high:高风险,这类问题不会直接阻止升级,但建议您在升级前或升级后解决这些问题,以避免升级后出现问题。

        • 案例1:检测到自定义的Leapp actors或文件

          Risk Factor: high 
          Title: Detected custom leapp actors or files.
          Summary: We have detected installed custom actors or files on the system. These can be provided e.g. by third party vendors, Red Hat consultants, or can be created by users to customize the upgrade (e.g. to migrate custom applications). This is allowed and appreciated. However Red Hat is not responsible for any issues caused by these custom leapp actors. Note that upgrade tooling is under agile development which could require more frequent update of custom actors.
          The list of custom leapp actors and files:
              - /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/alibaba/content.crt
              - /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/alibaba/key.pem
              - /usr/share/leapp-repository/repositories/system_upgrade/common/files/rhui/alibaba/leapp-alibaba.repo
          Related links:
              - Customizing your Red Hat Enterprise Linux in-place upgrade: https://red.ht/customize-rhel-upgrade
          Remediation: [hint] In case of any issues connected to custom or third party actors, contact vendor of such actors. Also we suggest to ensure the installed custom leapp actors are up to date, compatible with the installed packages.

          处理办法:确保自定义actors是最新版本,并且与Leapp工具和系统环境兼容。升级完成后,检查系统是否正常运行,并及时解决因自定义actors引起的问题。如何管理自定义actors可参见Customizing your Red Hat Enterprise Linux in-place upgrade

        • 案例2: 在升级过程中自动更新GRUB2配置

          Risk Factor: high 
          Title: GRUB2 core will be automatically updated during the upgrade
          Summary: On legacy (BIOS) systems, GRUB2 core (located in the gap between the MBR and the first partition) cannot be updated during the rpm transaction and Leapp has to initiate the update running "grub2-install" after the transaction. No action is needed before the upgrade. After the upgrade, it is recommended to check the GRUB configuration.

          处理办法:升级后检查GRUB配置,确保系统能够正常启动。

      • low:低风险,这类问题对升级过程或系统运行的影响较小,但建议您在升级前或升级后解决这些问题,以确保系统稳定运行。

        案例:SELinux将被设置为permissive模式

        Risk Factor: low 
        Title: SElinux will be set to permissive mode
        Summary: SElinux will be set to permissive mode. Current mode: enforcing. This action is required by the upgrade process to make sure the upgraded system can boot without beinig blocked by SElinux rules.
        Remediation: [hint] Make sure there are no SElinux related warnings after the upgrade and enable SElinux manually afterwards. Notice: You can ignore the "/root/tmp_leapp_py3" SElinux warnings.

        处理办法:升级后确保没有SELinux相关警告,然后将SELinux重新设置为 enforcing 模式,确保系统安全合规。

      • info:提示,这类问题通常是信息性提示,不会对升级过程或系统运行产生影响。您可以查看报告中的具体提示,了解升级过程中会发生的变化。

        案例:排除部分目标系统仓库

        Risk Factor: info 
        Title: Excluded target system repositories
        Summary: The following repositories are not supported by Red Hat and are excluded from the list of repositories used during the upgrade.
        - rhui-codeready-builder-for-rhel-9-aarch64-rhui-rpms
        - codeready-builder-for-rhel-9-aarch64-rpms
        - codeready-builder-for-rhel-9-s390x-rpms
        - codeready-builder-beta-for-rhel-9-ppc64le-rpms
        - codeready-builder-for-rhel-9-x86_64-rpms
        Remediation: [hint] If some of excluded repositories are still required to be used during the upgrade, execute leapp with the --enablerepo option with the repoid of the repository required to be enabled as an argument (the option can be used multiple times).

        处理办法:如果某些被排除的仓库在升级过程中仍然需要启用,可以使用 --enablerepo 选项启用它们。

  6. 运行以下命令,进行升级。

    • 升级至RHEL 9最新版本。

      leapp upgrade  --no-rhsm
    • 升级至具体的目标版本,例如需要将RHEL 8升级至RHEL 9.4版本。

      leapp upgrade  --no-rhsm --target 9.4

    如下图所示,表示升级成功。

    image

  7. 运行以下命令,重启进入新系统。

    reboot
  8. 验证升级结果。

    • 运行cat /etc/redhat-release命令检查系统版本是否已更新。

    • 查看升级的执行日志或报告是否正常。

    • 观察您的业务在RHEL 9系统上运行是否正常。

  9. (条件必选)运行以下命令,配置RHEL的源。

    使用Leapp升级工具升级完成后,默认会修改/etc/dnf/vars/releasever文件来限定系统升级到RHEL的具体版本。例如RHEL 9.4,repo源信息为https://xxxx/9.4/xxx,后续您只能访问RHEL 9.4版本下的软件包。如果您希望能够自动访问RHEL 9最新版本的软件包,确保获取到最新的安全补丁和功能更新,可以通过删除releasever配置文件并重建元数据缓存来实现。

    rm -f /etc/dnf/vars/releasever
    dnf clean all && dnf makecache

    执行完成后,RHEL 9repo源信息会更新为https://xxxx/9/xxx,系统将能够自动获取RHEL 9最新版本的安全补丁和功能更新,确保系统始终处于最新状态。

相关文档

  • 您也可以通过服务器迁移中心SMCRedHat 8升级至RedHat 9。具体操作,请参见操作系统迁移(Linux)

  • 有关Red Hat的更多介绍,请参见红帽官方文档Red Hat Enterprise Linux

  • 关于RHEL 7进入延长生命周期阶段的常见问题可参考红帽官方FAQ文档。