Linux FTP Server 负载均衡实践指南
一、方案总览与适用场景
二、四层转发型方案 HAProxy 与 Nginx Stream
HAProxy 示例(推荐)
global
log /dev/log local0
log /dev/log local1 notice
daemon
defaults
log global
mode tcp
option tcplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend ftp_front
bind *:21
default_backend ftp_back
backend ftp_back
balance roundrobin
server ftp1 192.168.1.101:21 check
server ftp2 192.168.1.102:21 check
server ftp3 192.168.1.103:21 check
Nginx Stream 示例(支持 SSL/TLS 终止或透传)
stream {
upstream ftp_servers {
server 192.168.1.101:21;
server 192.168.1.102:21;
server 192.168.1.103:21;
}
server {
listen 21;
proxy_pass ftp_servers;
# 如需在负载均衡器终止 TLS,可添加证书并启用 ssl 指令
# ssl_certificate /path/to/cert.crt;
# ssl_certificate_key /path/to/key.key;
# ssl_protocols TLSv1.2 TLSv1.3;
}
}
三、内核级 LVS + Keepalived 方案
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication { auth_type PASS; auth_pass 42 }
virtual_ipaddress { 192.168.1.100 }
}
virtual_server 192.168.1.100 21 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.101 21 {
weight 1
TCP_CHECK { connect_timeout 10; connect_port 21 }
}
real_server 192.168.1.102 21 {
weight 1
TCP_CHECK { connect_timeout 10; connect_port 21 }
}
real_server 192.168.1.103 21 {
weight 1
TCP_CHECK { connect_timeout 10; connect_port 21 }
}
}
四、被动模式与防火墙要点
五、安全与运维实践