CentOS Linux 内核升级

参考:

  • https://www.kernel.org/
  • http://elrepo.org/tiki/tiki-index.php
  • https://www.lijiaocn.com/%E6%8A%80%E5%B7%A7/2019/02/25/centos-kernel-upgrade.html
  • https://www.cnblogs.com/anliven/p/7944842.html

准备

导入公钥:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

CentOS8:

yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

CentOS7:

yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

CentOS6:

yum install https://www.elrepo.org/elrepo-release-6.el6.elrepo.noarch.rpm

安装

两种可选的内核:

  • kernel-ml: http://elrepo.org/tiki/kernel-ml
  • kernel-lt: http://elrepo.org/tiki/kernel-lt

查看当前可用的内核:

# 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                                     4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-devel.x86_64                               4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-doc.noarch                                 4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-headers.x86_64                             4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-tools.x86_64                               4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-tools-libs.x86_64                          4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                    4.4.220-1.el7.elrepo                    elrepo-kernel
kernel-ml-devel.x86_64                               5.6.7-1.el7.elrepo                      elrepo-kernel
kernel-ml-doc.noarch                                 5.6.7-1.el7.elrepo                      elrepo-kernel
kernel-ml-headers.x86_64                             5.6.7-1.el7.elrepo                      elrepo-kernel
kernel-ml-tools.x86_64                               5.6.7-1.el7.elrepo                      elrepo-kernel
kernel-ml-tools-libs.x86_64                          5.6.7-1.el7.elrepo                      elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                    5.6.7-1.el7.elrepo                      elrepo-kernel
perf.x86_64                                          5.6.7-1.el7.elrepo                      elrepo-kernel
python-perf.x86_64                                   5.6.7-1.el7.elrepo                      elrepo-kernel

这里选择 ml 版本安装:

yum --enablerepo=elrepo-kernel install kernel-ml

配置

查看 grub2 中配置的内核:

# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.6.7-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-a5c9d82b98ce4e54bd4cc8444d497181) 7 (Core)

设置第一个默认启动:

# grub2-set-default 0
# grub2-mkconfig -o /boot/grub2/grub.cfg

然后重启查看:

# uname -r
5.6.7-1.el7.elrepo.x86_64

可选:删除不用的内核

查看安装的内核:

# rpm -qa |grep kernel
kernel-tools-3.10.0-1062.el7.x86_64
kernel-tools-libs-3.10.0-1062.el7.x86_64
kernel-3.10.0-1062.el7.x86_64
kernel-ml-5.6.7-1.el7.elrepo.x86_64

删除指定的内核:

# yum remove kernel-3.10.0-1062.el7.x86_64

查看所有内核:

# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.6.7-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (0-rescue-a5c9d82b98ce4e54bd4cc8444d497181) 7 (Core)

Ansible playbook

通过 Ansible 可以批量或自动更新主机内核:

- hosts: 主机
  remote_user: root
  tasks:
  - name: add key
    rpm_key:
      state: present
      key: https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  - name: install elrepo7
    yum:
      name: https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
      state: present
  - name: install kernel-ml
    yum:
      name: kernel-ml
      enablerepo: elrepo-kernel
      state: present
  - name: grub2-set-default
    command: grub2-set-default 0
  - name: grub2-mkconfig
    command: grub2-mkconfig -o /boot/grub2/grub.cfg
  - name: reboot
    reboot:

注:reboot 命令要求的 ansble 2.7 版本
https://docs.ansible.com/ansible/latest/modules/reboot_module.html#reboot-module

isea533 CSDN认证博客专家 运维开发 系统架构
《MyBatis从入门到精通》作者,MyBatis分页插件PageHelper作者,通用Mapper作者,个人网站:https://mybatis.io
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页