zoukankan      html  css  js  c++  java
  • centos升级内核

    一、查看当前内核版本

    
    [root@server-1 home]# uname -a
    Linux server-1 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

    内核版本为3.10

    二、安装elrepo的yum源

    Centos 6 YUM源:http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

    Centos 7 YUM源:http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

    首先导入elrepo的key

    [root@server-1 home]# rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

    然后安装elrepo的yum源

    [root@server-1 home]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
    获取http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
    获取http://elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:elrepo-release-7.0-4.el7.elrepo  ################################# [100%]
    [root@server-1 home]# 

    设置好yum源后,可以查看可用的内核安装包

    [root@server-1 home]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
    已加载插件:fastestmirror
    Determining fastest mirrors
     * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
    elrepo-kernel                                                                                        | 2.9 kB  00:00:00     
    elrepo-kernel/primary_db                                                                             | 1.9 MB  00:00:01     
    可安装的软件包
    kernel-lt.x86_64                                              4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-devel.x86_64                                        4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-doc.noarch                                          4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-headers.x86_64                                      4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-tools.x86_64                                        4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-tools-libs.x86_64                                   4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-lt-tools-libs-devel.x86_64                             4.4.207-1.el7.elrepo                             elrepo-kernel
    kernel-ml.x86_64                                              5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-devel.x86_64                                        5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-doc.noarch                                          5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-headers.x86_64                                      5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-tools.x86_64                                        5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-tools-libs.x86_64                                   5.4.7-1.el7.elrepo                               elrepo-kernel
    kernel-ml-tools-libs-devel.x86_64                             5.4.7-1.el7.elrepo                               elrepo-kernel
    perf.x86_64                                                   5.4.7-1.el7.elrepo                               elrepo-kernel
    python-perf.x86_64                                            5.4.7-1.el7.elrepo                               elrepo-kernel
    [root@server-1 home]# 

    关于内核版本的定义如下:

    版本性质:主分支ml(mainline),稳定版(stable),长期维护版(longterm)

    kernel-ml.x86_64为主线版,当前为5.4.7

    kernel-lt.x86_64为长期维护版,当前为4.4.207

    三、升级内核

    [root@server-1 home]# yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * elrepo: mirrors.tuna.tsinghua.edu.cn
     * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.aliyun.com
    base                                                                                                 | 3.6 kB  00:00:00     
    dell-system-update_dependent                                                                         | 2.3 kB  00:00:00     
    dell-system-update_independent                                                                       | 2.3 kB  00:00:00     
    elrepo                                                                                               | 2.9 kB  00:00:00     
    extras                                                                                               | 2.9 kB  00:00:00     
    updates                                                                                              | 2.9 kB  00:00:00     
    (1/3): extras/7/x86_64/primary_db                                                                    | 153 kB  00:00:00     
    (2/3): elrepo/primary_db                                                                             | 438 kB  00:00:02     
    (3/3): updates/7/x86_64/primary_db                                                                   | 5.9 MB  00:00:02     
    正在解决依赖关系
    --> 正在检查事务
    ---> 软件包 kernel-ml.x86_64.0.5.4.7-1.el7.elrepo 将被 安装
    ---> 软件包 kernel-ml-devel.x86_64.0.5.4.7-1.el7.elrepo 将被 安装
    --> 解决依赖关系完成
    
    依赖关系解决
    
    ============================================================================================================================
     Package                        架构                  版本                               源                            大小
    ============================================================================================================================
    正在安装:
     kernel-ml                      x86_64                5.4.7-1.el7.elrepo                 elrepo-kernel                 48 M
     kernel-ml-devel                x86_64                5.4.7-1.el7.elrepo                 elrepo-kernel                 13 M
    
    事务概要
    ============================================================================================================================
    安装  2 软件包
    
    总下载量:61 M
    安装大小:267 M
    Downloading packages:
    (1/2): kernel-ml-devel-5.4.7-1.el7.elrepo.x86_64.rpm                                                 |  13 MB  00:00:13     
    (2/2): kernel-ml-5.4.7-1.el7.elrepo.x86_64.rpm                                                       |  48 MB  00:00:33     
    ----------------------------------------------------------------------------------------------------------------------------
    总计                                                                                        1.8 MB/s |  61 MB  00:00:33     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
    警告:RPM 数据库已被非 yum 程序修改。
    ** 发现 1 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
    smbios-utils-bin-2.3.3-8.el7.x86_64 有缺少的需求 libsmbios = ('0', '2.3.3', '8.el7')
      正在安装    : kernel-ml-devel-5.4.7-1.el7.elrepo.x86_64                                                               1/2 
      正在安装    : kernel-ml-5.4.7-1.el7.elrepo.x86_64                                                                     2/2 
      验证中      : kernel-ml-5.4.7-1.el7.elrepo.x86_64                                                                     1/2 
      验证中      : kernel-ml-devel-5.4.7-1.el7.elrepo.x86_64                                                               2/2 
    
    已安装:
      kernel-ml.x86_64 0:5.4.7-1.el7.elrepo                     kernel-ml-devel.x86_64 0:5.4.7-1.el7.elrepo                    
    
    完毕!
    [root@server-1 home]# 

    对于一些无法上网的服务器,或者需要安装指定版本内核的需求,我们可以把kernel image的rpm包下载下来安装,下载地址如下:

    下载指定版本 kernel: http://rpm.pbone.net/index.php3?stat=3&limit=1&srodzaj=3&dl=40&search=kernel

    下载指定版本 kernel-devel:http://rpm.pbone.net/index.php3?stat=3&limit=1&srodzaj=3&dl=40&search=kernel-devel

    官方 Centos 6: http://elrepo.org/linux/kernel/el6/x86_64/RPMS/

    官方 Centos 7: http://elrepo.org/linux/kernel/el7/x86_64/RPMS/

    将rpm包下载上传到服务器上,使用下面的命令安装即可:

    # yum -y install kernel-ml-devel-4.12.4-1.el7.elrepo.x86_64.rpm 
    # yum -y install kernel-ml-4.12.4-1.el7.elrepo.x86_64.rpm

    四、修改grub中默认的内核版本

    内核升级完毕后,目前内核还是默认的版本,如果此时直接执行reboot命令,重启后使用的内核版本还是默认的3.10,不会使用新的安装的版本,我们可以通过命令查看默认启动顺序:

    [root@server-1 ~]# cat /etc/grub2.cfg |grep menuentry
    if [ x"${feature_menuentry_id}" = xy ]; then
      menuentry_id_option="--id"
      menuentry_id_option=""
    export menuentry_id_option
    menuentry 'CentOS Linux (5.4.7-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-382d3d45-f099-432a-8323-3b89a19e8e3c' {
    menuentry 'CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-382d3d45-f099-432a-8323-3b89a19e8e3c' {
    menuentry 'CentOS Linux (0-rescue-06394465633042fba137279e22a218b6) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-06394465633042fba137279e22a218b6-advanced-382d3d45-f099-432a-8323-3b89a19e8e3c' {
    [root@server-1 ~]# 

    可以看到新版本内核在位置0,老版本内核在位置1,我们只需要将内核启动顺序修改为0,就可以使用新版本内核

    root@server-1 ~]# vim /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="console"
    GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
    GRUB_DISABLE_RECOVERY="true"

    将GRUB_DEFAULT=saved修改为GRUB_DEFAULT=0

    GRUB_TIMEOUT=5
    GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
    GRUB_DEFAULT=0
    GRUB_DISABLE_SUBMENU=true
    GRUB_TERMINAL_OUTPUT="console"
    GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
    GRUB_DISABLE_RECOVERY="true"

    接下来运行命令来重新创建内核配置:

    [root@server-1 ~]# grub2-mkconfig -o /boot/grub2/gurb.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-5.4.7-1.el7.elrepo.x86_64
    Found initrd image: /boot/initramfs-5.4.7-1.el7.elrepo.x86_64.img
    Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-06394465633042fba137279e22a218b6
    Found initrd image: /boot/initramfs-0-rescue-06394465633042fba137279e22a218b6.img
    done

    五、重启系统

    [root@server-1 ~]# reboot

    六、查看版本

    [root@localhost ~]# uname -a
    Linux localhost.localdomain 5.4.7-1.el7.elrepo.x86_64 #1 SMP Tue Dec 31 11:30:50 EST 2019 x86_64 x86_64 x86_64 GNU/Linux
    [root@localhost ~]# 

    可以看到已经是使用最新安装的内核版本了。

    七、清理缓存并生成新的缓存

    [root@localhost ~]# yum clean all
    已加载插件:fastestmirror
    正在清理软件源: base dell-system-update_dependent dell-system-update_independent elrepo extras updates
    Cleaning up list of fastest mirrors
    Other repos take up 10 M of disk space (use --verbose for details)
    [root@localhost ~]# 
    [root@localhost ~]# yum makecache
    已加载插件:fastestmirror
    Determining fastest mirrors
     * base: mirrors.huaweicloud.com
     * elrepo: mirrors.tuna.tsinghua.edu.cn
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.huaweicloud.com
    base                                                                                                 | 3.6 kB  00:00:00     
    dell-system-update_dependent                                                                         | 2.3 kB  00:00:01     
    dell-system-update_independent                                                                       | 2.3 kB  00:00:00     
    elrepo                                                                                               | 2.9 kB  00:00:00     
    extras                                                                                               | 2.9 kB  00:00:00     
    updates                                                                                              | 2.9 kB  00:00:00     
    (1/19): base/7/x86_64/group_gz                                                                       | 165 kB  00:00:00     
    (2/19): base/7/x86_64/other_db                                                                       | 2.6 MB  00:00:04     
    (3/19): base/7/x86_64/filelists_db                                                                   | 7.3 MB  00:00:04     
    (4/19): dell-system-update_dependent/7/x86_64/primary_db                                             |  32 kB  00:00:10     
    (5/19): dell-system-update_dependent/7/x86_64/other_db                                               | 7.1 kB  00:00:00     
    (6/19): dell-system-update_independent/filelists_db                                                  |  53 kB  00:00:05     
    (7/19): elrepo/filelists_db                                                                          |  38 kB  00:00:00     
    (8/19): elrepo/primary_db                                                                            | 438 kB  00:00:00     
    (9/19): elrepo/other_db                                                                              |  32 kB  00:00:00     
    (10/19): extras/7/x86_64/filelists_db                                                                | 207 kB  00:00:00     
    (11/19): extras/7/x86_64/primary_db                                                                  | 153 kB  00:00:00     
    (12/19): extras/7/x86_64/other_db                                                                    | 100 kB  00:00:00     
    (13/19): updates/7/x86_64/filelists_db                                                               | 3.3 MB  00:00:00     
    (14/19): dell-system-update_independent/other_db                                                     |  25 kB  00:00:04     
    (15/19): updates/7/x86_64/primary_db                                                                 | 5.9 MB  00:00:02     
    (16/19): updates/7/x86_64/other_db                                                                   | 368 kB  00:00:02     
    (17/19): dell-system-update_independent/primary_db                                                   | 111 kB  00:00:14     
    (18/19): dell-system-update_dependent/7/x86_64/filelists_db                                          |  80 kB  00:00:29     
    base/7/x86_64/primary_db       FAILED                                          ==-        ]  35 kB/s |  21 MB  00:02:50 ETA 
    http://mirrors.tuna.tsinghua.edu.cn/centos/7.7.1908/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.tuna.tsinghua.edu.cn/centos/7.7.1908/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
    正在尝试其它镜像。
    (19/19): base/7/x86_64/primary_db                                                                    | 6.0 MB  00:00:02     
    元数据缓存已建立
    [root@localhost ~]# 

     八、更新YUM库

    [root@localhost ~]# yum update
  • 相关阅读:
    5.线性回归算法
    4.K均值算法--应用
    3.K均值算法
    机器学习2
    机器学习1
    第十五次作业
    第十三次作业
    第十一次作业
    P1250 种树
    P1516 青蛙的约会
  • 原文地址:https://www.cnblogs.com/sky-cheng/p/12146054.html
Copyright © 2011-2022 走看看