这几天BBR很火的样子,我就半夜测试一下。BBR和锐速都属于TCP拥塞控制技术,虽然这类技术互联网上面不少,不过我都不是很了解。
本文章仅为我个人的测试,各地区测试情况不一样,而且BBR还处于开发初期并且开源,而锐速则已经停止开发了。
一键脚本安装:『原创』Debian/Ubuntu系统 TCP拥塞控制技术 ——TCP-BBR 一键安装脚本
注意:TCP-BBR和锐速一样,不支持Openvz,查看本教程之前,请先确定你的VPS的虚拟化技术!
注意:本教程涉及到VPS更换内核,所以如果步骤错误,或者VPS不兼容最新的内核,会导致无法开机等错误,请勿用于生产环境!!!!
启动步骤
首先是教程,本人喜欢Debian,所以我先使用 Debian 7 / 8 x64 系统来做测试。Ubuntu随后考虑加上。
每一个步骤,我都会加上VPS中执行后的提示,本教程以64位为例。但是各个系统可能会存在差异,所以仅为参考。
在 2016-12-05 21:00 更新的 4.9.0-rc8 内核已经支持了TCP-BBR,最新内核看这里。(目前最新的是 4.9.0 正式版)
注意:TCP-BBR必须是 2016-12-05 21:00 更新的 4.9.0-rc8 内核及以后的版本 才能开启,而锐速并不支持这个最新的内核版本,所以TCP-BBR和锐速是不能共存的。
下载内核文件(64位系统)
- wget –O linux–image–4.9.0–amd64.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb
下载内核文件(32位系统)
- wget –O linux–image–4.9.0–i386.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_i386.deb
- # VPS提示(64位)
- root@bbr1:~# wget -O linux-image-4.9.0-amd64.deb http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb
- converted ‘http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb’ (ANSI_X3.4–1968) -> ‘http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9-rc8/linux-image-4.9.0-040900rc8-generic_4.9.0-040900rc8.201612051443_amd64.deb’ (UTF–8)
- —2016–12–08 15:31:16— http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb
- Resolving kernel.ubuntu.com (kernel.ubuntu.com)… 91.189.94.216
- Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
- HTTP request sent, awaiting response… 200 OK
- Length: 60489324 (58M) [application/x–debian–package]
- Saving to: ‘linux-image-4.9.0-amd64.deb’
- linux–image–4.9.0–040900 100%[=====================================>] 57.69M 3.02MB/s in 14s
- 2016–12–08 15:31:31 (4.05 MB/s) – ‘linux-image-4.9.0-amd64.deb’ saved [60489324/60489324]
安装内核(64位)
- dpkg –i linux–image–4.9.0–amd64.deb
安装内核(32位)
- dpkg –i linux–image–4.9.0–i386.deb
- # VPS提示
- root@bbr1:~# dpkg -i linux-image-4.9.0-amd64.deb
- Selecting previously unselected package linux–image–4.9.0–040900rc8–generic.
- (Reading database … 25141 files and directories currently installed.)
- Preparing to unpack linux–image–4.9.0–040900rc8–generic_4.9.0–040900rc8.201612051443_amd64.deb …
- Done.
- Unpacking linux–image–4.9.0–040900rc8–generic (4.9.0–040900rc8.201612051443) …
- Setting up linux–image–4.9.0–040900rc8–generic (4.9.0–040900rc8.201612051443) …
- Running depmod.
- update–initramfs: deferring update (hook will be called later)
- Examining /etc/kernel/postinst.d.
- run–parts: executing /etc/kernel/postinst.d/apt–auto–removal 4.9.0–040900rc8–generic /boot/vmlinuz–4.9.0–040900rc8–generic
- run–parts: executing /etc/kernel/postinst.d/initramfs–tools 4.9.0–040900rc8–generic /boot/vmlinuz–4.9.0–040900rc8–generic
- update–initramfs: Generating /boot/initrd.img–4.9.0–040900rc8–generic
- run–parts: executing /etc/kernel/postinst.d/zz–update–grub 4.9.0–040900rc8–generic /boot/vmlinuz–4.9.0–040900rc8–generic
- Generating grub configuration file …
- Found linux image: /boot/vmlinuz–4.9.0–040900rc8–generic
- Found initrd image: /boot/initrd.img–4.9.0–040900rc8–generic
- Found linux image: /boot/vmlinuz–3.16.0–4–amd64
- Found initrd image: /boot/initrd.img–3.16.0–4–amd64
- done
列出并删除旧内核
列出VPS 除了刚才安装的内核以外的 所有内核名称:
注意:这个代码是排除了刚才安装的 4.9.0内核,所以不会显示刚才安装的那个内核。删除了多余的内核后,就会什么都不显示!
- dpkg –l|grep linux–image | awk ‘{print $2}’ | grep –v ‘linux-image-4.9.0-040900-generic’
- root@bbr1:~# dpkg -l|grep linux-image | awk ‘{print $2}’ | grep -v ‘linux-image-4.9.0-040900-generic’
- linux–image–3.16.0–4–amd64
- linux–image–amd64
我使用的VPS是 3.16.0-4-amd64
内核的,所以删除这两个内核:linux-image-3.16.0-4-amd64、linux-image-amd64
。
删除旧内核:
- apt–get purge 旧内核名称
- # !!!!示例!!!!
- # 比如我是有这两个内核,所以我把这两个删掉,不要照着我的这个步骤做,自己换成你VPS的内核名称!!!
- apt–get purge linux–image–3.16.0–4–amd64
- apt–get purge linux–image–amd64
- # !!!!示例!!!!
删除旧内核的过程中会提示你是否继续,选择 Y
,然后还会提示你是否终止删除内核的行为,选择 NO
。
- # VPS提示
- root@bbr1:~# apt-get purge linux-image-3.16.0-4-amd64
- Reading package lists… Done
- Building dependency tree
- Reading state information… Done
- The following packages were automatically installed and are no longer required:
- libuuid–perl linux–base
- Use ‘apt-get autoremove’ to remove them.
- The following packages will be REMOVED:
- linux–image–3.16.0–4–amd64* linux–image–amd64*
- 0 upgraded, 0 newly installed, 2 to remove and 7 not upgraded.
- After this operation, 164 MB disk space will be freed.
- Do you want to continue? [Y/n] y
- (Reading database … 31152 files and directories currently installed.)
- Removing linux–image–3.16.0–4–amd64 (3.16.36–1+deb8u2) …
- Ok, proceeding with removing running kernel image.
- /etc/kernel/postrm.d/initramfs–tools:
- update–initramfs: Deleting /boot/initrd.img–3.16.0–4–amd64
- /etc/kernel/postrm.d/zz–update–grub:
- Generating grub configuration file …
- Found linux image: /boot/vmlinuz–4.9.0–040900rc8–generic
- Found initrd image: /boot/initrd.img–4.9.0–040900rc8–generic
- done
- The link /vmlinuz.old is a damaged link
- Removing symbolic link vmlinuz.old
- You may need to re–run your boot loader
- The link /initrd.img.old is a damaged link
- Removing symbolic link initrd.img.old
- You may need to re–run your boot loader
- Purging configuration files for linux–image–3.16.0–4–amd64 (3.16.36–1+deb8u2) …
- # ================================================
- root@bbr1:~# apt-get purge linux-image-amd64
- Reading package lists… Done
- Building dependency tree
- Reading state information… Done
- The following packages were automatically installed and are no longer required:
- libuuid–perl linux–base
- Use ‘apt-get autoremove’ to remove them.
- The following packages will be REMOVED:
- linux–image–amd64*
- 0 upgraded, 0 newly installed, 1 to remove and 7 not upgraded.
- After this operation, 164 MB disk space will be freed.
- Do you want to continue? [Y/n] y
- (Reading database … 31152 files and directories currently installed.)
- Removing linux–image–amd64 (3.16.36–1+deb8u2) …
- Ok, proceeding with removing running kernel image.
- /etc/kernel/postrm.d/initramfs–tools:
- update–initramfs: Deleting /boot/initrd.img–amd64
- /etc/kernel/postrm.d/zz–update–grub:
- Generating grub configuration file …
- Found linux image: /boot/vmlinuz–4.9.0–040900rc8–generic
- Found initrd image: /boot/initrd.img–4.9.0–040900rc8–generic
- done
- The link /vmlinuz.old is a damaged link
- Removing symbolic link vmlinuz.old
- You may need to re–run your boot loader
- The link /initrd.img.old is a damaged link
- Removing symbolic link initrd.img.old
- You may need to re–run your boot loader
- Purging configuration files for linux–image–amd64 (3.16.36–1+deb8u2) …
- # ================================================
- # 最后在看一下内核是否只剩下教程安装的内核。
- root@bbr1:~# dpkg -l|grep linux-image | awk ‘{print $2}’
- ii linux–image–4.9.0–040900–generic 4.9.0–040900rc8.201612051443 amd64 Linux kernel image for version 4.9.0 on 64 bit x86 SMP
更新 grub 系统引导文件并重启VPS
- # 更新系统引导文件
- update–grub
- # 重启VPS,执行后SSH链接会断开,等十几秒再重新连接继续执行下面的启动命令。
- reboot
- # VPS提示
- root@bbr1:~# update-grub
- Generating grub configuration file …
- Found linux image: /boot/vmlinuz–4.9.0–040900rc8–generic
- Found initrd image: /boot/initrd.img–4.9.0–040900rc8–generic
- done
开启bbr
- echo “net.core.default_qdisc=fq” >> /etc/sysctl.conf
- echo “net.ipv4.tcp_congestion_control=bbr” >> /etc/sysctl.conf
执行这个保存生效更改。
- sysctl –p
- # VPS提示
- root@bbr1:~# sysctl -p
- net.ipv6.conf.all.accept_ra = 2
- net.core.default_qdisc = fq
- net.ipv4.tcp_congestion_control = bbr
关闭bbr
- sed –i ‘/net\.core\.default_qdisc=fq/d’ /etc/sysctl.conf
- sed –i ‘/net\.ipv4\.tcp_congestion_control=bbr/d’ /etc/sysctl.conf
- sysctl –p
执行完上面的代码,就使用reboot重启VPS后才能关闭bbr,重启后再用下面的查看bbr状态代码,查看是否关闭了。
- reboot
查看bbr是否开启
执行下面命令,如果结果中有bbr,即证明你的内核已开启bbr。
- sysctl net.ipv4.tcp_available_congestion_control
执行下面命令,看到有 tcp_bbr 模块,即说明bbr已启动
- lsmod | grep bbr
- # VPS提示
- root@bbr1:~# sysctl net.ipv4.tcp_available_congestion_control
- net.ipv4.tcp_available_congestion_control = bbr cubic reno
- # ================================================
- root@bbr1:~# lsmod | grep bbr
- tcp_bbr 20480 0
因为BBR是集成在内核中的,所以不能卸载,除非更换其他的内核。
裸 SS/锐速+SS/BBR+SS 速度对比
本人的测试环境是:晚上23:00点,联通运营商,美国渣渣VPS。
各个地区和运营商都存在差别,我的测试 速度对比仅供参考。谷歌网盘单线程下载测速地址:100MB
因为是半夜测试的,再加上用的美国垃圾小鸡,所以 裸SS 速度感人。
使用 锐速+SS 后,单线程下载测速,翻了十倍,Youtube 也能看 1080P流畅 了。
换成 BBR+SS 后,单线程又在 锐速+SS 的基础上翻了一倍,Youtube 速度有上升了一个档次 1440P 倒是勉强,1080P可以随便拖拉了。
虽然 Youtube 的数值不是很准,但是还是有点用的,数值太低同样也代表速度不行。
总其以上,锐速(ServerSpeed)的技术已经成熟、定型,加速效果还是不错的,但是不再更新和维护了。
而 TCP-BBR 属于新生的技术,处于开发初期,买没有完善成熟,未来的潜力相信还好更好。
所以总的来说:非折腾党,还是建议先使用锐速观望 TCP-BBR 一段时间,这是最稳妥的办法。
裸 SS
锐速+SS
BBR+SS
本文章安装步骤来自:https://github.com/iMeiji/shadowsocks_install/wiki/开启TCP-BBR拥塞控制算法
责任声明:本站一切资源均原创或收集自互联网,仅作交流学习之用,请勿用作商业!如造成任何后果,本站概不负责!