centos升级系统内核及升级系统版本
查看版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
查看内核版本
[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64
[root@localhost ~]#
###准备升级内核到7.9系统的内核
虚拟机新增一个cdrom,相当于再加一个光盘,用于挂载新的系统镜像目录,然后将iso镜像挂载上去
[root@localhost ~]# mount /dev/sr1 /mnt
mount: /dev/sr1 is write-protected, mounting read-only
[root@localhost ~]# ls /mnt
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
可以看出sr0是centos7.4的内核rpm软件包
[root@localhost Packages]# ls |grep 3.10 |grep -i kernel
kernel-3.10.0-862.el7.x86_64.rpm
kernel-abi-whitelists-3.10.0-862.el7.noarch.rpm
kernel-debug-devel-3.10.0-862.el7.x86_64.rpm
kernel-devel-3.10.0-862.el7.x86_64.rpm
kernel-headers-3.10.0-862.el7.x86_64.rpm
kernel-tools-3.10.0-862.el7.x86_64.rpm
kernel-tools-libs-3.10.0-862.el7.x86_64.rpm
[root@localhost Packages]# uname -r
3.10.0-862.el7.x86_64
[root@localhost Packages]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 4.4G 0 rom
sr1 11:1 1 4.2G 0 rom /mnt
[root@localhost Packages]# mount /dev/sr0 /tmp
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost Packages]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1009M 17G 6% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.6M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr1 4.2G 4.2G 0 100% /mnt
/dev/sr0 4.4G 4.4G 0 100% /tmp
[root@localhost Packages]# cd /tmp/Packages/
[root@localhost Packages]# ls |grep 3.10 |grep kernel
kernel-3.10.0-1160.el7.x86_64.rpm
kernel-abi-whitelists-3.10.0-1160.el7.noarch.rpm
kernel-debug-devel-3.10.0-1160.el7.x86_64.rpm
kernel-devel-3.10.0-1160.el7.x86_64.rpm
kernel-headers-3.10.0-1160.el7.x86_64.rpm
kernel-tools-3.10.0-1160.el7.x86_64.rpm
kernel-tools-libs-3.10.0-1160.el7.x86_64.rpm
目标:内核升级成为”kernel-3.10.0-1160.el7.x86_64.rpm“
##安装yum工具
yum -y install yum-utils
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# ls
bak CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@localhost yum.repos.d]# mv *.repo bak
[root@localhost yum.repos.d]# ls
bak
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
######设置本地yum源(centos7.9的)
[root@localhost yum.repos.d]# yum-config-manager --add file:///tmp
Loaded plugins: fastestmirror
adding repo from: file:///tmp
[tmp]
name=added from: file:///tmp
baseurl=file:///tmp
enabled=1
[root@localhost yum.repos.d]# ls
bak tmp.repo
[root@localhost yum.repos.d]# echo "gpgcheck=0" >>tmp.repo
重新更新一下,yum仓库,发现只有centos7.9的yum源仓库
###########现在的内核(红色部分)
[root@localhost yum.repos.d]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
###需要升级的内核版本
[root@localhost yum.repos.d]# ls /tmp/Packages/ |grep kernel-3.10
kernel-3.10.0-1160.el7.x86_64.rpm
进入、到挂载的目录,去安装内核的rpm包:
[root@localhost yum.repos.d]# cd /tmp/Packages/
[root@localhost Packages]# yum -y install kernel-3.10.0-1160.el7.x86_64.rpm(使用yum安装,自动解决依赖问题,rpm -ivh没有依赖也可以执行,但是有依赖就会报错,rpm -ivh需要一个一个解决依赖问题)
####检查一下,内核版本没变化
[root@localhost Packages]# uname -r
3.10.0-862.el7.x86_64
#########需要重启,方能生效
Init 6 或者reboot
##########重启之后,发现内核版本已经发生了变化:
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
############至此,内核版本升级完成######################
@@@@@@@@@@@@@@@@@@@@@@
想直接版本也给他升级成7.9版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@localhost ~]#
[root@localhost ~]# yum update -y
###刚刚重启了,所以挂载目录掉了,需要挂载/tmp
Total download size: 150 M
Downloading packages:
Error downloading packages:
numactl-libs-2.0.12-5.el7.x86_64: [Errno 256] No more mirrors to try.
pam-1.1.8-23.el7.x86_64: [Errno 256] No more mirrors to try.
1:grub2-tools-extra-2.02-0.86.el7.centos.x86_64: [Errno 256] No more mirrors to try.
7:device-mapper-1.02.170-6.el7.x86_64: [Errno 256] No more mirrors to try.
iwl100-firmware-39.31.5.1-79.el7.noarch: [Errno 256] No more mirrors to try.
7:lvm2-libs-2.02.187-6.el7.x86_64: [Errno 256] No more mirrors to try.
1:grub2-pc-modules-2.02-0.86.el7.centos.noarch: [Errno 256] No more mirrors to try.
2:microcode_ctl-2.1-73.el7.x86_64: [Errno 256] No more mirrors to try.
glib2-2.56.1-7.el7.x86_64: [Errno 256] No more mirrors to try.
iproute-4.11.0-30.el7.x86_64: [Errno 256] No more mirrors to try.
mount /dev/sr0 /tmp
ls /tmp/Packages/kernel*
yum update -y
##看来升级系统成功
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]#
###必须重启进行测试,看是否能重启服务器成功,则升级系统没有问题,如果开机失败,还得排查升级失败的问题
init 6
####重新登陆服务器,检查系统版本为7.9,升级成功,(一般都是离线升级,所以在升级系统前,需要将生产环境的所有数据都要备份好,程序什么都打包好,以备升级系统完成后将升级前的环境再次部署上去,确保生产环境不丢失,否则数据丢失就编程系统升级的一个故障事故了)