### Linux内核升级通常有两种方式
1. 下载新版内核到服务器上,进行编译安装,之后删除老内核,优点是:可完全控制编译项,缺点是:慢,且容易失败;
2. 采用yum 方式安装,优点是:快捷方便,成功率高。
我这里采用第二种方式来安装,毕竟网站还在使用,不能耽误。采用yum安装最多也就三五分钟的事,万一失败,还能补救。
说明:以下步骤如未特殊声明,均在 shell环境下执行命令行
一:导入key
```
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
```
二:安装elrepo的yum源
```
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
```
三:安装内核(默认安装最新稳定版本内核)
```
yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml
```
四:查看启动顺序
```
awk -F\\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
```
新的内核版本默认会在最前面,下面将选择系统启动时的内核版本,顺序为 0 。
五:选择默认内核版本
```
grub2-set-default 0
```
六:重启服务器,使之生效
```
reboot
```
七:验证内核版本
```
uname -a
```
说明升级成功,检查了下各部分,均无异常, good!
重新登陆了下服务器,使用漏洞检测工具验证,漏洞修复完成, 历时20分钟。
下面是整个升级命令行的执行过程
\[root@iZ23gbeynf2Z ~\]# rpm -qa | grep kernel kernel-devel-3.10.0-693.21.1.el7.x86\_64 kernel-3.10.0-693.5.2.el7.x86\_64 kernel-3.10.0-693.2.2.el7.x86\_64 kernel-3.10.0-514.26.2.el7.x86\_64 kernel-3.10.0-693.17.1.el7.x86\_64 kernel-tools-libs-3.10.0-693.21.1.el7.x86\_64 kernel-headers-3.10.0-693.21.1.el7.x86\_64 kernel-ml-4.16.2-1.el7.elrepo.x86\_64 php-symfony-http-kernel-2.8.12-2.el7.noarch kernel-devel-3.10.0-693.5.2.el7.x86\_64 abrt-addon-kerneloops-2.1.11-48.el7.centos.x86\_64 kernel-devel-3.10.0-693.2.2.el7.x86\_64 kernel-3.10.0-693.21.1.el7.x86\_64 kernel-devel-3.10.0-514.26.2.el7.x86\_64 kernel-devel-3.10.0-693.17.1.el7.x86\_64 kernel-tools-3.10.0-693.21.1.el7.x86\_64 \[root@iZ23gbeynf2Z ~\]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org \[root@iZ23gbeynf2Z ~\]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm Retrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm Preparing... ################################# \[100%\] package elrepo-release-7.0-3.el7.elrepo.noarch is already installed \[root@iZ23gbeynf2Z ~\]# yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml Loaded plugins: langpacks Package kernel-ml-4.16.2-1.el7.elrepo.x86\_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package kernel-ml-devel.x86\_64 0:4.16.2-1.el7.elrepo will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================================================== Installing: kernel-ml-devel x86\_64 4.16.2-1.el7.elrepo elrepo-kernel 12 M Transaction Summary =================================================================================================================================================================== Install 1 Package Total download size: 12 M Installed size: 45 M Is this ok \[y/d/N\]: y Downloading packages: kernel-ml-devel-4.16.2-1.el7.elrepo.x86\_64.rpm | 12 MB 00:00:04 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : kernel-ml-devel-4.16.2-1.el7.elrepo.x86\_64 1/1 Verifying : kernel-ml-devel-4.16.2-1.el7.elrepo.x86\_64 1/1 Installed: kernel-ml-devel.x86\_64 0:4.16.2-1.el7.elrepo Complete! \[root@iZ23gbeynf2Z ~\]# awk -F\\' '$1=="menuentry " {print $2}' /etc/grub2.cfg CentOS Linux (4.16.2-1.el7.elrepo.x86\_64) 7 (Core) CentOS Linux (3.10.0-693.21.1.el7.x86\_64) 7 (Core) CentOS Linux (3.10.0-693.17.1.el7.x86\_64) 7 (Core) CentOS Linux (3.10.0-693.5.2.el7.x86\_64) 7 (Core) CentOS Linux (3.10.0-693.2.2.el7.x86\_64) 7 (Core) CentOS Linux (3.10.0-514.26.2.el7.x86\_64) 7 (Core) CentOS Linux, with Linux 0-rescue-45461f76679f48ee96e95da6cc798cc8 \[root@iZ23gbeynf2Z ~\]# grub2-set-default 0 \[root@iZ23gbeynf2Z ~\]# reboot Connection closed by foreign host.
```