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

OpenShift / RHEL / DevSecOps 汇总目录

说明

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

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

准备 CentOS 7.5 环境

本文使用的是 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 即可,过程略。

准备 docker 18.06.3.ce 环境

安装 docker

  1. 安装 docker 所需 Yum Repo。
bash 复制代码
$ curl -LO https://download.docker.com/linux/centos/docker-ce.repo
  1. 安装 docker。
bash 复制代码
$ yum list docker-ce --showduplicates
$ yum install docker-ce-18.06.3.ce-3.el7
  1. 配置开机启动。
bash 复制代码
$ systemctl enable --now docker
$ systemctl status docker 

验证 docker

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

准备 mysql 5.7

安装 mysql 环境

  1. 安装 mysql 安装所需 Yum Repo。
bash 复制代码
$ 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。
bash 复制代码
$ 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。
bash 复制代码
$ yum install -y mysql-community-server
  1. 配置开机启动。
bash 复制代码
$ systemctl enable --now mysqld
$ systemctl status mysqld

验证 mysql

  1. 使用临时密码登录 mysql。
bash 复制代码
$ grep 'temporary password' /var/log/mysqld.log
$ mysql -u root -p
  1. 修改密码。
bash 复制代码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd';
  1. 创建用户。
bash 复制代码
mysql> CREATE USER 'user1'@'%' IDENTIFIED BY 'P@ssw0rd';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'localhost'  WITH GRANT OPTION;
  1. 操作 database 和 table。
bash 复制代码
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。
bash 复制代码
$ 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。
bash 复制代码
$ curl -LO http://rpms.remirepo.net/enterprise/remi-release-7.rpm
$ yum install remi-release-7.rpm
  1. 安装 redis 5.0.13。
bash 复制代码
$ yum --enablerepo=remi list redis --showduplicates
$ yum --enablerepo=remi install redis-5.0.13-1.el7.remi
  1. 配置开机启动。
bash 复制代码
$ systemctl enable --now redis
$ systemctl status redis

验证 redis

  1. 进入 redis-cli 环境。
bash 复制代码
$ redis-cli
  1. 操作redis。
bash 复制代码
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 安装包。
bash 复制代码
$ 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。
bash 复制代码
$ yum localinstall erlang-23.3.4.11-1.el7.x86_64.rpm
$ yum localinstall rabbitmq-server-3.9.13-1.el7.noarch.rpm
  1. 配置开机启动。
bash 复制代码
$ systemctl enable --now rabbitmq-server
$ systemctl status rabbitmq-server

启动 webconsole

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

验证 rabbitmq

  1. 关闭防火墙。
bash 复制代码
$ systemctl stop firewalld
  1. 用浏览器打开 webconsole 地址,例如 http://192.168.x.x:15672

准备 mongodb 4.4.2 环境

安装 mongodb

  1. 准备安装 mongodb 用到的 Yum Repo。
bash 复制代码
$ 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。
bash 复制代码
$ 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. 配置开机启动。
bash 复制代码
$ systemctl enable --now mongod
$ systemctl status mongod

验证 mongodb

  1. 进入 mongo。
bash 复制代码
$ mongo
  1. 操作 dbs 和 collections。
bash 复制代码
> 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()

准备 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-2009.iso" 一行,然后点击 "第一IDE控制器主通道" 右侧图标,点击 "选择虚拟盘..." 菜单,然后在弹出窗口选中 CentOS-7-x86_64-DVD-2009.iso 文件,这样第一个 IDE 就会挂载 CentOS-7-x86_64-DVD-2009.iso 文件了。
  2. 选中 "CentOS7.viso" 一行,然后点击 "第一IDE控制器从通道" 右侧图标,点击 "选择虚拟盘..." 菜单,然后在弹出窗口选中 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 两个文件了。

挂载 ISO

  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 文件系统。
bash 复制代码
$ mkdir /mnt/centos79 /mnt/rhel79
$ mount /dev/sr0 /mnt/centos79
$ mount /dev/sr1 /mnt/rhel79
  1. 配置本地 Yum Repo。
bash 复制代码
$ 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 已经可用。
bash 复制代码
$ 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 版本。
bash 复制代码
$ cat /etc/redhat-release
$ uname -r
  1. 升级 CentOS。
bash 复制代码
$ yum update
  1. 完成后再次查看当前发行版和 kernel 版本。
bash 复制代码
$ 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 版本,确认已更新。
bash 复制代码
$ uname -r
3.10.0-1160.el7.x86_64

将 CentOS 7.9 原地迁移至 RHEL 7.9

安装 convert2rhel

方法1

  1. 下载安装 convert2rhel 所需 Yum Repo。
bash 复制代码
$ 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。
bash 复制代码
$ yum -y install convert2rhel

方法2

使用 rpm 安装 convert2rhel。

bash 复制代码
$ 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

进行转换

  1. 确认当前可用 Yum Repo。
bash 复制代码
$ 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. 执行命令,在迁移前先进行分析。
bash 复制代码
$ convert2rhel analyze --disable-submgr --enablerepo=rhel79-local-repo
  1. 根据以上返回结果的提示,设置以下环境变量。
bash 复制代码
$ export CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK=1
$ export CONVERT2RHEL_OUTDATED_PACKAGE_CHECK_SKIP=1
$ export CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS=1
$ export CONVERT2RHEL_TAINTED_KERNEL_MODULE_CHECK_SKIP=1
  1. 执行迁移
bash 复制代码
$ convert2rhel --disable-submgr --enablerepo=rhel79-local-repo
  1. 完成后重启 Linux。
  2. 确认当前发行版和 kernel 版本已迁移到 RHEL 7.9 了。
bash 复制代码
$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
$ uname -r
3.10.0-1160.el7.x86_64

参考

https://www.redhat.com/en/interactive-labs/migrate-red-hat-enterprise-linux-centos-linux

https://www.cnblogs.com/tenghu/p/15887218.html

相关推荐
Spring-wind1 小时前
【linux】kill命令
linux
dreamer2921 小时前
21、Tomato
linux·安全·web安全·网络安全·系统安全
小小的木头人2 小时前
Docker vs. containerd 深度剖析容器运行时
运维·docker·容器
Data 3172 小时前
Shell脚本编程基础(二)
大数据·linux·运维·数据仓库·sql·centos·bash
it技术分享just_free3 小时前
基于 K8S kubernetes 的常见日志收集方案
linux·运维·docker·云原生·容器·kubernetes·k8s
bmseven3 小时前
windows远程桌面连接ubuntu
linux·windows·ubuntu
aidroid3 小时前
git github仓库管理
linux·运维·docker
学习3人组4 小时前
集群服务器主机实现主机名与IP绑定
运维·服务器·tcp/ip
三朝看客4 小时前
k8s自动清理pod脚本分享
linux·docker
it技术分享just_free4 小时前
基于 K8S kubernetes 搭建 安装 EFK日志收集平台
运维·docker·云原生·容器·kubernetes·k8s