Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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 (http://ben.timby.com/?page_id=210).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.