CentOS Linux 6 / 7 安装 BBR(来自 Google 的 TCP 拥塞控制算法)

本文最后一次更新于:2019 年 5 月 10 日 11:34:37

BBR 介绍:

TCP BBR( Bottleneck Bandwidth and Round-trip propagation time )是由 Google 设计,于 2016 年发布的拥塞算法。以往大部分拥塞算法是基于丢包来作为降低传输速率的信号,而 BBR 则基于模型主动探测。相对于传统的 TCP 拥塞控制算法,BBR 在充分利用网络带宽的同时,还能够大幅减少不必要的丢包。更多算法细节请参见该篇文章《 BBR 拥塞控制算法解析(来自 Google 的 TCP 拥塞控制算法)》。

Google 在 YouTube 上应用该算法,将全球平均的 YouTube 网络吞吐量提高了 4 % ,在一些国家超过了 14 % 。根据实地测试,在部署了最新版内核并开启了 TCP BBR 的机器上,网速甚至可以提升好几个数量级。

安装:

目前 Linux Kernel 4.09 及其以上版本(包括 5.x )已经集成了 BBR ,并且对于 QUIC 可用,所以只需要升级 Kernel 即可。

1 、使用一个 Linux Shell 脚本在 CentOS Linux 6 / 7 上安装 BBR :

为了方便批量安装于是 Ricky 在写完本篇文章的 8 个月后又写了一个自动化安装 BBR 的 Linux Shell 脚本,同时考虑到了一些细节问题(如在 CentOS Linux 6.x 上安装 BBR 前更新 nss 等),详情请看《使用 Linux Shell 脚本在 CentOS Linux 6 / 7 上安装 BBR(来自 Google 的 TCP 拥塞控制算法)》。

2 、在 CentOS Linux 6 上使用命令安装 BBR :

1 、进入你的 CentOS ,先升级你的 CentOS Linux 6 到最新的版本(当前最新版本是 6.10 ):

[root@host ~]# yum -y update

请使用如下命令查看 CentOS Linux 的版本号:

[root@host ~]# cat /etc/redhat-release 
CentOS release 6.10 (Final)

2 、再使用 yum 安装 wget(如果已经安装过,可忽略这步):

[root@host ~]# yum -y install wget

3 、Ricky 个人是喜欢把一些临时文件放到 /tmp 目录下,所以进入 /tmp 目录,使用 wget 命令把 kernel 的 rpm 包下载到这里,并安装这些 rpm 包:

64 位操作系统使用这个:
[root@host ~]# wget https://pan.ccie.lol:44944/file/Linux/CentOS/6/rpm/kernel-ml-4.18.20-1.el6.elrepo.x86_64.rpm -P /tmp/
[root@host ~]# wget https://pan.ccie.lol:44944/file/Linux/CentOS/6/rpm/kernel-ml-devel-4.18.20-1.el6.elrepo.x86_64.rpm -P /tmp/
[root@host ~]# rpm -ivh /tmp/kernel-ml-devel-4.18.20-1.el6.elrepo.x86_64.rpm
[root@host ~]# rpm -ivh /tmp/kernel-ml-4.18.20-1.el6.elrepo.x86_64.rpm
[root@host ~]# rm -f /tmp/kernel-ml-devel-4.18.20-1.el6.elrepo.x86_64.rpm /tmp/kernel-ml-4.18.20-1.el6.elrepo.x86_64.rpm

32 位操作系统使用这个:
[root@host ~]# wget https://pan.ccie.lol:44944/file/Linux/CentOS/6/rpm/kernel-ml-4.18.20-1.el6.elrepo.i686.rpm -P /tmp/
[root@host ~]# wget https://pan.ccie.lol:44944/file/Linux/CentOS/6/rpm/kernel-ml-devel-4.18.20-1.el6.elrepo.i686.rpm -P /tmp/
[root@host ~]# rpm -ivh /tmp/kernel-ml-devel-4.18.20-1.el6.elrepo.i686.rpm
[root@host ~]# rpm -ivh /tmp/kernel-ml-4.18.20-1.el6.elrepo.i686.rpm
[root@host ~]# rm -f /tmp/kernel-ml-devel-4.18.20-1.el6.elrepo.i686.rpm /tmp/kernel-ml-4.18.20-1.el6.elrepo.i686.rpm

4 、添加 BBR 相关配置,然后重启服务器:

[root@host ~]# sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
[root@host ~]# sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
[root@host ~]# sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf

[root@host ~]# echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
[root@host ~]# echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf

[root@host ~]# reboot

5 、CentOS Linux 6 重启完成后,请使用如下命令查看 BBR 是否开启:

[root@host ~]# cat /etc/redhat-release 
CentOS release 6.10 (Final)

[root@host ~]# uname -r
4.18.20-1.el6.elrepo.x86_64

[root@host ~]# lsmod | grep bbr
tcp_bbr                20480  135

[root@host ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic bbr

至此,安装完成。

3 、在 CentOS Linux 7 上使用命令安装 BBR :

1 、进入你的 CentOS ,先升级你的 CentOS Linux 7 到最新的版本(当前最新版本是 7.6 ):

[root@host ~]# yum -y update

请使用如下命令查看 CentOS Linux 的版本号:

[root@host ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

2 、安装 elrepo 并升级内核:

[root@host ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@host ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
[root@host ~]# yum --enablerepo=elrepo-kernel install kernel-ml kernel-ml-devel -y

3 、更新 grub 文件:

[root@host ~]# egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
[root@host ~]# grub2-set-default 0

4 、添加 BBR 相关配置:

[root@host ~]# echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
[root@host ~]# echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf

5 、重启服务器:

[root@host ~]# reboot

6 、CentOS Linux 7 重启完成后,请使用如下命令查看 BBR 是否开启:

[root@host ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

[root@host ~]# uname -r
5.1.0-1.el7.elrepo.x86_64

[root@host ~]# lsmod | grep bbr
tcp_bbr                20480  338 

[root@host ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic bbr

至此,安装完成。

这篇文章对你有帮助吗?

相关文章

1条评论

Ricky 发表评论 取消回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据