童东生 Java 程序员

搬瓦工vps加速(BBR安装)教程

2018-06-13
vps

OpenVZ 安装 BBR

虚拟化:OpenVZ

系统:Ubuntu 14.04 x64、Ubuntu 16.04 x64、CentOS 6 x64、CentOS 7 x64 

内存:128MB以上 

只支持 64 位系统,要求 glibc 版本 2.14 以上

  1. 安装 脚本下载并执行
    wget https://raw.githubusercontent.com/kuoruan/shell-scripts/master/ovz-bbr/ovz-bbr-installer.sh 
    chmod +x ovz-bbr-installer.sh 
    ./ovz-bbr-installer.sh
    

    需要配置的选项:

    1. 端口,即你用到的端口。开启后,流量先经过 BBR 处理,然后发送给指定端口。
    2. 可能需要配置“公网接口名称”,即你服务器上具有公网 IP 的接口名称。搬瓦工 OpenVZ 上默认都是 venet0,不需要配置。 在有 firewalld 的服务器上安装的时候,firewalld 会干扰 iptables 的规则,造成网络不通(现在具体原因未知,谁有解决方案可以提示一下)。所以在装有 firewalld 的服务器上需要先退出 firewalld:
      systemctl disable firewalld 
      systemctl stop firewalld
      
  2. 卸载
    ./ovz-bbr-installer.sh uninstall
    
  3. 多端口配置 安装的时候只配置了一个加速端口,但是你可以配置多端口加速,配置方法非常简单。 修改文件
    vim /usr/local/haproxy-lkl/etc/port-rules
    

    在文件里添加需要加速的端口,每行一条,可以配置单个端口或者端口范围,以 # 开头的行将被忽略。 例如:8800 或者 8800-8810 配置完成之后,只需要重启 haproxy-lkl 即可。

  4. 启动、停止、重启 HAproxy-lkl
    systemctl {start|stop|restart} haproxy-lkl
    

    或者

    service haproxy-lkl {start|stop|restart}
    

    如果想自定义配置(新手请忽略)

    /usr/local/haproxy-lkl/sbin/haproxy-lkl
    
  5. 更新 glibc 如果 glibc 版本过低,可以进行更新。如:CentOS 6: 
     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.gz
     wget http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz
     tar -zxf glibc-2.15.tar.gz
     tar -zxf glibc-ports-2.15.tar.gz
     mv glibc-ports-2.15 glibc-2.15/ports
     mkdir glibc-build-2.15
     cd glibc-build-2.15
     ../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
     make all && make install
    

    检查一下

    ldd --version
    ldd (GNU libc) 2.15
    Copyright (C) 2012 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Written by Roland McGrath and Ulrich Drepper.
    
  6. 判断 BBR 是否工作 判断 bbr 是否正常启动可以尝试 ping 10.0.0.2,如果能通,说明 bbr 已经启动。
    检查一下 iptables 规则
    iptables -t nat -nL
    Chain PREROUTING (policy ACCEPT)
    target     prot opt source               destination
    LKL_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               destination
    DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8989 to:10.0.0.2
    

KVM、Xen 安装 BBR

虚拟化:KVM、Xen等,除了OpenVZ基本都行 

系统:CentOS 6+,Debian 7+,Ubuntu 12+  

内存:128MB以上  

  1. 安装 使用root登陆VPS,输入下面命令:
    $ wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
    $ chmod +x bbr.sh
    $ ./bbr.sh
    

    完成后,提示重启,输入y并重启VPS。
    2. 验证是否安装成功

    $ uname -r
    

    查看内核版本,含有 4.10 就表示 OK 了

    $ sysctl net.ipv4.tcp_available_congestion_control
    net.ipv4.tcp_available_congestion_control = bbr cubic reno
    

    执行:

    $ sysctl net.ipv4.tcp_congestion_control
    net.ipv4.tcp_congestion_control = bbr
    

    执行:

    $ sysctl net.core.default_qdisc
    net.core.default_qdisc = fq
    

    执行:

    $ lsmod | grep bbr
    

    返回值有 tcp_bbr 模块即说明bbr已启动。


评论

文章目录