目錄
- 一.前言
- 二.系統環境
- 三.系統內核下載網址
- 四.centos7離線升級系統內核
- 1.先查看系統環境
- 2.離線升級系統內核
- 五.在線升級系統內核
一.前言
CentOS(Community ENTerprise Operating System)是Linux發行版之一,它是來自于Red Hat Enterprise Linux依照開放源代碼規定釋出的源代碼所編譯而成,由于出自同樣的源代碼,因此有些要求高度穩定性的服務器以CentOS替代商業版的Red Hat Enterprise Linux使用,
CentOS系統簡潔穩定,但是系統內核版本低,有的軟體要求的系統內核版本高,此時升級系統內核即可滿足要求!
本文分別介紹離線升級系統內核和在線升級系統內核的方法,另外除了離線升級系統內核和在線升級系統內核,還可以從https://www.kernel.org/官網下載指定內核原始碼并進行編譯升級,但是此步驟較為繁瑣,在此忽略,
二.系統環境
服務器版本 | 系統內核版本 | CPU架構 |
---|---|---|
CentOS Linux release 7.4.1708 (Core) | 3.10.0-693.el7.x86_64 | x86_64 |
三.系統內核下載網址
centos 系統內核可以去如下兩個網站下載:
1.清華大學開源軟體鏡像站:https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/

? 2.elrepo鏡像站:https://elrepo.org/linux/kernel/el7/x86_64/RPMS/

四.centos7離線升級系統內核
1.先查看系統環境
查看作業系統版本
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
查看系統內核
[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64
2.離線升級系統內核
更新yum源倉庫
[[email protected] ~]# yum -y update
啟用 ELRepo 倉庫,ELRepo 倉庫是基于社區的用于企業級 Linux 倉庫,提供對 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 發行版(CentOS、Scientific、Fedora 等)的支持,ELRepo 聚焦于和硬體相關的軟體包,包括檔案系統驅動、顯卡驅動、網路驅動、聲卡驅動和攝像頭驅動等,
匯入ELRepo倉庫的公共密鑰
[[email protected] ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
安裝ELRepo倉庫的yum源
[[email protected] ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
從elrepo下載系統內核包,如果不匯入ELRepo倉庫的公共密鑰和安裝ELRepo倉庫的yum源,是下載不了內核包的
[[email protected] ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.160-1.el7.elrepo.x86_64.rpm
清華的這個鏡像站可以直接下載
[[email protected] ~]# wget https://mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-5.4.197-1.el7.elrepo.x86_64.rpm --no-check-certificate
內核包下載好,kernel-ml代表主線版本,總是保持主線最新的內核,kernel-lt代表長期支持版本,支持周期更長,如果你要追求最新的版本,直接選擇帶ml的rpm包即可,如果你要追求穩定且更長的支持周期,直接選擇lt版本即可,
[[email protected] ~]# ll -h kernel-lt-5.4.197-1.el7.elrepo.x86_64.rpm*
-rw-r--r-- 1 root root 51M 6月 5 19:47 kernel-lt-5.4.197-1.el7.elrepo.x86_64.rpm
安裝內核包
[[email protected] ~]# rpm -ivh kernel-lt-5.4.197-1.el7.elrepo.x86_64.rpm
警告:kernel-lt-5.4.197-1.el7.elrepo.x86_64.rpm: 頭V4 DSA/SHA256 Signature, 密鑰 ID baadae52: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:kernel-lt-5.4.197-1.el7.elrepo ################################# [100%]
內核升級完畢后,需要我們修改內核的啟動順序,默認啟動的順序應該為1,升級以后內核是往前面插入為0,設定GRUB_DEFAULT=0,一般新安裝的內核在第一個位置,所以設定default=0,意思是 GRUB 初始化頁面的第一個內核將作為默認內核,
默認的grub檔案,GRUB_DEFAULT=saved
[[email protected] ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_CMDLINE_LINUX="rhgb quiet nomodeset"
GRUB_DISABLE_RECOVERY="true"
使 GRUB_DEFAULT=0
[[email protected] ~]# vim /etc/default/grub
[[email protected] ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_CMDLINE_LINUX="rhgb quiet nomodeset"
GRUB_DISABLE_RECOVERY="true"
設定默認啟動內核,grub2-set-default 0和/etc/default/grub檔案里的GRUB_DEFAULT=0意思一樣
[[email protected] ~]# grub2-set-default 0
查看所有的內核
[[email protected] ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux 7 Rescue 12667e2174a8483e915fd89a3bc359fc (5.4.197-1.el7.elrepo.x86_64)
1 : CentOS Linux (5.4.197-1.el7.elrepo.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-80c608ceab5342779ba1adc2ac29c213) 7 (Core)
重新生成grub組態檔
[[email protected] ~]# vim /boot/grub2/grub.cfg
[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.197-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.197-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-12667e2174a8483e915fd89a3bc359fc
Found initrd image: /boot/initramfs-0-rescue-12667e2174a8483e915fd89a3bc359fc.img
Found linux image: /boot/vmlinuz-0-rescue-80c608ceab5342779ba1adc2ac29c213
Found initrd image: /boot/initramfs-0-rescue-80c608ceab5342779ba1adc2ac29c213.img
done
重啟并查看內核版本
[[email protected] ~]# reboot
可以看到內核升級成功
[[email protected] ~]# uname -r
5.4.197-1.el7.elrepo.x86_64
[[email protected] ~]# uname -rs
Linux 5.4.197-1.el7.elrepo.x86_64
五.在線升級系統內核
匯入ELRepo倉庫的公共密鑰,啟用 ELRepo 倉庫,ELRepo 倉庫是基于社區的用于企業級 Linux 倉庫,提供對 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 發行版(CentOS、Scientific、Fedora 等)的支持,ELRepo 聚焦于和硬體相關的軟體包,包括檔案系統驅動、顯卡驅動、網路驅動、聲卡驅動和攝像頭驅動等,
[[email protected] ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
安裝ELRepo倉庫的yum源
[[email protected] ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
獲取http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
準備中... ################################# [100%]
正在升級/安裝...
1:elrepo-release-7.0-3.el7.elrepo ################################# [100%]
kernel-ml代表主線版本,總是保持主線最新的內核,kernel-lt代表長期支持版本,支持周期更長,如果你要追求最新的版本,直接選擇帶ml的rpm包即可,如果你要追求穩定且更長的支持周期,直接選擇lt版本即可,
查看可用的系統內核包
[[email protected] ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
已加載插件:fastestmirror
,,,,,,
Loading mirror speeds from cached hostfile
* elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
可安裝的軟體包
elrepo-release.noarch 7.0-5.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 5.4.197-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 5.4.197-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 5.4.197-1.el7.elrepo elrepo-kernel
,,,,,,
kernel-ml-tools-libs.x86_64 5.18.2-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 5.18.2-1.el7.elrepo elrepo-kernel
perf.x86_64 5.18.2-1.el7.elrepo elrepo-kernel
python-perf.x86_64 5.18.2-1.el7.elrepo elrepo-kernel
剛才安裝的lt版本,現在安裝ml版本
安裝最新版本內核,--enablerepo 選項開啟 CentOS 系統上的指定倉庫,默認開啟的是 elrepo,這里用 elrepo-kernel 替換,或者yum install -y kernel-lt-4.4.218-1.el7.elrepo --enablerepo=elrepo-kernel
[[email protected] ~]# yum --enablerepo=elrepo-kernel install kernel-ml -y
已加載插件:fastestmirror
elrepo | 3.0 kB 00:00:00
elrepo/primary_db | 580 kB 00:00:06
Loading mirror speeds from cached hostfile
* elrepo: hkg.mirror.rackspace.com
* elrepo-kernel: hkg.mirror.rackspace.com
正在解決依賴關系
--> 正在檢查事務
---> 軟體包 kernel-ml.x86_64.0.5.18.2-1.el7.elrepo 將被 安裝
--> 解決依賴關系完成
,,,,,,
Downloading packages:
kernel-ml-5.18.2-1.el7.elrepo.x86_64.rpm | 56 MB 00:00:42
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 資料庫已被非 yum 程式修改,
正在安裝 : kernel-ml-5.18.2-1.el7.elrepo.x86_64 1/1
驗證中 : kernel-ml-5.18.2-1.el7.elrepo.x86_64 1/1
已安裝:
kernel-ml.x86_64 0:5.18.2-1.el7.elrepo
完畢!
查看所有的內核版本
[[email protected] ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (5.18.2-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (5.4.197-1.el7.elrepo.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-12667e2174a8483e915fd89a3bc359fc) 7 (Core)
4 : CentOS Linux (0-rescue-80c608ceab5342779ba1adc2ac29c213) 7 (Core)
內核升級完畢后,需要我們修改內核的啟動順序,默認啟動的順序應該為1,升級以后內核是往前面插入為0,設定GRUB_DEFAULT=0,一般新安裝的內核在第一個位置,所以設定default=0,意思是 GRUB 初始化頁面的第一個內核將作為默認內核,
[[email protected] ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_CMDLINE_LINUX="rhgb quiet nomodeset"
GRUB_DISABLE_RECOVERY="true"
[[email protected] ~]# grub2-set-default 0
重新生成grub組態檔
[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.18.2-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.18.2-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-5.4.197-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.4.197-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-12667e2174a8483e915fd89a3bc359fc
Found initrd image: /boot/initramfs-0-rescue-12667e2174a8483e915fd89a3bc359fc.img
Found linux image: /boot/vmlinuz-0-rescue-80c608ceab5342779ba1adc2ac29c213
Found initrd image: /boot/initramfs-0-rescue-80c608ceab5342779ba1adc2ac29c213.img
done
重啟
[[email protected] ~]# reboot
查看當前系統內核版本
[[email protected] ~]# uname -sr
Linux 5.18.2-1.el7.elrepo.x86_64
[[email protected] ~]# uname -r
5.18.2-1.el7.elrepo.x86_64
致力于一條龍式的為您解決問題轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/497194.html
標籤:Linux
下一篇:返回列表