在离线环境中将 CentOS 7.X 原地升级并迁移至 RHEL 7.9

OpenShift / RHEL / DevSecOps 汇总目录

说明

  1. 本文将说明如何在离线环境中将 CentOS 7.5 升级并迁移至 RHEL 7.9。为了简化准备过程,本文前面将在在线环境中安装用到的各种所需验证软件,而在后面升级迁移的时候再切换到由 ISO 构成的离线 Yum Repo。
  2. CentOS 7.x 需要先升级到 CentOS 7.9 后才能迁移到 RHEL 7.9。
  3. 以下所安装的验证软件基本都选择了和 CentOS 7.5 一个时期的较早版本,且都是单机安装配置。
  4. 另外出于方便,以下所有操作都使用的是 root 用户。
    在这里插入图片描述

Convert2RHEL 简介

Convert2RHEL 是 RedHat 提供的一个命令行工具,用于分析系操作统的情况,并将基于 RPM 的 Linux 操作系统转换为红帽企业 Linux。 它支持将 CentOS Linux 7 和 Oracle Linux 7 以及 Alma Linux 8、Oracle Linux 8、CentOS Linux 8 和 Rocky Linux 8 的转换到对应版本的 RHEL。

准备 CentOS 7.5 VM 及其他被验证软件环境

安装 CentOS VM 并配置 CentOS 7.5 Yum Repo

本文使用的是 VirtualBox 6.1 的虚拟化软件。

  1. 下载 CentOS-7-x86_64-DVD-1804.iso(CentOS 7.5)、CentOS-7-x86_64-DVD-2009.iso(CentOS 7.9)、rhel-server-7.9-x86_64-dvd.iso 文件。
  2. 创建一个名为 CentOS7 的 VM,然后用 CentOS-7-x86_64-DVD-1804.iso 在其中最小化安装 CentOS 7.5 即可,过程略。
  3. 将 CentOS-7-x86_64-DVD-1804.iso 挂载到 CentOS 7.5 文件系统。
$ mkdir /mnt/centos75
$ mount /dev/sr0 /mnt/centos75
  1. 配置本地 Yum Repo。
$ cat > /etc/yum.repos.d/centos75-local.repo << EOF 
[centos75-local-repo]
name = centos75 local repo
baseurl=file:///mnt/centos75
enabled=1
gpgcheck=0
EOF

准备 docker 18.06.3.ce 环境

安装 docker

  1. 安装 docker 所需 Yum Repo。
$ curl -L https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
  1. 安装 docker。
$ yum list docker-ce --showduplicates
$ yum install docker-ce-18.06.3.ce-3.el7
  1. 配置开机启动。
$ systemctl enable --now docker
$ systemctl status docker 

验证 docker

  1. 下载 tomcat:7.0.63 镜像。
$ docker pull tomcat:7.0.63
$ docker images
  1. 运行 tomcat 镜像
$ docker run -d -p 8080:8080 --name tomcat-test tomcat:7.0.63
$ docker ps -a
  1. 访问 tomcat
$ curl http://localhost:8080
  1. 删除镜像
$ docker rm tomcat-test

准备 mysql 5.7 环境

安装 mysql 环境

  1. 安装 mysql 安装所需 Yum Repo。
$ curl -LO http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
$ rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
$ yum localinstall mysql57-community-release-el7-8.noarch.rpm
  1. 确认已经有以下 3 个 mysql 的 Yum Repo。
$ yum repolist enabled | grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community           242
mysql-tools-community/x86_64            MySQL Tools Community                104
mysql57-community/x86_64                MySQL 5.7 Community Server           696
  1. 安装 mysql。
$ yum install -y mysql-community-server
  1. 配置开机启动。
$ systemctl enable --now mysqld
$ systemctl status mysqld

验证 mysql

  1. 使用临时密码登录 mysql。
$ grep 'temporary password' /var/log/mysqld.log
$ mysql -u root -p
  1. 修改密码。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd';
  1. 创建用户。
mysql> CREATE USER 'user1'@'%' IDENTIFIED BY 'P@ssw0rd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost'  WITH GRANT OPTION;
  1. 操作 database 和 table。
mysql> create database crm;
mysql> use crm;
mysql> create table customer(id int,name varchar(20));
mysql> insert into customer values (1,'Jack');
mysql> insert into customer values (2,'Tom');
mysql> insert into customer values (3,'Bob');
mysql> insert into customer values (4,'James');
mysql> insert into customer values (5,'John');
mysql> select * from crm.customer;

准备 redis 5.0.13 环境

安装 redis

  1. 安装 epel 所需 Yum Repo。
$ curl -LO https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ yum install epel-release-latest-7.noarch.rpm
  1. 安装 redis 所需 Yum Repo。
$ curl -LO http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ yum install remi-release-7.rpm
  1. 安装 redis 5.0.13。
$ yum --enablerepo=remi list redis --showduplicates
$ yum --enablerepo=remi install redis-5.0.13-1.el7.remi
  1. 配置开机启动。
$ systemctl enable --now redis
$ systemctl status redis

验证 redis

  1. 进入 redis-cli 环境。
$ redis-cli
  1. 操作redis。
127.0.0.1:6379> SET 1 Jack
127.0.0.1:6379> SET 2 Tom
127.0.0.1:6379> SET 3 Bob
127.0.0.1:6379> SET 4 James
127.0.0.1:6379> SET 5 John
127.0.0.1:6379> GET 4

准备 rabbitmq 3.3.5 环境

安装 rabbitmq

  1. 下载 erlang 和 rabbitmq 的 rpm 安装包。
$ curl -LO https://github.com/rabbitmq/erlang-rpm/releases/download/v23.3.4.11/erlang-23.3.4.11-1.el7.x86_64.rpm
$ curl -LO https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.9.13/rabbitmq-server-3.9.13-1.el7.noarch.rpm
  1. 安装 erlang 和 rabbitmq。
$ yum localinstall erlang-23.3.4.11-1.el7.x86_64.rpm
$ yum localinstall rabbitmq-server-3.9.13-1.el7.noarch.rpm
  1. 配置开机启动。
$ systemctl enable --now rabbitmq-server
$ systemctl status rabbitmq-server

启动 webconsole

  1. 启动 webconsole
$ rabbitmq-plugins enable rabbitmq_management
  1. 创建用户。
$ rabbitmqctl add_user admin password
$ rabbitmqctl set_user_tags admin administrator

验证 rabbitmq

  1. 关闭防火墙。
$ systemctl stop firewalld
  1. 用浏览器打开 webconsole 地址,例如 http://<CENTOS-HOST-IP>:15672
    在这里插入图片描述

准备 mongodb 4.4.2 环境

安装 mongodb

  1. 准备安装 mongodb 用到的 Yum Repo。
$ cat > /etc/yum.repos.d/mongodb.repo << EOF 
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://pgp.mongodb.com/server-4.4.asc
EOF
  1. 安装 mongodb。
$ yum install mongodb-org-4.4.2 mongodb-org-server-4.4.2 mongodb-org-shell-4.4.2 mongodb-org-mongos-4.4.2 mongodb-org-tools-4.4.2
  1. 配置开机启动。
$ systemctl enable --now mongod
$ systemctl status mongod

验证 mongodb

  1. 进入 mongo。
$ mongo
  1. 操作 dbs 和 collections。
> show dbs
> use crm
> db.crm.insert({"1":"Jack"})
> db.crm.insert({"2":"Tom"})
> db.crm.insert({"3":"Bob"})
> db.crm.insert({"4":"James"})
> db.crm.insert({"5":"John"})
> db.crm.find()

准备 postgresql 9.2.23

安装 postgresql

  1. 安装 postgresql,然后初始化数据库。
$ yum install postgresql-server
$ postgresql-setup initdb
  1. 配置开机启动。
systemctl enable --now postgresql
systemctl status postgresql

验证 postgresql

  1. 进入 postgres 用户,然后执行客户端,最后查看 postgresql 的版本。
$ su postgres
bash-4.2$  psql
could not change directory to "/root"
psql (9.2.23)
Type "help" for help.
postgres=# show server_version;
 server_version
----------------
 9.2.23
(1 row)
  1. 创建测试表。
postgres=# CREATE TABLE playground (
    equip_id serial PRIMARY KEY,
    type varchar (50) NOT NULL,
    color varchar (25) NOT NULL,
    location varchar(25) check (location in ('north', 'south', 'west', 'east', 'northeast', 'southeast', 'southwest', 'northwest')),
    install_date date
);
postgres=# \dt
          List of relations
 Schema |    Name    | Type  |  Owner   
--------+------------+-------+----------
 public | playground | table | postgres
(1 row)
  1. 向表添加数据。
postgres=# INSERT INTO playground (type, color, location, install_date) VALUES ('slide', 'blue', 'south', '2014-04-28');
postgres=# INSERT INTO playground (type, color, location, install_date) VALUES ('swing', 'yellow', 'northwest', '2010-08-16');
  1. 从表查询数据。
postgres=# SELECT * FROM playground;
equip_id | type  | color  | location  | install_date 
----------+-------+--------+-----------+--------------
        1 | slide | blue   | south     | 2014-04-28
        2 | swing | yellow | northwest | 2010-08-16
(2 rows)

准备 Oracle DB 12c 环境

见《在离线环境中将运行 Oracle DB 12c 的 CentOS 7.5 原地升级并迁移至 RHEL 7.9》一文。

准备 CentOS 7.9 和 RHEL 7.9 的离线 Yum Repo

配置 ISO 挂载文件

  1. 设置 CentOS 7.5 VM 的存储。选中 “CentOS-7-x86_64-DVD-1804.iso” 一行,然后点击 “第一IDE控制器主通道” 右侧图标,点击 “选择虚拟盘…” 菜单,然后在弹出窗口选中 CentOS-7-x86_64-DVD-2009.iso 文件,这样第一个 IDE 就会挂载 CentOS-7-x86_64-DVD-2009.iso 文件了。
    在这里插入图片描述
  2. 在关闭 VM 后点击下图的 “添加虚拟光驱” 右侧图标,然后在弹出的 “虚拟光盘选择” 窗口中点击 “注册” 图标,再在文件夹中选中 rhel-server-7.9-x86_64-dvd.iso 文件。最后在 “虚拟光盘选择” 窗口中点击 “选择” 按钮,这样第二个 IDE 就会挂载 rhel-server-7.9-x86_64-dvd.iso 文件了。
    在这里插入图片描述
  3. 完成后 VM 就可以同时挂载 CentOS-7-x86_64-DVD-2009.iso 和 rhel-server-7.9-x86_64-dvd.iso 两个文件了。
    在这里插入图片描述

配置 CentOS 7.9 和 RHEL 7.9 Yum Repo

  1. 将 CentOS-7-x86_64-DVD-2009.iso 和 rhel-server-7.9-x86_64-dvd.iso 挂载到运行 CentOS 7.5 的 VM 上。
    在这里插入图片描述
  2. 将 ISO 挂载到 CentOS 7.5 文件系统。
$ mkdir /mnt/centos79 /mnt/rhel79
$ mount /dev/sr0 /mnt/centos79
$ mount /dev/sr1 /mnt/rhel79
  1. 配置本地 Yum Repo。
$ cat > /etc/yum.repos.d/centos79-local.repo << EOF 
[centos79-local-repo]
name = centos79 local repo
baseurl=file:///mnt/centos79
enabled=1
gpgcheck=0
EOF
 
$ cat > /etc/yum.repos.d/rhel79-local.repo << EOF 
[rhel79-local-repo]
name = rhel79 local repo
baseurl=file:///mnt/rhel79
enabled=1
gpgcheck=0
EOF
  1. 确认 CentOS 7.9 和 RHEL 7.9 的离线 Yum Repo 已经可用。
$ yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                 repo name                                      status
centos79-local-repo                     centos79 local repo                            4,070
rhel79-local-repo                       rhel79 local repo                              5,230
repolist: 9,300

将 CentOS 7.5 原地升级至 CentOS 7.9

  1. 查看当前发行版和 kernel 版本。
$ cat /etc/redhat-release
$ uname -r
  1. 确认 Yum Repo 只有 CentOS 7.9。
$ yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                 repo name                                      status
centos79-local-repo                     centos79 local repo                            4,070
repolist: 4,070
  1. 查看当前环境中所有可升级的软件包。
$ yum list updates
  1. 开始升级 CentOS 7.5。
$ yum update
  1. 确认被升级的 Package 和使用的 Repository。
。。。
Dependencies Resolved

=======================================================================================================================================================================
 Package                                         Arch                     Version                                          Repository                             Size
=======================================================================================================================================================================
Installing:
 grub2                                           x86_64                   1:2.02-0.86.el7.centos                           centos79-local-repo                    32 k
     replacing  grub2.x86_64 1:2.02-0.65.el7.centos.2
 grub2-tools                                     x86_64                   1:2.02-0.86.el7.centos                           centos79-local-repo                   1.8 M
     replacing  grub2-tools.x86_64 1:2.02-0.65.el7.centos.2
 grub2-tools-extra                               x86_64                   1:2.02-0.86.el7.centos                           centos79-local-repo                   1.0 M
     replacing  grub2-tools.x86_64 1:2.02-0.65.el7.centos.2
 grub2-tools-minimal                             x86_64                   1:2.02-0.86.el7.centos                           centos79-local-repo                   174 k
     replacing  grub2-tools.x86_64 1:2.02-0.65.el7.centos.2
 iwl7260-firmware                                noarch                   25.30.13.0-79.el7                                centos79-local-repo                   6.1 M
     replacing  iwl7265-firmware.noarch 22.0.7.0-62.el7
 kernel                                          x86_64                   3.10.0-1160.el7                                  centos79-local-repo                    50 M
Updating:
 GeoIP                                           x86_64                   1.5.0-14.el7                                     centos79-local-repo                   1.5 M
 acl                                             x86_64                   2.2.51-15.el7                                    centos79-local-repo                    81 k
 alsa-lib                                        x86_64                   1.1.8-1.el7                                      centos79-local-repo                   425 k
。。。
  1. 完成后再次查看当前发行版和 kernel 版本。
$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
$ uname -r
3.10.0-862.el7.x86_64
  1. 为了生效 kernel,需要重启 Linux。
  2. 重启后再次查看 kernel 版本,确认已更新。
$ uname -r
3.10.0-1160.el7.x86_64
  1. 使用前面各软件的验证步骤确认所有软件均可正常运行和使用。注意:如果软件是通过 CentOS ISO 安装的,这些软件的版本有可能会随新版的 CentOS 一起更新升级。如果软件是从其他渠道安装的,则版本不会变化。

将 CentOS 7.9 原地迁移至 RHEL 7.9

安装 convert2rhel

方法1

  1. 下载安装 convert2rhel 所需 Yum Repo。
$ curl -o /etc/yum.repos.d/convert2rhel.repo https://ftp.redhat.com/redhat/convert2rhel/7/convert2rhel.repo
  1. 修改 /etc/yum.repos.d/convert2rhel.repo 文件,将 gpgcheck 改为 0。
  2. 安装 convert2rhel。
$ yum -y install convert2rhel

方法2

使用 rpm 安装 convert2rhel。

$ curl -LO https://github.com/oamg/convert2rhel/releases/download/v1.7.1/convert2rhel-1.7.1-1.el7.noarch.rpm
$ yum localinstall convert2rhel-1.7.1-1.el7.noarch.rpm

将 CentOS 7.9 转换到 RHEL 7.9

  1. 执行以下命令查看已安装的软件包及其供应商。注意:convert2rhel 只转换由 CentOS 供应的软件。
$ rpm -qa --queryformat '%{vendor}:%{name}\n' | sort
。。。。。
CentOS:yum-metadata-parser
CentOS:yum-plugin-fastestmirror
CentOS:yum-utils
CentOS:zenity
CentOS:zlib
Docker:docker-ce
Fedora Project:epel-release
Fedora Project:imlib2
Fedora Project:openbox
Fedora Project:openbox-libs
Fedora Project:python2-pyxdg
MongoDB:mongodb-database-tools
MySQL:mysql57-community-release
(none):convert2rhel
(none):gpg-pubkey
(none):gpg-pubkey
(none):gpg-pubkey
(none):gpg-pubkey
(none):gpg-pubkey
(none):gpg-pubkey
(none):mongodb-org
(none):mongodb-org-database-tools-extra
(none):mongodb-org-mongos
(none):mongodb-org-server
(none):mongodb-org-shell
(none):mongodb-org-tools
(none):rabbitmq-server
Oracle and/or its affiliates:mysql-community-client
Oracle and/or its affiliates:mysql-community-common
Oracle and/or its affiliates:mysql-community-libs
Oracle and/or its affiliates:mysql-community-libs-compat
Oracle and/or its affiliates:mysql-community-server
Remi's RPM repository <https://rpms.remirepo.net/>:redis
Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine:remi-release
VMware, Inc.:erlang
  1. 确认当前可用 Yum Repo 有 CentOS 7.9 和 RHEL 7.9。
$ yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                 repo name                                      status
centos79-local-repo                     centos79 local repo                            4,070
rhel79-local-repo                       rhel79 local repo                              5,230
repolist: 9,300
  1. 执行命令,在迁移前先进行分析。
$ convert2rhel analyze --disable-submgr --enablerepo=rhel79-local-repo
  1. 根据以上返回结果的提示,设置以下环境变量。
$ export CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK=1 			## 跳过是否升为最新内核的检查
$ export CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS=1				## 检查所有加载的内核模块在 RHEL 资源库中是否可用
$ export CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP=1	## 跳过污点内核模块检查
$ export CONVERT2RHEL_OUTDATED_PACKAGE_CHECK_SKIP=1			## 跳过对过期包的检查
  1. 执行迁移。
$ convert2rhel --disable-submgr --enablerepo=rhel79-local-repo
  1. 完成前会有以下提示,说明部分非 RedHat 的第三方包无法替换。
Listing packages not signed by Red Hat
The following packages were left unchanged.
 
Package                                                Vendor/Packager                                                       Repository
-------                                                ---------------                                                       ----------
0:mysql-community-libs-5.7.44-1.el7.x86_64             Oracle and/or its affiliates                                          N/A
0:mysql-community-common-5.7.44-1.el7.x86_64           Oracle and/or its affiliates                                          N/A
0:epel-release-7-14.noarch                             Fedora Project                                                        N/A
0:yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch      CentOS                                                                centos79-local-re                         po
0:mongodb-org-4.4.2-1.el7.x86_64                       (none)                                                                N/A
0:erlang-23.3.4.11-1.el7.x86_64                        VMware, Inc.                                                          N/A
0:remi-release-7.9-6.el7.remi.noarch                   Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine  N/A
0:openbox-libs-3.5.2-6.el7.x86_64                      Fedora Project                                                        N/A
0:python2-pyxdg-0.25-8.el7.noarch                      Fedora Project                                                        N/A
0:mongodb-org-server-4.4.2-1.el7.x86_64                (none)                                                                N/A
0:compat-libstdc++-33-3.2.3-72.el7.x86_64              CentOS                                                                N/A
0:rabbitmq-server-3.9.13-1.el7.noarch                  (none)                                                                N/A
2:container-selinux-2.119.2-1.911c772.el7_8.noarch     CentOS                                                                N/A
0:mysql-community-server-5.7.44-1.el7.x86_64           Oracle and/or its affiliates                                          N/A
0:mongodb-org-mongos-4.4.2-1.el7.x86_64                (none)                                                                N/A
0:redis-5.0.13-1.el7.remi.x86_64                       Remi's RPM repository <https://rpms.remirepo.net/>                    N/A
0:mysql-community-client-5.7.44-1.el7.x86_64           Oracle and/or its affiliates                                          N/A
0:docker-ce-18.06.3.ce-3.el7.x86_64                    Docker                                                                N/A
0:convert2rhel-1.7.1-1.el7.noarch                      (none)                                                                N/A
0:openbox-3.5.2-6.el7.x86_64                           Fedora Project                                                        N/A
0:mysql-community-libs-compat-5.7.44-1.el7.x86_64      Oracle and/or its affiliates                                          N/A
0:mongodb-database-tools-100.9.4-1.x86_64              MongoDB                                                               N/A
0:mongodb-org-database-tools-extra-4.4.2-1.el7.x86_64  (none)                                                                N/A
0:mysql57-community-release-el7-8.noarch               MySQL                                                                 N/A
0:mongodb-org-shell-4.4.2-1.el7.x86_64                 (none)                                                                N/A
0:imlib2-1.4.9-8.el7.x86_64                            Fedora Project                                                        N/A
0:mongodb-org-tools-4.4.2-1.el7.x86_64                 (none)                                                                N/A
  1. 成功迁移后会有 “Conversion successful!” 提示。
  2. 迁移过程的日志会写到 /var/log/convert2rhel/convert2rhel.log 文件中。
  3. 重启 Linux 后确认当前发行版和 kernel 版本已迁移到 RHEL 7.9 了。
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
$ uname -r
3.10.0-1160.el7.x86_64
  1. 使用前面各软件的验证步骤确认所有软件均可正常运行和使用。

参考

https://www.redhat.com/en/interactive-labs/migrate-red-hat-enterprise-linux-centos-linux
https://www.cnblogs.com/tenghu/p/15887218.html
https://github.com/oamg/convert2rhel/wiki/Environment-variables

  • 23
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值