redsocks icon indicating copy to clipboard operation
redsocks copied to clipboard

Automatic failover in case of proxy-server failure

Open hillz1 opened this issue 8 years ago • 2 comments

Hi @darkk

I have 3 socks5 proxies that I create with:

ssh -D 1080
ssh -D 1081
ssh -D 1082

Can I use redsocks to load balance those proxies ? perhaps I can configure the redsocks.conf to be something like this ?

redsocks {
    local_ip = 127.0.0.1;
    local_port = 11080;
    ip = 127.0.0.1;
    port = 1080;
    port = 1081;
    port = 1082;
    type = socks5;
}

If I can't, do you have an idea on how to do this ?

hillz1 avatar Dec 26 '16 15:12 hillz1

You can configure several local_ports to match several different ports like that:

redsocks {
    local_ip = 127.0.0.1; ip = 127.0.0.1; type = socks5;
    local_port = 11080;
    port = 1080;
}
redsocks {
    local_ip = 127.0.0.1; ip = 127.0.0.1; type = socks5;
    local_port = 11081;
    port = 1081;
}
redsocks {
    local_ip = 127.0.0.1; ip = 127.0.0.1; type = socks5;
    local_port = 11082;
    port = 1082;
}

And now the trick is to do proper load balancing as definition of «proper» varies a lot. I don't know if simple randomized load balancing is OK for you, but it can be implemented like that

iptables … -m random --mode random --probability 0.3333333333 -j REDIRECT --to-ports 11080
iptables … -m random --mode random --probability 0.3333333333 -j REDIRECT --to-ports 11081
iptables … -j REDIRECT --to-ports 11082

darkk avatar Dec 27 '16 21:12 darkk

I want to do dynamic load balancing, so first it has to check whether the first socks proxy is online, if it's not then skip that proxy and check the second one, if the second one is online then switch to that proxy, it should continuously do that, any ideas on how to achieve such a thing ?

hillz1 avatar Dec 28 '16 07:12 hillz1