温馨提示:这篇文章已超过890天没有更新,请注意相关的内容是否还可用!
摘要:本篇文章介绍了一种通过OpenVZ VPS开启BBR(Bottleneck Bandwidth and Round-trip time)加速的方法,并提供了一键脚本实现魔改BBR加速的便捷方式。该脚本能够简化操作过程,帮助用户快速配置网络参数,提升网络性能,优化网络连接体验。
BBR是由Google开发的一款开源的阻塞控制算法,无数的经验已经证明了BBR在网络较差的情况下有非常好的加速效果。但是OpenVZ构架的VPS由于内核版本较低(一般为2.6,内核版本4.9以上才自带原版BBR),又由于不独立,无法通过升级内核的方式来开启BBR加速。
好在网友们的智慧是无穷的,提供了多种不同的方法来为OpenVZ VPS开启BBR加速,但无外乎UML(User-Mode Linux)、LKL(LKL-Haproxy、LKL-Rinetd)两种方式。其中LKL比UML更简单,只需要转发端口,且LKL比UML占用资源更少,不过据说LKL的加速效果没有UML好。另外,UML和LKL-Haproxy都需要VPS支持并TUN/TAP,如果VPS后台无TUN/TAP功能,则只能使用LKL-Rinetd。
下面是本站收集的OpenVZ VPS开启BBR加速常见的脚本:
1.来自扩软博客的脚本(含魔改BBR)
1.1 扩软博客通过LKL-Rinetd开启BBR教程
1.1.1 手动搭建(仅支持 64 位系统)
下载文件到 /usr/bin/rinetd-bbr:
wget -O /usr/bin/rinetd-bbr https://github.com/linhua55/lkl_study/releases/download/v1.2/rinetd_bbr_powered
设置权限:
chmod a+x /usr/bin/rinetd-bbr
创建配置文件:
vi /etc/rinetd-bbr.conf
输入以下内容,其中的 443 请改为你的端口,IP 地址统一写 0.0.0.0:
# bindadress bindport connectaddress connectport 0.0.0.0 443 0.0.0.0 443
获取接口名称,看具有公网 IP 的接口名称(比如我的公网 IP 是 10.10.10.10),上面这种的接口是 venet0:0 而不是 venet0,搬瓦工的 OpenVZ 应该都是 venet0:0 接口:
# ip addr1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: venet0: <broadcast,pointopoint,noarp,up,lower_up> mtu 1500 qdisc noqueue state UNKNOWN link/void inet 127.0.0.2/32 scope host venet0 inet 10.10.10.10/32 brd 10.10.10.10 scope global venet0:0</broadcast,pointopoint,noarp,up,lower_up></loopback,up,lower_up>
启动,注意:将最后的接口改为你上面获取到的接口。在命令最后面加 & 以使其能后台运行:
/usr/bin/rinetd-bbr -f -c /etc/rinetd-bbr.conf raw venet0:0 &
1.1.2 验证
正常情况下的输出:
[ 0.000000] Linux version 4.10.0+ (root@gcc) (gcc version 4.9.4 (Ubuntu 4.9.4-2ubuntu1~14.04.1) ) #1 Mon Jul 31 04:50:50 UTC 2017[ 0.000000] bootmem address range: 0x7f2acc000000 - 0x7f2acffff000[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16159[ 0.000000] Kernel command line: virtio_mmio.device=268@0x1000000:1[ 0.000000] PID hash table entries: 256 (order: -1, 2048 bytes)[ 0.000000] Dentry cache hash table entries: 8192 (order: 4, 65536 bytes)[ 0.000000] Inode-cache hash table entries: 4096 (order: 3, 32768 bytes)[ 0.000000] Memory available: 64492k/0k RAM[ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1[ 0.000000] NR_IRQS:4096[ 0.000000] lkl: irqs initialized[ 0.000000] clocksource: lkl: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns[ 0.000001] lkl: time and timers initialized (irq2)[ 0.000003] pid_max: default: 4096 minimum: 301[ 0.000021] Mount-cache hash table entries: 512 (order: 0, 4096 bytes)[ 0.000023] Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)[ 0.009053] console [lkl_console0] enabled[ 0.009056] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns[ 0.009128] NET: Registered protocol family 16[ 0.009265] clocksource: Switched to clocksource lkl[ 0.009324] NET: Registered protocol family 2[ 0.009418] TCP established hash table entries: 512 (order: 0, 4096 bytes)[ 0.009421] TCP bind hash table entries: 512 (order: 0, 4096 bytes)[ 0.009503] TCP: Hash tables configured (established 512 bind 512)[ 0.009971] UDP hash table entries: 128 (order: 0, 4096 bytes)[ 0.009976] UDP-Lite hash table entries: 128 (order: 0, 4096 bytes)[ 0.010060] virtio-mmio: Registering device virtio-mmio.0 at 0x1000000-0x100010b, IRQ 1.[ 0.010186] workingset: timestamp_bits=62 max_order=14 bucket_order=0[ 0.010203] virtio-mmio virtio-mmio.0: Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.[ 0.010350] NET: Registered protocol family 10[ 0.010849] Segment Routing with IPv6[ 0.010859] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver[ 0.010993] Warning: unable to open an initial console.[ 0.011006] This architecture does not have kernel memory protection.[ 2.169284] random: fast init done
查看 iptables 规则,已经有两条规则了:
# iptables -t raw -nLChain PREROUTING (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 /* LKL_RAW */DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 /* LKL_RAW */ Chain OUTPUT (policy ACCEPT)target prot opt source destination
1.2 扩软博客通过LKL-Haproxy开启BBR脚本(含魔改版)
1.2.1 使用方法
已测试通过的系统: Ubuntu 14.04 x64、Ubuntu 16.04 x64、CentOS 6 x64、CentOS 7 x64 只支持 64 位系统,要求 glibc 版本 2.14 以上。
wget https://raw.githubusercontent.com/kuoruan/shell-scripts/master/ovz-bbr/ovz-bbr-installer.shchmod +x ovz-bbr-installer.sh./ovz-bbr-installer.sh
GitHub项目备份地址:https://github.com/6266/shell-scripts
需要配置的有如下几个选项:
1.需要加速的端口,加速开启之后,流量会先经过 BBR 处理。
2.可能需要配置 “公网接口名称”,即你服务器上具有公网 IP 的接口名称。搬瓦工 OpenVZ 上默认都是 venet0,但是有朋友可能需要安装在其他服务器上,所以我加入了此选项。
ip addr
需要注意的是,在有 firewalld 的服务器上安装的时候,firewalld 会干扰 iptables 的规则,造成网络不通(现在具体原因未知,谁有解决方案可以提示一下)。所以在装有 firewalld 的服务器上需要先退出 firewalld:
systemctl disable firewalldsystemctl stop firewalld
卸载:
./ovz-bbr-installer.sh uninstall
1.2.2 多端口加速
安装的时候只配置了一个加速端口,但是你可以配置多端口加速,配置方法非常简单。 修改文件:
vi /usr/local/haproxy-lkl/etc/port-rules
在文件里添加需要加速的端口,每行一条,可以配置单个端口或者端口范围,以 # 开头的行将被忽略。 例如:8800 或者 8800-8810 配置完成之后,只需要重启 haproxy-lkl 即可。
注: 最初版本的实现是需要再开一个新端口,后来经人提醒,我又看了一下 HAproxy 的配置说明,可以直接代理后端端口,不必再开新端口。请注意,使用该方法后,如果 HAproxy 进程异常退出,会造成无法连接原有端口。所以,请确保在退出 HAproxy 时是通过命令正常退出的,在退出时会自动清理原有的防火墙规则。
使用 systemctl 或者 service 命令来启动、停止和重启 HAporxy-lkl:
systemctl {start|stop|restart} haproxy-lkl service haproxy-lkl {start|stop|restart}
/usr/local/haproxy-lkl/etc/haproxy.cfg 这个文件是通过 port-rules 自动生成的,每次启动都会重新生成,所以直接修改它的配置没用。 如果想要自定义配置,请修改启动文件:
vi /usr/local/haproxy-lkl/sbin/haproxy-lkl
1.2.3 更新 glibc
wget http://ftp.redsleeve.org/pub/steam/glibc-2.15-60.el6.x86_64.rpm \http://ftp.redsleeve.org/pub/steam/glibc-common-2.15-60.el6.x86_64.rpm \http://ftp.redsleeve.org/pub/steam/glibc-devel-2.15-60.el6.x86_64.rpm \http://ftp.redsleeve.org/pub/steam/glibc-headers-2.15-60.el6.x86_64.rpm \http://ftp.redsleeve.org/pub/steam/nscd-2.15-60.el6.x86_64.rpm
然后安装:
rpm -Uvh glibc-2.15-60.el6.x86_64.rpm \glibc-common-2.15-60.el6.x86_64.rpm \glibc-devel-2.15-60.el6.x86_64.rpm \glibc-headers-2.15-60.el6.x86_64.rpm \nscd-2.15-60.el6.x86_64.rpm
如果以上步骤无法更新,可以手动编译更新(来自网友的方法):
wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gzwget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gztar -zxf glibc-2.15.tar.gztar -zxf glibc-ports-2.15.tar.gzmv glibc-ports-2.15 glibc-2.15/portsmkdir glibc-build-2.15cd glibc-build-2.15../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/binmake all && make install
检查一下(已经升级到 glibc 2.15 了):
ldd --versionldd (GNU libc) 2.15Copyright (C) 2012 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Written by Roland McGrath and Ulrich Drepper.
1.2.4 判断BBR是否正常工作
判断 bbr 是否正常启动可以尝试 ping 10.0.0.2,如果能通,说明 bbr 已经启动。然后检查 iptables 规则,里边会看到多了一张链表 LKL_IN,里边有相应的端口规则:
iptables -t nat -nLChain PREROUTING (policy ACCEPT)target prot opt source destinationLKL_IN all -- 0.0.0.0/0 0.0.0.0/0 Chain POSTROUTING (policy ACCEPT)target prot opt source destination Chain OUTPUT (policy ACCEPT)target prot opt source destination Chain LKL_IN (1 references)target prot opt source destinationDNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8989 to:10.0.0.2
2.来自南琴浪的脚本(魔改BBR)
2.1 南琴浪LKL-Rinetd一键脚本
2.1.1 概述
本项目 Github 地址: https://github.com/tcp-nanqinlang/lkl-rinetd
本项目备份 Github 地址:https://github.com/6266/lkl-rinetd
2.1.2 使用要求
OpenVZ
64 bit
Ram >> 64M
2.1.3 使用方法
Debian or Ubuntu:
适用于 单网卡(单 IP)
服务器:
wget https://github.com/tcp-nanqinlang/lkl-rinetd/releases/download/1.1.0/tcp_nanqinlang-rinetd-debianorubuntu.shbash tcp_nanqinlang-rinetd-debianorubuntu.sh
适用于 多网卡(多 IP)
服务器,会为所有网卡(所有 IP)提供加速:
wget https://github.com/tcp-nanqinlang/lkl-rinetd/releases/download/1.1.0/tcp_nanqinlang-rinetd-debianorubuntu-multiNIC.shbash tcp_nanqinlang-rinetd-debianorubuntu-multiNIC.sh
CentOS 7:
和上面一样,也分 单网卡 和 多网卡 版本:
# 单网卡wget https://github.com/tcp-nanqinlang/lkl-rinetd/releases/download/1.1.0/tcp_nanqinlang-rinetd-centos.shbash tcp_nanqinlang-rinetd-centos.sh# 多网卡wget https://github.com/tcp-nanqinlang/lkl-rinetd/releases/download/1.1.0/tcp_nanqinlang-rinetd-centos-multiNIC.shbash tcp_nanqinlang-rinetd-centos-multiNIC.sh
2.1.4 使用说明
安装 lkl-rinetd
此命令用于安装 lkl-rinetd。
在 /home/tcp_nanqinlang
进行安装,所以安装完成后不要动这个文件夹了(除非你想修改端口)。
安装过程中,会提示输入端口号。多个端口号用空格隔开。不支持端口段。
安装完成后,会开启 lkl-rinetd。以后重启机器也会随开机自启。
使用前请注意自己的 iptables 相关设置。
此命令用于检查 lkl-rinetd 运行与否,可通过返回的提示判断。
运行此命令会删除 /home/tcp_nanqinlang 、移除 rc.local 对应开机自启项和清空 iptables raw 表。属于完整卸载,不会有残留。且卸载后无需重启。
2.2 南琴浪LKL-HaProxy一键脚本
2.2.1 概述
本项目 Github 地址: https://github.com/tcp-nanqinlang/lkl-haproxy
本项目 备份Github 地址:https://github.com/6266/lkl-haproxy
2.2.2 使用要求
OpenVZ
64 bit
Ram >> 64M
支持并开启TUN/TAP
2.2.3 使用方法
以下适用于 Debian 8+ 环境:
# Debian 8+# 64 bit# ldd > = 2.14# tun/tap enabledwget https://github.com/tcp-nanqinlang/lkl-haproxy/releases/download/1.1.1/tcp_nanqinlang-haproxy-debian.shbash tcp_nanqinlang-haproxy-debian.sh
以下适用于 CentOS 7 环境:
# CentOS 7# 64 bit# ldd > = 2.14# tun/tap enabledwget https://github.com/tcp-nanqinlang/lkl-haproxy/releases/download/1.1.1/tcp_nanqinlang-haproxy-centos.shbash tcp_nanqinlang-haproxy-centos.sh
2.2.4 使用方法
以下进行脚本使用说明:
此命令用于安装 lkl-haproxy。
在 /home/tcp_nanqinlang
进行安装,所以安装完成后不要动这个文件夹了(除非你想修改端口)。
安装过程中,会提示你选择单个端口
或端口段
输入,具体已在运行脚本的提示中有说明,这里不再赘述。
安装完成后,会开启 lkl-haproxy。以后重启机器也会随开机自启。
以后若需要修改转发端口,请将 /home/tcp_nanqinlang/haproxy.cfg
中的端口号和 /home/tcp_nanqinlang/redirect.sh
中的端口号改为你想要的端口或端口段,修改完成后重启服务器。
使用前请注意自己的 iptables 相关设置。
此命令用于检查 lkl-haproxy 运行与否,可通过返回的提示判断。
运行此命令会卸载 haproxy、删除 /home/tcp_nanqinlang、移除 rc.local 开机自启项。稍后请自行移除 iptables
相关规则。
3.来自91yun的脚本(原版BBR)
GitHub项目备份地址:https://github.com/6266/uml
3.1 91yun LKL-Haproxy一键安装包
3.1.1 前置要求
LKL要求ldd的版本至少在
2.14
,目前我测试下来,如果不想折腾建议直接安装CentOS7
,Debian8
和Ubuntu16
。2、安装包只使用
64bit
的系统。3、默认的端口转发只转发了
9000-9999
的端口(可修改)。4、只适用
openvz
,后台需开启TUN/TAP
。
3.1.2 使用方法
wget --no-check-certificate https://github.com/91yun/uml/raw/master/lkl/install.sh && bash install.sh
判断是否安装成功,如果 10.0.0.2 能 ping 通说明成功, ping 不通说明失败:
ping 10.0.0.2
3.1.3 修改转发端口
修改/root/lkl/run.sh:
vim /root/lkl/run.sh# 按"/"查找9000-9999,按"i",进入编辑状态,改成你想要的端口段,按"Esc"推出编辑状态,按":wq"保存并退出
修改 /root/lkl/haproxy.cfg:
vim /root/lkl/haproxy.cfg# 按"/"查找9000-9999,按"i",进入编辑状态,改成你想要的端口段,按"Esc"推出编辑状态,按":wq"保存并退出
重启 VPS:
reboot
3.2 91yun UML BBR加速一键安装包
由于该一键安装包涉及SSR安装,所以这里不收录。
还没有评论,来说两句吧...