CentOS 7.3安装新内核并开启Google BBR加速的详细教程
Google 开源了其 TCP BBR 拥塞控制算法,并提交到了 Linux 内核,从 4.9 开始,Linux 内核已经用上了该算法。根据以往的传统,Google 总是先在自家的生产环境上线运用后,才会将代码开源,此次也不例外。
Google BBR在增加吞吐量和减少延迟有不错的效果,很多博客对此都有介绍,今天在VPS安装了一下,访问了该VPS上面的网站,感觉速度确实有所提升。
安装
centos7.3
1、yum系统更新(更新到CentOS 7.3)
1 | <span style="font-size: 14px;"><code>yum update</code></span> |
2、查看系统版本
1 | <span style="font-size: 14px;"><code>cat /etc/redhat-release</code></span> |
输出如下(release数值大于7.3即可),则表示已升级到7.3
1 | <span style="font-size: 14px;">CentOS Linux release 7.3.1611 (Core)</span> |
3、安装elrepo并升级内核
1 2 3 | <span style="font-size: 14px;"><code>rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org </span><span style="font-size: 14px;"><code>rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm </span><span style="font-size: 14px;"><code>yum --enablerepo=elrepo-kernel install kernel-ml -y</code></span> |
正常情况下将输出如下信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <span style="font-size: 14px;"><code>Transaction Summary </span><span style="font-size: 14px;"><code>================================================================================</code></span> <span style="font-size: 14px;"><code>Install 1 Package </span><span style="font-size: 14px;"><code>Total download size: 39 M </span><span style="font-size: 14px;"><code>Installed size: 169 M</code></span> <span style="font-size: 14px;"><code>Downloading packages:</code></span> <span style="font-size: 14px;"><code>kernel-ml-4.9.0-1.el7.elrepo.x86_64.rpm | 39 MB 00:00</code></span> <span style="font-size: 14px;"><code>Running transaction check</code></span> <span style="font-size: 14px;"><code>Running transaction test</code></span> <span style="font-size: 14px;"><code>Transaction test succeeded</code></span> <span style="font-size: 14px;"><code>Running transaction</code></span> <span style="font-size: 14px;"><code>Warning: RPMDB altered outside of yum.</code></span> <span style="font-size: 14px;"><code> Installing : kernel-ml-4.9.0-1.el7.elrepo.x86_64 1/1</code></span> <span style="font-size: 14px;"> Verifying : kernel-ml-4.9.0-1.el7.elrepo.x86_64 1/1</code></span> <span style="font-size: 14px;"><code>Installed:</code></span> <span style="font-size: 14px;"><code> kernel-ml.x86_64 0:4.9.0-1.el7.elrepo</code></span> <span style="font-size: 14px;"><code>Complete!</code></span> |
4、更新grub文件并重启(reboot后,ssh会断开,稍等一会儿重新连接)
1 2 3 | <span style="font-size: 14px;"><code>egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \' </span><span style="font-size: 14px;"><code>grub2-set-default 0 </span><span style="font-size: 14px;"><code>reboot</code></span> |
5、开机后查看内核是否已更换为4.9
1 | <span style="font-size: 14px;"><code>uname -r</code></span> |
输出如下内容则表示内核4.9已经启动了(数值大于4.9即可)
1 | <span style="font-size: 14px;"><code>4.9.0-1.el7.elrepo.x86_64</code></span> |
CentOS 7.4
导入 elrepo 软件源的 GPG 公钥
1 | <span style="font-size: 14px;"><code>rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</code></span> |
导入 elrepo 软件源
说明:该地址可以自动下载该源的最新的软件列表,无需修改地址。
1 | <span style="font-size: 14px;"><code>rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm</code></span> |
下载并安装新的内核
启用软件源并下载安装最新稳定版内核
1 | <span style="font-size: 14px;"><code>yum -y --enablerepo=elrepo-kernel install kernel-ml</code></span> |
设定 Grub 默认启动新内核
说明:如果手动修改过 Grub 的配置文件,以下命令可能无法执行成功。请自行修改 Grub 配置文件。
1 | <span style="font-size: 14px;"><code>grub2-set-default 0</code></span> |
使用新的内核重启
1 | <span style="font-size: 14px;"><code>reboot</code></span> |
检查设置 & 删除旧的内核
查看当前系统的内核版本号
1 | <span style="font-size: 14px;"><code>uname -r</code></span> |
如果输出是 4.10 以上的版本,说明安装成功。
1 | <span style="font-size: 14px;"><code>4.14.13-1.el7.elrepo.x86_64</code></span> |
删除旧内核
说明:删除旧内核的目的是为了防止 yum 更新旧版内核之后覆盖了 grub 默认启动项
1 | <span style="font-size: 14px;"><code>yum -y remove kernel kernel-tools</code></span> |
开启bbr
1 | <span style="font-size: 14px;"> <code>vim /etc/sysctl.conf</code></span> |
1 2 | <span style="font-size: 14px;"><code>net.core.default_qdisc = fq</code></span> <span style="font-size: 14px;"><code>net.ipv4.tcp_congestion_control = bbr</code></span> |
1 | <span style="font-size: 14px;"><code>sysctl -p</code></span> |
a.若
1 | <span style="font-size: 14px;"><code>sysctl net.ipv4.tcp_available_congestion_control</code></span> |
返回
1 | <span style="font-size: 14px;"><code>net.ipv4.tcp_available_congestion_control = bbr cubic reno</code></span> |
则成功
b.若
1 | <span style="font-size: 14px;"><code>lsmod | grep bbr</code></span> |
1 2 | <span style="font-size: 14px;"><code>tcp_bbr 16384 1</code></span> tcp_bbr 20480 0 |