I am trying to load balance ftp between 2 servers. currently 2 servers are pointed to ftp.domain.com, the second server is technically used for fault tolerance but I want to balance traffic between the 2 servers. How can I achieve this? I thought of making a simple script that would redirect users from ftp.domain to 01.ftp.domain and 02.ftp.domain etc but the problem is that FTP apps dont read pages so if a user attempts to login to ftp.domain it wont redirect them anywhere.
1 Answers
To load balance your servers you should consider both command and data channels. To load balance command channel I suggest you to use HAProxy. If you use it, you should specify in your /etc/haproxy/haproxy.cfg
the following:
listen ftp-lb00
bind IP:21
mode tcp
option tcplog
balance leastconn
server ftp-serv00 192.168.1.1:21 check
server ftp-serv01 192.168.1.2:21 check
IP here is a public ip whereas the connection is then redirected to 192.168.1.0/24 network. You should also define NAT forwarding in your iptables
. For instructions to do this you can look the accepted answer here (How can I port forward with iptables?).
To perform load balance of data channel you should run as root in terminal these commands
iptables -A POSTROUTING -s 192.168.1.1/32 -o eth1 -j SNAT --to-source IP
iptables -A POSTROUTING -s 192.168.1.2/32 -o eth1 -j SNAT --to-source IP
These settings are valid for so-called active data channel. For setup in passive data channel case and more detailed instructions, please, consult this article (https://gist.github.com/erkie/922996a2ec4125d79c7f8772cda328ce).

- 95
- 1
- 8

- 1,330
- 9
- 11