搭载SSR && BBR

来源:互联网 发布:宝宝鼻屎 知乎 编辑:程序博客网 时间:2024/04/29 19:46

效果图

这里写图片描述

安装SSR

一键部署ssr代码(虽然代码兼容SS客户端,但最好用SSR客户端,因为SSR客户端可以用SSR混淆协议)如下:

yum -y install wgetwget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR.shchmod +x shadowsocksR.sh./shadowsocksR.sh 2>&1 | tee shadowsocksR.log

推荐0板瓦工,内置了ssr和ssr 还有openvpn,非常非常省事,1年只要200块….

下载SSR客户端

复制服务器完成安装后显示的SSR链接 右键 剪切板批量导入ssr://链接

安装BBR(kvm)

这个一键加速取自秋水逸冰,感谢作者!

wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.shchmod +x bbr.sh./bbr.sh

可以根据根据下面命令进行查询是否加速成功

uname -r

返回 : 4.10.4-1.el6.elrepo.i686

sysctl net.ipv4.tcp_congestion_control

返回 : net.ipv4.tcp_congestion_control = bbr

lsmod | grep bbr

返回: tcp_bbr 20480 65

安装BBR(openvz)

本方法取自扩软博客

已测试通过的系统: 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

需要配置的有如下几个选项:

1.需要加速的端口,即的 SS 端口。加速开启之后,流量会先经过 BBR 处理,之后再发送给后端的 SS。
2.可能需要配置 “公网接口名称”,即你服务器上具有公网 IP 的接口名称。搬瓦工 OpenVZ 上默认都是 venet0,但是有朋友可能需要安装在其他服务器上,所以我加入了此选项。
需要注意的是,在有 firewalld 的服务器上安装的时候,firewalld 会干扰 iptables 的规则,造成网络不通(现在具体原因未知,谁有解决方案可以提示一下)。所以在装有 firewalld 的服务器上需要先退出 firewalld:

systemctl disable firewalldsystemctl stop firewalld

如需卸载,请使用:

./ovz-bbr-installer.sh uninstall

错误说明

有些机器一切正常,但是加速失败。从网友的反馈来看,可能需要将 SS 的监听地址从 vps IP 改到 127.0.0.1 或者 0.0.0.0,具体未测试,加速失败的朋友可以试一试

多端口加速

安装的时候只配置了一个加速端口,但是你可以配置多端口加速,配置方法非常简单。 修改文件

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-lklservice haproxy-lkl {start|stop|restart}

/usr/local/haproxy-lkl/etc/haproxy.cfg 这个文件是通过 port-rules 自动生成的,每次启动都会重新生成,所以直接修改它的配置没用。 如果想要自定义配置,请修改启动文件:

/usr/local/haproxy-lkl/sbin/haproxy-lkl

更新 glibc

CentOS 6 更新 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

检查一下:

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.

已经升级到 glibc 2.15 了。

判断 BBR 已正常工作

判断 bbr 是否正常启动可以尝试 ping 10.0.0.2,如果能通,说明 bbr 已经启动。
然后检查 iptables 规则

iptables -t nat -nLChain PREROUTING (policy ACCEPT)target     prot opt source               destinationLKL_IN     all  --  0.0.0.0/0            0.0.0.0/0Chain POSTROUTING (policy ACCEPT)target     prot opt source               destinationChain OUTPUT (policy ACCEPT)target     prot opt source               destinationChain 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
原创粉丝点击