在美国VPS上搭建转发服务,加速服务器上搭建haproxy服务
使用原理: PC->加速服务器frontend->加速服务器backend->美国 VPS
1.安装haproxy:
centos:
yum install haproxy -y
注: 如果yum找不到haproxy的话, 需要下载执行一下:
#CentOS 5 – 32-bit
rpm -Uvh http://mirror.overthewire.com.au/pub/epel/5/i386/epel-release-5-4.noarch.rpm
#CentOS 5 – 64-bit
rpm -Uvh http://mirror.overthewire.com.au/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
#CentOS 6 – 32-bit
rpm -Uvh http://mirror.overthewire.com.au/pub/epel/6/i386/epel-release-6-8.noarch.rpm
#CentOS 6 – 64-bit
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
ubuntu
apt-get install haproxy
debian
先添加apt源
vi /etc/apt/sources.list
然后添加源
deb http://ftp.us.debian.org/debian/ wheezy-backports main
保存后
apt-get update
然后安装haproxy
apt-get install haproxy
2.修改haproxy配置文件,使用脚本启动haproxy
vi /etc/default/haproxy
将该选项修改为1 ENABLED=1
3.修改配置文件
vi /etc/haproxy/haproxy.cfg
单户:
global
ulimit-n 51200
defaults
log global
mode tcp
option dontlognull
contimeout 1000
clitimeout 150000
srvtimeout 150000
frontend ss-in
bind *:8968
default_backend ss-out
backend ss-out
server server1 SS_IP:8968 maxconn 20480 #SS_IP是ss的ip,8968是SS的端口
多户或者均衡
global
ulimit-n 51200
defaults
log global
mode tcp
option dontlognull
timeout connect 1000ms
timeout client 150000ms
timeout server 150000ms
frontend 110-in
bind *:110
default_backend 110-out
frontend 109-in
bind *:109
default_backend 109-out
frontend 110-in-jp
bind *:1110
default_backend 110-out-jp
backend 110-out
server server1 spg.xx.xx:110 maxconn 20480
backend 109-out
server server1 spg.xx.xx:109 maxconn 20480
backend 110-out-jp
server server1 jp.xx.xx:110 maxconn 20480
可以配置多端口。
frontend的端口为要在中转服务器上用的端口
backend的端口是源服务器的ip和端口
每个端口的“frontend” 要对应一个“backend”
文件写的时候要记得一一对应。
4.启动服务,检查修改是否生效
service haproxy start
如果前面没设置开机启动,就运行一下:
update-rc.d haproxy defaults
关闭防火墙
sudo ufw disable
借鉴
http://blog.e9china.net/tufan/centos5liyonghaproxyshadowsockszhongzhuan.html
http://www.crazycen.com/internet/2225.html
https://smileawei.com/shadowsocks-haproxy/
文章评论
这样做的意义是什么呢?加速服务器上不能直接搭ss吗?
@panzhc 加速服务器是在国内,搭建SS 没意义