╃苍狼山庄╃╃苍狼山庄╃

Clang出品,
必属精品!

CentOS6.X 7.X升级内核新版本

前言

由于安装Docker时,Docker支持

CentOS 7 (64-bit)
CentOS 6.5 (64-bit) 或更高的版本

Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本

CentOS 7 的内核一般都是3.10的,而CentOS 6.X 的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到3.10版本。

升级内核的方式,网上有很多方法是下载内核然后编译,这样需要安装很多必备的环境和工具,比较麻烦,但是也有助于我们了解内核的编译。

这里介绍直接安装的方法:

1. 查看当前内核版本

[root@localhost ~]# more /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

2. 导入public key

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

3. 安装ELRepo到CentOS

可以去http://elrepo.org/tiki/tiki-index.php 选择要安装的ELRepo,要使用这个内核,需要安装yum-plugin-fastestmirror

RHEL-7, SL-7 or CentOS-7执行下面命令:

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

RHEL-6, SL-6 or CentOS-6执行下面命令:

rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

4. 安装 kernel

1)安装 kernel-lt(lt=long-term)

yum --enablerepo=elrepo-kernel install kernel-lt

2)安装kernel-ml(ml=mainline)

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

5. 编辑grub.conf文件,修改Grub引导顺序

1)CentOS 7

查看内核顺序:

awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

显示结果:

0 : CentOS Linux (4.15.7-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-693.21.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-693.17.1.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
4 : CentOS Linux (0-rescue-033e4dda56c7f927aaea40b35994e058) 7 (Core)

设置默认启动内核:

grub2-set-default 0

2)CentOS 6

vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_have-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/xvda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (4.14.0-1.el6.elrepo.x86_64)
    root (hd0,0)
    kernel /vmlinuz-4.14.0-1.el6.elrepo.x86_64 ro root=/dev/mapper/vg_have-lv_root rd_LVM_LV=vg_have/lv_root rd_LVM_LV=vg_have/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us console=hvc0 crashkernel=auto rhgb quiet
    initrd /initramfs-4.14.0-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-696.13.2.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-696.13.2.el6.x86_64 ro root=/dev/mapper/vg_have-lv_root rd_LVM_LV=vg_have/lv_root rd_LVM_LV=vg_have/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us console=hvc0 crashkernel=auto rhgb quiet
    initrd /initramfs-2.6.32-696.13.2.el6.x86_64.img

[info_box]因为一般新安装的内核在第一个位置,所以设置default=0,表示启动新内核[/info_box]

6. 重启

重启后查看此时内核版本:

[root@localhost ~]# uname -r
4.14.0-1.el6.elrepo.x86_64

7. 其他设置

1)BBR设置

内核升级完成后,可以安装docker或者设置BBR,下面说一下BBR设置:

#设置bbr
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
#保存生效
sysctl -p
#查看内核是否已开启BBR
sysctl net.ipv4.tcp_available_congestion_control
#查看BBR是否启动
lsmod | grep bbr

2)Docker安装

安装支持包:

sudo yum install -y yum-utils  device-mapper-persistent-data  lvm2

添加源:

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装Docker:

sudo yum install docker-ce

启动Docker:

sudo systemctl start docker
本原创文章未经允许不得转载 | 当前页面:╃苍狼山庄╃ » CentOS6.X 7.X升级内核新版本

评论

文章评论已关闭!