Debian/Ubuntu TCP BBR 改进版/增强版

2017-07-03T00:38:00

背景:

原版的BBR对于我们来说,速度不太稳定.
通过修改BBR源码,调整参数,使其更强劲.

准备:

使用前,请确认能够开启BBR.
可参考: Debian/Ubuntu 开启 TCP BBR 拥塞算法
或者直接执行此命令进行开启.

 
wget --no-check-certificate -qO 'BBR.sh' 'https://moeclub.org/attachment/LinuxShell/BBR.sh' && chmod a+x BBR.sh && bash BBR.sh -f

注意:执行此命令会自动重启.


一键地址:

 

 
wget --no-check-certificate -qO 'BBR_POWERED.sh' 'https://moeclub.org/attachment/LinuxShell/BBR_POWERED.sh' && chmod a+x BBR_POWERED.sh && bash BBR_POWERED.sh

 


说明:

      • 执行过程中会重新编译模块.
      • 模块默认为开机自动加载.
      • 模块名称:tcp_bbr_powered
      • 可用 modprobe tcp_bbr_powered 命令进行加载模块.
      • 可执行 lsmod |grep 'bbr_powered'
        结果不为空,则加载模块成功
      • 可执行 sysctl -w net.ipv4.tcp_congestion_control=bbr_powered 使用此模块.

以上只是说明,直接使用一键脚本即可.


完整代码:

 

 
#!/bin/bash
 
[ "$EUID" -ne '0' ] && echo "Error,This script must be run as root! " && exit 1
[ -z "$(dpkg -l |grep 'grub-')" ] && echo "Not found grub." && exit 1
which make >/dev/null 2>&1
[ $? -ne '0' ] && {
echo "Install make..."
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq make >/dev/null 2>&1
which make >/dev/null 2>&1
[ $? -ne '0' ] && {
echo "Error! Install make. "
exit 1
}
}
which gcc-4.9 >/dev/null 2>&1
[ $? -ne '0' ] && {
echo "Install gcc-4.9..."
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq gcc-4.9 >/dev/null 2>&1
which gcc-4.9 >/dev/null 2>&1
[ $? -ne '0' ] && {
echo "Error! Install gcc-4.9. "
exit 1
}
}
MainURL='http://kernel.ubuntu.com/~kernel-ppa/mainline'
KernelVer="$(wget -qO- "$MainURL" |awk -F '/">|href="' '{print $2}' |sed '/rc/d;/^$/d' |tail -n1)"
[ -n "$KernelVer" ] && ReleaseURL="$(echo -n "$MainURL/$KernelVer")"
KernelBit="$(getconf LONG_BIT)"
KernelBitVer=''
[ "$KernelBit" == '32' ] && KernelBitVer='i386'
[ "$KernelBit" == '64' ] && KernelBitVer='amd64'
[ -z "$KernelBitVer" ] && echo "Error! " && exit 1
HeadersFile="$(wget -qO- "$ReleaseURL" |awk -F '">|href="' '/generic.*.deb/{print $2}' |grep 'headers' |grep "$KernelBitVer" |head -n1)"
[ -n "$HeadersFile" ] && HeadersAll="$(echo "$HeadersFile" |sed 's/-generic//g;s/_'${KernelBitVer}'.deb/_all.deb/g')"
[ -z "$HeadersAll" ] && echo "Error! Get Linux Headers for All." && exit 1
echo "$HeadersFile" | grep -q "$(uname -r)"
[ $? -ne '0' ] && echo "Error! Header not be matched by Linux Kernel." && exit 1
echo -ne "Download Kernel Headers for All\n\t$HeadersAll\n"
wget -qO "$HeadersAll" "$ReleaseURL/$HeadersAll"
echo -ne "Install Kernel Headers for All\n\t$HeadersAll\n"
dpkg -i "$HeadersAll" >/dev/null 2>&1
echo -ne "Download Kernel Headers\n\t$HeadersFile\n"
wget -qO "$HeadersFile" "$ReleaseURL/$HeadersFile"
echo -ne "Install Kernel Headers\n\t$HeadersFile\n"
dpkg -i "$HeadersFile" >/dev/null 2>&1
echo -ne "Download BBR POWERED Source code\n"
[ -e ./tmp ] && rm -rf ./tmp
mkdir -p ./tmp && cd ./tmphttps://moeclub.org/2017/06/24/278/
[ $? -eq '0' ] && {
wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxSoftware/bbr/tcp_bbr_powered.c.deb' >./tcp_bbr_powered.c
echo 'obj-m:=tcp_bbr_powered.o' >./Makefile
make -s -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=`which gcc-4.9`
echo "Loading TCP BBR POWERED..."
[ -f ./tcp_bbr_powered.ko ] && [ -f /lib/modules/$(uname -r)/modules.dep ] && {
cp -rf ./tcp_bbr_powered.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a >/dev/null 2>&1
}
modprobe tcp_bbr_powered
[ ! -f /etc/sysctl.conf ] && touch /etc/sysctl.conf
sed -i '/net.core.default_qdisc.*/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_congestion_control.*/d' /etc/sysctl.conf
echo "net.core.default_qdisc = fq" >>/etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr_powered" >>/etc/sysctl.conf
}
lsmod |grep -q 'bbr_powered'
[ $? -eq '0' ] && {
sysctl -p >/dev/null 2>&1
echo "Finish! "
exit 0
} || {
echo "Error, Loading BBR POWERED."
exit 1
}

 


注意事项:

如遇报错:Error! Header not be matched by Linux Kernel.
请用使用本博客提供的脚本重新开启BBR,可直接参考本篇中的准备步骤.
如遇报错:Error! Install gcc-4.9.
首先尝试apt-get update,再次执行此脚本.
如果未解决想办法自行安装gcc-4.9,或切换系统后再试.
本脚本在Debian8,Ubuntu16.04上通过测试.

 

via。https://moeclub.org/2017/06/24/278/

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »
因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合MIP标准。