https://blog.kuoruan.com/115.html

Google BBR是一个TCP加速优化工具,类似于锐速,可用于优化 TCP 连接。最近一下就火起来了,说明还是有牛逼的地方,咱也别落后,用起来。

GitHub 地址为:https://github.com/google/bbr

仔细看了看,GitHub 主页上有明确的说明“This is not an official Google product.” 说明这其实不是 Google 的官方项目,但是是在 Google 的 GitHub 上,比较奇怪。

要想启用 BBR 需要切换内核,所以必须要 KVM 或者 XEN 架构的 VPS。这点和锐速一致,所以 Openvz 的朋友是用不了的。由于需要跟换内核,属于危险操作,请不要用于生产环境,可能会造成无法开机,切记!

至于加速效果,有人反馈比锐速好,有人反馈比锐速弱。我测试后感觉效果还是不错的,但是用起来比破解版锐速放心一些吧,它是内置到最新的内核里边了。

安装 BBR

1.一键安装脚本

网上有 BBR 的一键安装脚本,我找到两个:

可用于 CentOS 6。

可用于 Debian / Ubuntu 14.04 + (说明看这里:https://www.dou-bi.co/wlzy-16/)。

我是手动安装的,没测试过,请自测。CentOS 7 可以看这里:https://zhujiwiki.com/10156.html

2.手动安装方式

先看官方手动编译内核的文档:

https://github.com/google/bbr/blob/master/Documentation/bbr-quick-start.md

看起来比较麻烦,我们还是直接安装编译好的吧。

我的系统是 Ubuntu x64,可以直接到 ppa 仓库里下载:http://kernel.ubuntu.com/~kernel-ppa/mainline/

网页拉到最后,看最新的内核,当前最新的是 v4.10-rc5:http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10-rc5/

下载内核文件:

32位下这些:

其他内核版本请去上面的链接寻找。

下载完成之后可以开始安装了:

安装完成之后可以删除多余的内核:

然后更新一下 grub:

请确保至少存在一个内核,要不然会无法启动!!!

重启 vps:

重启之后,查看一下当前的内核:

已经是 4.10 了,现在可以启用 BBR 了:

使配置生效。

然后可以检查一下:

结果里边已经有 BBR 了,说明启用成功。没成功的话,再重启一下 VPS。

Debian 的手动安装方法可以看这里:https://moonagic.com/try-bbr/

 

BBR.sh 源码

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install BBR"
    exit
fi

clear
echo "+------------------------------------------------------------------------+"
echo "|                          GooGle TCP BBR                                |"
echo "+------------------------------------------------------------------------+"
echo "|        A tool to auto-compile & install BBR on CentOS                  |"
echo "+------------------------------------------------------------------------+"
echo "|                 Welcome to  http://github.com/52fancy                  |"
echo "+------------------------------------------------------------------------+"

Get_RHEL_Version()
{
    if grep -Eqi "release 5." /etc/redhat-release; then
        RHEL_Version='5'
    elif grep -Eqi "release 6." /etc/redhat-release; then
        RHEL_Version='6'
    elif grep -Eqi "release 7." /etc/redhat-release; then
        RHEL_Version='7'
    fi
}

Get_RHEL_Version
if [ $RHEL_Version != "6" ]; then
    echo "Error: You must be CentOS 6 to run this script, please use CentOS 6 to install BBR"
	exit
fi

Get_OS_Bit()
{
    if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
        OS_Bit='64'
    else
        OS_Bit='32'
    fi
}

Install()
{
    Get_OS_Bit
    if uname -r | grep -Eqi "4.10."; then
	    if lsmod | grep -Eqi "bbr"; then
		    echo "您已经成功安装BBR"
		    exit
		else
		    if [ ! `cat /etc/sysctl.conf | grep -i -E "net.core.default_qdisc=fq"` ]; then
		        echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
		    fi
		    if [ ! `cat /etc/sysctl.conf | grep -i -E "net.ipv4.tcp_congestion_control=bbr"` ]; then
		        echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
		    fi
		    sysctl -p
		fi
	else
	    if [ ! -f "/boot/grub/grub.conf" ];then
			echo "不支持当前系统,即将退出程序!"
			exit
		fi
		
	    echo -n "内核不一致,即将替换内核 [y or n]:"
		read code
		if [ $code = "y" -o $code = "Y" ]; then
		    if [ $OS_Bit = "64" ]; then
		        rpm -ivh http://elrepo.org/linux/kernel/el6/x86_64/RPMS/kernel-ml-4.10.1-1.el6.elrepo.x86_64.rpm --force
			fi
			if [ $OS_Bit = "32" ]; then
		        rpm -ivh http://elrepo.org/linux/kernel/el6/i386/RPMS/kernel-ml-4.10.1-1.el6.elrepo.i686.rpm --force
			fi
			
			kernel_default=`grep '^title ' /boot/grub/grub.conf | awk -F'title ' '{print i++ " : " $2}' | grep "4.10." | grep -v debug | cut -d' ' -f1`
			sed -i "s/^default.*/default=${kernel_default}/" /boot/grub/grub.conf
			
			if [ ! `cat /etc/sysctl.conf | grep -i -E "net.core.default_qdisc=fq"` ]; then
		        echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
		    fi
		    if [ ! `cat /etc/sysctl.conf | grep -i -E "net.ipv4.tcp_congestion_control=bbr"` ]; then
		        echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
		    fi
		    sysctl -p >/dev/null 2>&1
		
			rm -f $0
			read -p "重启后生效,是否重启?[y]:" is_reboot
			if [[ ${is_reboot} == "y" || ${is_reboot} == "Y" ]]; then
			    reboot
			else
			    exit
			fi
		else
		    echo "程序即将退出安装"
            exit
		fi
	fi
}
 
Install
exit