CentOS轉換Redhat Enterprise Linux(一)6.x

隨着CentOS社區項目將會轉移到CentOS Stream,相信很多使用者會考慮將自家生產環境中的CentOS轉換到Redhat Enterprise Linux,這樣才能夠保證企業基礎架構和應用的穩定性。本篇文章簡要介紹Convert2RHEL工具將CentOS的轉換爲RHEL的方法。

但需要注意的是,這裏只是很簡單的操作系統轉換,真正在企業裏做轉換還需要考慮保證應用或數據庫的高可用性,因此建議需請相應的人員提前做諮詢工作。下面就看下大致的步驟:

  1. 這個演示我們利用CentOS 6.9進行實驗。

CentOS轉換Redhat Enterprise Linux(一)6.x

  1. 切換到/etc/yum.repos.d目錄,這個位置是配置yum源的目錄,以*.repo文件配置不同的yum源。將CentOS-Base.repo文件備份(改動配置前將原文件備份,是一個好習慣)。
[root@centos69-130 ~]# cd /etc/yum.repos.d
[root@centos69-130 yum.repos.d]# pwd
/etc/yum.repos.d
[root@centos69-130 yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
  1. 因爲CentOS 6.x已經不在支持週期,因此其yum源不在Redhat網站,我們需要將默認位置改到vault網站。
[root@centos69-130 yum.repos.d]# ls
CentOS-Base.repo      CentOS-Debuginfo.repo  CentOS-Media.repo  packagekit-media.repo
CentOS-Base.repo.bak  CentOS-fasttrack.repo  CentOS-Vault.repo
[root@centos69-130 yum.repos.d]# cat CentOS-Base.repo
[base-vault]
name=base-vault
baseurl=https://vault.centos.org/6.9/os/x86_64/
gpgcheck=0
enabled=1
  1. 因爲轉換工作主要是將各種CentOS package轉換爲RHEL package,因此我們需要將RHEL光盤鏡像掛載並mount。

CentOS轉換Redhat Enterprise Linux(一)6.x

  1. 將cdrom mount到文件系統。

    [root@centos69-130 ~]# 
    [root@centos69-130 ~]# mkdir /cdrom
    [root@centos69-130 ~]# mount /dev/cdrom /cdrom
    mount: block device /dev/sr0 is write-protected, mounting read-only
  2. 創建將RHEL cdrom作爲yum源的repo文件RHEL-cdrom.repo
[root@centos69-130 yum.repos.d]# ls
CentOS-Base.repo      CentOS-Debuginfo.repo  CentOS-Media.repo  packagekit-media.repo
CentOS-Base.repo.bak  CentOS-fasttrack.repo  CentOS-Vault.repo  RHEL-cdrom.repo
[root@centos69-130 yum.repos.d]# cat RHEL-cdrom.repo 
[cdrom]
name=cdrom
baseurl=file:///cdrom
gpgcheck=0
enabled=1
  1. 如下我們配置了CentOS-Base.repo和RHEL-cdrom.repo兩個文件,內容如下。

    [root@centos69-130 yum.repos.d]# ls
    CentOS-Base.repo      CentOS-Debuginfo.repo  CentOS-Media.repo  packagekit-media.repo
    CentOS-Base.repo.bak  CentOS-fasttrack.repo  CentOS-Vault.repo  RHEL-cdrom.repo
    [root@centos69-130 yum.repos.d]# cat CentOS-Base.repo
    [base-vault]
    name=base-vault
    baseurl=https://vault.centos.org/6.9/os/x86_64/
    gpgcheck=0
    enabled=1
    [root@centos69-130 yum.repos.d]# cat RHEL-cdrom.repo 
    [cdrom]
    name=cdrom
    baseurl=file:///cdrom
    gpgcheck=0
    enabled=1
  2. 更新yum源的cache。
[root@centos69-130 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base-vault cdrom
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@centos69-130 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base-vault                                                                                   | 3.7 kB     00:00     
base-vault/group_gz                                                                          | 226 kB     00:00     
base-vault/filelists_db                                                                      | 6.4 MB     00:04     
base-vault/primary_db                                                                        | 4.7 MB     00:03     
base-vault/other_db                                                                          | 2.8 MB     00:01     
cdrom                                                                                        | 4.1 kB     00:00 ... 
cdrom/group_gz                                                                               | 216 kB     00:00 ... 
cdrom/filelists_db                                                                           | 3.4 MB     00:00 ... 
cdrom/primary_db                                                                             | 3.1 MB     00:00 ... 
cdrom/other_db                                                                               | 1.3 MB     00:00 ... 
Metadata Cache Created
  1. 安裝convert2rhel工具包。
[root@centos69-130 yum.repos.d]#  yum install -y https://github.com/oamg/convert2rhel/releases/download/v0.15/convert2rhel-0.15-1.el6.noarch.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
convert2rhel-0.15-1.el6.noarch.rpm                                                           |  83 kB     00:00 ... 
Examining /var/tmp/yum-root-PKw7Gm/convert2rhel-0.15-1.el6.noarch.rpm: convert2rhel-0.15-1.el6.noarch
  1. 因爲我們使用本地源進行轉換,所以暫時不需要向Redhat註冊系統,先disable-submgr;後面加上參數配置yum源名稱,和上面配置的名稱一致;可以配置多個yum源。
[root@centos69-130 yum.repos.d]# convert2rhel --disable-submgr --enablerepo cdrom --debug

[01/29/2021 08:27:21] TASK - [Prepare: End user license agreement] ******************************
The following text is a copy of the November 2010 version of RHEL EULA [1].
For up-to-date version of RHEL EULA, please visit [2].
[1] https://www.redhat.com/f/pdf/licenses/GLOBAL_EULA_RHEL_English_20101110.pdf
[2] https://www.redhat.com/en/about/red-hat-end-user-license-agreements

END USER LICENSE AGREEMENT
RED HAT® ENTERPRISE LINUX® AND RED HAT APPLICATIONS
  1. 接受EULA

    Copyright © 2010 Red Hat, Inc. All rights reserved. "Red Hat" and the Red Hat "Shadowman" logo are registered trademarks of Red Hat, Inc. "Linux" is a registered trademark of Linus Torvalds. All other trademarks are the property of their respective owners.
    WARNING - By continuing you accept this EULA.
    Continue with the system conversion? [y/n]: y
  2. 確認一些package將會被替代,這一步等待時間會稍長
[01/29/2021 08:30:43] TASK - [Prepare: Gather system information] *******************************
Name:                CentOS
OS major version:    6
[01/29/2021 08:30:43] DEBUG - Calling command 'uname -i'
Architecture:        x86_64
Config filename:     centos-6-x86_64.cfg
Running the 'rpm -Va' command which can take several minutes. It can be disabled by using the --no-rpm-va option.
[01/29/2021 08:30:43] DEBUG - Calling command 'rpm -Va'
The 'rpm -Va' output has been stored in the /var/log/convert2rhel/rpm_va.log file
[01/29/2021 08:31:34] TASK - [Prepare: Determine RHEL variant] **********************************
Variant: Server
[01/29/2021 08:31:34] TASK - [Prepare: Backup System] *******************************************
Backing up /etc/system-release
Copying /etc/system-release to /var/lib/convert2rhel/
Backing up /etc/yum.conf
Copying /etc/yum.conf to /var/lib/convert2rhel/
[01/29/2021 08:31:34] TASK - [Prepare: Clear YUM/DNF version locks] *****************************
Usage of YUM/DNF versionlock plugin not detected.
[01/29/2021 08:31:34] TASK - [Convert: Remove excluded packages] ********************************
Searching for the following excluded packages:
centos-bookmarks ................................ 0
centos-logos .................................... 0
centos-indexhtml ................................ 1
centos-release* ................................. 1
redhat-release* ................................. 0
libreport-centos ................................ 0
libreport-plugin-mantisbt ....................... 0
rhn* ............................................ 0
yum-rhn-plugin .................................. 0
WARNING - The following packages will be removed...
Package                                 Packager            Repository
-------                                 --------            ----------
centos-indexhtml-6-2.el6.centos.noarch  CentOS BuildSystem  anaconda-CentOS-201703281317.x86_64
centos-release-6-9.el6.12.3.x86_64      CentOS BuildSystem  anaconda-CentOS-201703281317.x86_64
Continue with the system conversion? [y/n]: y
  1. 檢測已安裝的應用packages將會被替代,而一些第三方package則不會被替代
Backing up centos-indexhtml-6-2.el6.centos.noarch
[01/29/2021 08:33:02] DEBUG - Downloading the centos-indexhtml-6-2.el6.centos.noarch package.
[01/29/2021 08:33:02] DEBUG - Calling command 'yumdownloader -v --destdir="/var/lib/convert2rhel/" centos-indexhtml-6-2.el6.centos.noarch'
Loading "fastestmirror" plugin
Loading "refresh-packagekit" plugin
Config time: 0.008
Loading mirror speeds from cached hostfile
repo time: 0.001
Setting up Package Sacks
pkgsack time: 0.015
centos-indexhtml-6-2.el6.centos.noarch.rpm    50% [=================-                 ]  0.0 B/s |  46 kB     --:-- centos-indexhtml-6-2.el6.centos.noarch.rpm   100% [===================================]  71 kB/s |  91 kB     00:00 rpmdb time: 0.000
centos-indexhtml-6-2.el6.centos.noarch.rpm                                                       |  91 kB     00:00     
Successfully downloaded the centos-indexhtml-6-2.el6.centos.noarch package.
[01/29/2021 08:33:05] DEBUG - Path of the downloaded package: /var/lib/convert2rhel/centos-indexhtml-6-2.el6.centos.noarch.rpm
Backing up centos-release-6-9.el6.12.3.x86_64
[01/29/2021 08:33:05] DEBUG - Downloading the centos-release-6-9.el6.12.3.x86_64 package.
[01/29/2021 08:33:05] DEBUG - Calling command 'yumdownloader -v --destdir="/var/lib/convert2rhel/" centos-release-6-9.el6.12.3.x86_64'
Loading "fastestmirror" plugin
Loading "refresh-packagekit" plugin
Config time: 0.006
Loading mirror speeds from cached hostfile
repo time: 0.000
Setting up Package Sacks
pkgsack time: 0.013
rpmdb time: 0.000
centos-release-6-9.el6.12.3.x86_64.rpm                                                           |  22 kB     00:00     
Successfully downloaded the centos-release-6-9.el6.12.3.x86_64 package.
[01/29/2021 08:33:06] DEBUG - Path of the downloaded package: /var/lib/convert2rhel/centos-release-6-9.el6.12.3.x86_64.rpm
Removing package: centos-indexhtml-6-2.el6.centos.noarch
[01/29/2021 08:33:06] DEBUG - Calling command 'rpm -e --nodeps centos-indexhtml-6-2.el6.centos.noarch'
Removing package: centos-release-6-9.el6.12.3.x86_64
[01/29/2021 08:33:06] DEBUG - Calling command 'rpm -e --nodeps centos-release-6-9.el6.12.3.x86_64'
warning: /etc/yum.repos.d/CentOS-Base.repo saved as /etc/yum.repos.d/CentOS-Base.repo.rpmsave
[01/29/2021 08:33:07] DEBUG - Successfully removed 2 packages
[01/29/2021 08:33:07] TASK - [Convert: Install Red Hat release package] *************************
Installing redhat-release-server package
No package to install
[01/29/2021 08:33:07] TASK - [Convert: Patch yum configuration file] ****************************
[01/29/2021 08:33:07] DEBUG - /etc/yum.conf patched.
[01/29/2021 08:33:07] TASK - [Convert: List third-party packages] *******************************
WARNING - Only packages signed by CentOS are to be reinstalled. Red Hat support won't be provided for the following third party packages:
Package                         Packager  Repository
-------                         --------  ----------
convert2rhel-0.15-1.el6.noarch  N/A       /convert2rhel-0.15-1.el6.noarch
Continue with the system conversion? [y/n]: y
  1. 將要開始conversion,警告:直到此步之前都可以自動回滾,開始這步驟之後,如果需要回滾只能手工進行了。
WARNING - The tool allows rollback of any action until this point.
WARNING - By continuing all further changes on the system will need to be reverted manually by the user, if necessary.
Continue with the system conversion? [y/n]: y
  1. 將要開始替換成RHEL kernel
[01/29/2021 08:37:46] TASK - [Convert: Import Red Hat GPG keys] *********************************
[01/29/2021 08:37:46] DEBUG - Calling command 'rpm --import /usr/share/convert2rhel/gpg-keys/RPM-GPG-KEY-redhat-release'
[01/29/2021 08:37:46] DEBUG - Calling command 'rpm --import /usr/share/convert2rhel/gpg-keys/RPM-GPG-KEY-redhat-legacy-release'
[01/29/2021 08:37:46] TASK - [Convert: Prepare kernel] ******************************************
Installing RHEL kernel ...
[01/29/2021 08:37:46] DEBUG - Calling command 'yum install -y --disablerepo=* --enablerepo=cdrom kernel'
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Determining fastest mirrors
Package kernel-2.6.32-696.el6.x86_64 already installed and latest version
Nothing to do
Conflict of kernels: One of the installed kernels has the same version as the latest RHEL kernel.
[01/29/2021 08:37:47] DEBUG - Calling command 'yum list -y --disablerepo=* --enablerepo=cdrom --showduplicates kernel'
WARNING - The convert2rhel is going to force-replace the only kernel installed, which has the same NEVRA as the only available RHEL kernel. If anything goes wrong with such replacement, the system will become unbootable. If you want the convert2rhel to install the RHEL kernel in a safer manner, you can install a different version of kernel first and then run convert2rhel again.
Continue with the system conversion? [y/n]: y
  1. 接下來就是正式開始進行轉換,等待段時間後就完成啦!然後需要重啓。
[01/29/2021 08:44:26] TASK - [Final: Non-interactive mode] **************************************
For the non-interactive use of the tool, run the following command:
convert2rhel --disable-submgr  --disablerepo=*  --enablerepo=cdrom  -v Server -y
WARNING - In order to boot the RHEL kernel, restart of the system is needed.
[root@centos69-130 yum.repos.d]# reboot
  1. 重啓後看到已經轉換成Redhat Enterprise Linux啦!

CentOS轉換Redhat Enterprise Linux(一)6.x

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章