优化 Debian 上的 FTP 服务器速度,需要从网络、系统、FTP 服务软件配置、磁盘 IO 等多方面入手。下面以最常见的 vsftpd(Debian 默认推荐)为主,给出实用优化方案。
被动模式(PASV)通常比主动模式更快、更稳定
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
pasv_address=你的公网IP
并在防火墙中开放:
ufw allow 30000:31000/tcp
编辑 /etc/vsftpd.conf:
# 关闭 DNS 反向解析(极大提升连接速度)
reverse_lookup_enable=NO
# 并发与连接数
max_clients=200
max_per_ip=10
# 传输优化
connect_from_port_20=YES
idle_session_timeout=300
data_connection_timeout=300
# 本地用户速度(可选)
local_max_rate=0 # 0 表示不限速
重启服务:
systemctl restart vsftpd
编辑 /etc/sysctl.conf:
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 0
生效:
sysctl -p
如果追求极致性能,可考虑:
| 服务 | 特点 |
|---|---|
| ProFTPD | 模块化,调优空间大 |
| Pure-FTPd | 轻量、稳定 |
| SFTP (OpenSSH) | 更安全,但略慢 |
示例(Pure-FTPd):
apt install pure-ftpd
pure-ftpd -p 30000:31000
# CPU
top
# 网络
iftop
# 磁盘
iostat -x 1
✅ 被动模式
✅ 关闭反向 DNS
✅ 调大 TCP 缓冲区
✅ SSD + 本地用户
✅ 多线程客户端
如果你愿意,我可以:
你现在的 FTP 是内网还是公网?用的是 vsftpd 吗?