Yum Install Kernel

Yum 升级 Kernel 内核

过旧的内核可能已不再维护或有安全漏洞等问题,并且部署环境/程序也有不兼容的情况

更新内核是有风险的,在操作之前慎重,严谨在生产环境上操作,升级流程可参考 elrepo.org

1)安装 EL 源

$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
$ yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

2)查看现可提供升级的版本

$ yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: hkg.mirror.rackspace.com
Available Packages
kernel-lt.x86_64                       5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-devel.x86_64                 5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-doc.noarch                   5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-headers.x86_64               5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-tools.x86_64                 5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs.x86_64            5.4.231-1.el7.elrepo          elrepo-kernel
kernel-lt-tools-libs-devel.x86_64      5.4.231-1.el7.elrepo          elrepo-kernel
kernel-ml.x86_64                       6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-devel.x86_64                 6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-doc.noarch                   6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-headers.x86_64               6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-tools.x86_64                 6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-tools-libs.x86_64            6.1.11-1.el7.elrepo           elrepo-kernel
kernel-ml-tools-libs-devel.x86_64      6.1.11-1.el7.elrepo           elrepo-kernel
perf.x86_64                            5.4.231-1.el7.elrepo          elrepo-kernel
python-perf.x86_64                     5.4.231-1.el7.elrepo          elrepo-kerne

3)选择版本进行安装

  • kernel-ml,稳定主线版本
  • kernel-lt,长期支持版本
$ yum -y install kernel-ml --enablerepo=elrepo-kernel

4)查看现有内核版本

1
2
3
4
$ awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (6.1.11-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-7aac39666d8041ba853f00dd964bd0fe) 7 (Core)

5)将序号 0 的设置为密码的启动项并重新加载、重启服务器

$ grub2-set-default 0
$ grub2-mkconfig -o /boot/grub2/grub.cfg && reboot now

6)卸载旧内核,非必要,可自行选择

1
2
3
4
5
$ rpm -qa | grep kernel
$ yum -y remove $(rpm -qa | grep kernel | grep '3')
$ awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (6.1.11-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (0-rescue-7aac39666d8041ba853f00dd964bd0fe) 7 (Core)