Using Haproxy + shadowsocks (ha + ss) to setup multi ss backend and load balance
*Install haproxy
> sudo apt-get install haproxy
*Configure haproxy
>vim /etc/haproxy/haproxy.cfg
global
ulimit-n 51200
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend ss-in
mode tcp
bind $Your_IP:8002
default_backend shadowsocks
backend shadowsocks
mode tcp
balance roundrobin
server ss1 $Your_SS_IP1:$Your_SS_PORT1 maxconn 20480
server ss2 $Your_SS_IP2:$Your_SS_PORT2 maxconn 20480
--The haproxy only allows the remote ss servers with the same password. As here haproxy is only providing the function like a load balancing switch. It's like a multi channel valve which does NOT provide any shadowsocks protocol level functions. Haproxy only foward the packages from ss-in to ss-out and ss-out to ss-in.server ss2 $Your_SS_IP2:$Your_SS_PORT2 maxconn 20480
--The configuration above will setup ss1 and ss2 as the two channels to your remote shadowsocks server. And it will setup the frontend listen on the local port 8002 which acts like a real local ss server but actually load balanced remote servers ss1 and ss2.
*Restart haproxy
>sudo /etc/init.d/haproxy restart
评论
发表评论