当前位置: 移动技术网 > 网络运营>服务器>Linux > 如何将CentOS7升级至CentOS8(详细步骤)

如何将CentOS7升级至CentOS8(详细步骤)

2020年03月09日  | 移动技术网网络运营  | 我要评论

这篇文章以具体的示例来介绍一下从centos 7升级值centos 8的方法。

事前准备

最小化安装centos 7,具体版本如下所示:7.6.1810

[root@liumiao ~]# uname -a
linux devops 3.10.0-957.el7.x86_64 #1 smp thu nov 8 23:39:32 utc 2018 x86_64 x86_64 x86_64 gnu/linux
[root@liumiao ~]# cat /etc/redhat-release 
centos linux release 7.6.1810 (core) 
[root@liumiao ~]# 

步骤1: 安装epel-relase、yum-utils和rpmconf

执行命令:yum install yum-utils epel-release -y

执行日志如下所示:

...省略
========================================================================================================================================
 package        arch      version        repository     size
========================================================================================================================================
installing:
 epel-release      noarch      7-11         extras      15 k
 yum-utils       noarch      1.1.31-52.el7      base      121 k
installing for dependencies:
 libxml2-python      x86_64      2.9.1-6.el7_2.3      base      247 k
 python-chardet      noarch      2.2.1-3.el7       base      227 k
 python-kitchen      noarch      1.1.1-5.el7       base      267 k

transaction summary
========================================================================================================================================
install 2 packages (+3 dependent packages)
...省略

安装命令:yum install rpmconf -y

安装日志如下所示:

[root@liumiao ~]# yum install rpmconf -y
...省略
========================================================================================================================================
 package       arch       version        repository     size
========================================================================================================================================
installing:
 rpmconf       noarch       0.3.4-1.el7       epel       21 k

transaction summary
========================================================================================================================================
install 1 package
...省略
complete!
[root@liumiao ~]# 

步骤2: 安装前检查

检查配置:rpmconf -a

执行日志如下所示,如有选择直接使用缺省设定。

[root@liumiao ~]# rpmconf -a
[root@liumiao ~]# 

检查叶节点:列出和其他rpm没有依赖的软件包

[root@liumiao ~]# package-cleanup --leaves
loaded plugins: fastestmirror
libsysfs-2.1.0-16.el7.x86_64
[root@liumiao ~]# 

检查不再提供的软件包:列出当前仓库中不提供升级的软件包信息

[root@liumiao ~]# package-cleanup --orphans
loaded plugins: fastestmirror
loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * epel: hkg.mirror.rackspace.com
 * extras: mirror.bit.edu.cn
 * updates: ap.stykers.moe
geoip-1.5.0-13.el7.x86_64
...省略
yum-plugin-fastestmirror-1.1.31-50.el7.noarch
[root@liumiao ~]#

步骤3: 安装dnf 并执行dnf update

centos 8使用dnf作为缺省的包管理工具,使用yum安装自己的替代工具dnf并删除自己。

安装命令:yum install dnf -y

执行日志如下所示:

[root@liumiao ~]# yum install dnf -y
...省略
========================================================================================================================================
 package                arch           version                 repository        size
========================================================================================================================================
installing:
 dnf                  noarch          4.0.9.2-1.el7_6             extras          357 k
installing for dependencies:
 deltarpm                x86_64          3.6-3.el7                base           82 k
 dnf-data                noarch          4.0.9.2-1.el7_6             extras          51 k
 libcomps                x86_64          0.1.8-12.el7              extras          75 k
 libdnf                 x86_64          0.22.5-1.el7_6             extras          533 k
 libmodulemd              x86_64          1.6.3-1.el7               extras          141 k
 librepo                x86_64          1.8.1-7.el7               base           81 k
 libreport-filesystem          x86_64          2.1.11-43.el7.centos          base           40 k
 libsolv                x86_64          0.6.34-4.el7              base           329 k
 libyaml                x86_64          0.1.4-11.el7_0             base           55 k
 python-enum34             noarch          1.0.4-1.el7               base           52 k
 python2-dnf              noarch          4.0.9.2-1.el7_6             extras          414 k
 python2-hawkey             x86_64          0.22.5-1.el7_6             extras          68 k
 python2-libcomps            x86_64          0.1.8-12.el7              extras          47 k
 python2-libdnf             x86_64          0.22.5-1.el7_6             extras          608 k

transaction summary
========================================================================================================================================
install 1 package (+14 dependent packages)
...省略
[root@liumiao ~]#

清除yum:dnf -y remove yum yum-metadata-parser && rm -rf /etc/yum

执行日志如下所示:

[root@liumiao ~]# dnf -y remove yum yum-metadata-parser
dependencies resolved.
========================================================================================================================================
 package                  arch          version                repository        size
========================================================================================================================================
removing:
 yum                    noarch         3.4.3-161.el7.centos         @system         5.6 m
 yum-metadata-parser            x86_64         1.1.4-10.el7             @system          57 k
removing dependent packages:
 yum-plugin-fastestmirror         noarch         1.1.31-50.el7             @system          53 k
 yum-utils                 noarch         1.1.31-52.el7             @system         337 k

transaction summary
========================================================================================================================================
remove 4 packages

freed space: 6.0 m
running transaction check
transaction check succeeded.
running transaction test
transaction test succeeded.
running transaction
 preparing    :                                                        1/1 
 erasing     : yum-utils-1.1.31-52.el7.noarch                                         1/4 
 erasing     : yum-plugin-fastestmirror-1.1.31-50.el7.noarch                                 2/4 
 erasing     : yum-3.4.3-161.el7.centos.noarch                                        3/4 
 erasing     : yum-metadata-parser-1.1.4-10.el7.x86_64                                    4/4 
 verifying    : yum-3.4.3-161.el7.centos.noarch                                        1/4 
 verifying    : yum-metadata-parser-1.1.4-10.el7.x86_64                                    2/4 
 verifying    : yum-plugin-fastestmirror-1.1.31-50.el7.noarch                                 3/4 
 verifying    : yum-utils-1.1.31-52.el7.noarch                                         4/4

removed:
 yum-3.4.3-161.el7.centos.noarch   yum-metadata-parser-1.1.4-10.el7.x86_64   yum-plugin-fastestmirror-1.1.31-50.el7.noarch   
 yum-utils-1.1.31-52.el7.noarch   

complete!
[root@liumiao ~]# ls /etc/yum
pluginconf.d protected.d vars
[root@liumiao ~]# rm -rf /etc/yum
[root@liumiao ~]#

就像使用yum update那样使用dnf update进行更新。

[root@liumiao ~]# dnf upgrade
extra packages for enterprise linux 7 - x86_64                             5.6 mb/s | 16 mb   00:02  
centos-7 - base                                             3.5 mb/s | 10 mb   00:02  
centos-7 - updates                                           2.9 mb/s | 5.4 mb   00:01  
centos-7 - extras                                            40 kb/s | 251 kb   00:06  
 ...省略
========================================================================================================================================
 package                  arch        version                   repository      size
========================================================================================================================================
upgrading:
 epel-release                noarch       7-12                     epel         15 k
 ...省略
 tzdata                   noarch       2019c-1.el7                 updates       493 k
installing dependencies:
 bind-export-libs              x86_64       32:9.11.4-9.p2.el7              base         1.1 m
 geoipupdate                x86_64       2.5.0-1.el7                 base         35 k
 kernel                   x86_64       3.10.0-1062.4.3.el7             updates        50 m

transaction summary
========================================================================================================================================
install  3 packages
upgrade 164 packages

total download size: 259 m
is this ok [y/n]: y
downloading packages:
 ...省略
 installed:
 bind-export-libs-32:9.11.4-9.p2.el7.x86_64     geoipupdate-2.5.0-1.el7.x86_64     kernel-3.10.0-1062.4.3.el7.x86_64    

complete!
[root@liumiao ~]#

使用dnf更新centos 8的包

执行日志如下所示:

[root@liumiao ~]# dnf -y upgrade http://mirror.bytemark.co.uk/centos/8/baseos/x86_64/os/packages/centos-release-8.0-0.1905.0.9.el8.x86_64.rpm

extra packages for enterprise linux 7 - x86_64                             4.3 mb/s | 16 mb   00:03  
last metadata expiration check: 0:00:01 ago on wed 20 nov 2019 07:58:07 am est.
centos-release-8.0-0.1905.0.9.el8.x86_64.rpm                               13 kb/s | 26 kb   00:01  
dependencies resolved.
========================================================================================================================================
 package             arch           version                 repository           size
========================================================================================================================================
upgrading:
 centos-release          x86_64          8.0-0.1905.0.9.el8           @commandline          26 k

transaction summary
========================================================================================================================================
upgrade 1 package

total size: 26 k
downloading packages:
running transaction check
transaction check succeeded.
running transaction test
transaction test succeeded.
running transaction
 preparing    :                                                        1/1 
 upgrading    : centos-release-8.0-0.1905.0.9.el8.x86_64                                    1/2 
 cleanup     : centos-release-7-7.1908.0.el7.centos.x86_64                                  2/2 
 verifying    : centos-release-8.0-0.1905.0.9.el8.x86_64                                    1/2 
 verifying    : centos-release-7-7.1908.0.el7.centos.x86_64                                  2/2

upgraded:
 centos-release-8.0-0.1905.0.9.el8.x86_64                                               

complete!
[root@liumiao ~]#

更新epel仓库

执行日志如下所示:

[root@liumiao ~]# dnf -y upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
extra packages for enterprise linux 7 - x86_64                             578 kb/s | 16 mb   00:28  
centos-8 - base                                             635 kb/s | 7.9 mb   00:12  
centos-8 - extras                                            1.7 kb/s | 2.1 kb   00:01  
centos-8 - appstream                                          1.3 mb/s | 6.3 mb   00:04  
epel-release-latest-8.noarch.rpm                                    7.7 kb/s | 21 kb   00:02  
dependencies resolved.
========================================================================================================================================
 package              arch             version            repository             size
========================================================================================================================================
upgrading:
 epel-release            noarch            8-7.el8            @commandline            21 k

transaction summary
========================================================================================================================================
upgrade 1 package

total size: 21 k
downloading packages:
running transaction check
transaction check succeeded.
running transaction test
transaction test succeeded.
running transaction
 preparing    :                                                        1/1 
 upgrading    : epel-release-8-7.el8.noarch                                          1/2 
 cleanup     : epel-release-7-12.noarch                                            2/2 
 verifying    : epel-release-8-7.el8.noarch                                          1/2 
 verifying    : epel-release-7-12.noarch                                            2/2

upgraded:
 epel-release-8-7.el8.noarch                                                     

complete!
[root@liumiao ~]# 

 此时确认版本信息,已经发生了变化

[root@liumiao ~]# cat /etc/redhat-release 
centos linux release 8.0.1905 (core) 
[root@liumiao ~]# 

步骤4: 删除无用文件和centos 7的内核并安装centos 8的内核

删除无用的临时文件:dnf clean all

执行日志如下所示:

[root@liumiao ~]# dnf clean all
62 files removed
[root@liumiao ~]#

删除centos 7的旧核: rpm -e `rpm -q kernel`

执行日志如下所示:

[root@liumiao ~]# rpm -e `rpm -q kernel`
[root@liumiao ~]#

确认删除冲突的包

[root@liumiao ~]# rpm -e --nodeps sysvinit-tools
[root@liumiao ~]# 

更新centos 8系统

[root@liumiao ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
extra packages for enterprise linux 8 - x86_64                             2.0 mb/s | 3.5 mb   00:01  
centos-8 - base                                             160 kb/s | 7.9 mb   00:50  
centos-8 - appstream                                          1.6 mb/s | 6.3 mb   00:03  
centos-8 - extras                                            950 b/s | 2.1 kb   00:02  
last metadata expiration check: 0:00:02 ago on wed 20 nov 2019 08:09:51 am est.
dependencies resolved.
========================================================================================================================================
 package                arch      version                        repository     size
========================================================================================================================================
upgrading:
 rpmconf                noarch     1.0.20-1.el8                      epel        26 k
...省略
removed:
 deltarpm-3.6-3.el7.x86_64           libselinux-python-2.5-14.1.el7.x86_64    libxml2-python-2.9.1-6.el7_2.3.x86_64   
 newt-python-0.52.15-4.el7.x86_64       python-2.7.5-86.el7.x86_64         python-chardet-2.2.1-3.el7.noarch     
 python-firewall-0.6.3-2.el7_7.2.noarch    python-kitchen-1.1.1-5.el7.noarch      python-libs-2.7.5-86.el7.x86_64      
 python-linux-procfs-0.4.11-4.el7.noarch    python-schedutils-0.4-6.el7.x86_64     python-slip-0.4.0-4.el7.noarch       
 python-slip-dbus-0.4.0-4.el7.noarch      python-urlgrabber-3.10-9.el7.noarch     python2-dnf-4.0.9.2-1.el7_6.noarch     
 python2-hawkey-0.22.5-1.el7_6.x86_64     python2-libcomps-0.1.8-12.el7.x86_64    python2-libdnf-0.22.5-1.el7_6.x86_64    
 pyxattr-0.5.1-5.el7.x86_64          rpm-python-4.11.3-40.el7.x86_64       systemd-sysv-219-67.el7_7.2.x86_64    

complete!
[root@liumiao ~]# 

此时通过uname -a确认内核状态,仍是3.10.

[root@liumiao ~]# uname -a
linux devops 3.10.0-957.el7.x86_64 #1 smp thu nov 8 23:39:32 utc 2018 x86_64 x86_64 x86_64 gnu/linux
[root@liumiao ~]# cat /etc/redhat-release 
centos linux release 8.0.1905 (core) 
[root@liumiao ~]#

由于前文已经更新,此时如执行dnf -y install kernel-core会提示already updated,接下来更新一下centos 8的最小化安装的相关package,执行如下命令即可:

[root@liumiao ~]# dnf -y groupupdate "core" "minimal install"
last metadata expiration check: 0:13:34 ago on wed 20 nov 2019 08:09:51 am est.
dependencies resolved.
========================================================================================================================================
 package                 arch       version                      repository      size
========================================================================================================================================
installing group/module packages:
 dnf-plugin-spacewalk          noarch      2.8.5-11.module_el8.0.0+180+337688dc       appstream       24 k
 dnf-plugins-core            noarch      4.0.2.2-3.el8                   baseos        59 k
...省略
[root@liumiao ~]#

步骤5: 重启系统

重启之后即可确认内核和版本文件信息均已升至最新

[root@liumiao ~]# uname -a
linux devops 4.18.0-80.11.2.el8_0.x86_64 #1 smp tue sep 24 11:32:19 utc 2019 x86_64 x86_64 x86_64 gnu/linux
[root@liumiao ~]# cat /etc/redhat-release 
centos linux release 8.0.1905 (core) 
[root@liumiao ~]# 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网