在 CentOS 上提升 SFTP 传输速度,可以从 网络、系统参数、SSH/SFTP 配置、磁盘、客户端 多个层面来优化。下面按实用程度给你一套常见且有效的优化方案。
先判断是 网络、CPU、磁盘 哪个拖慢了速度:
top
iostat -x 1
iftop
编辑:
vim /etc/ssh/sshd_config
# 使用更快的加密算法
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-ctr,aes256-ctr
# 启用压缩(仅低速网络有效,高速网络建议关闭)
Compression no
# 提高吞吐量
ClientAliveInterval 30
ClientAliveCountMax 3
✅ aes-gcm 比 aes-cbc 快很多,尤其是大文件
systemctl restart sshd
vim /etc/sysctl.conf
加入或修改:
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_congestion_control = cubic
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
生效:
sysctl -p
✅ 对 千兆 / 万兆网络 提升明显
sftp -oCiphers=aes128-gcm@openssh.com user@server
| 场景 | 建议 |
|---|---|
| 大量小文件 | rsync + SSH |
| 超大文件 | 直传 + 校验 |
| 高并发 | 多连接并行 |
rsync -avz --progress /data/ user@ip:/data/
或开启多线程:
rsync -avz --progress --parallel=4 user@ip:/data/ /data/
iostat -x 1
noatimemount -o remount,noatime /
UseDNS no
GSSAPIAuthentication no
| 系统 | 建议 |
|---|---|
| CentOS 7 | 升级 OpenSSH ≥ 7.8 |
| CentOS 8/Stream | 默认已较优 |
| CentOS 6 | ❌ 建议直接升级 |
✅ 使用 aes-gcm
✅ 调整 TCP 缓冲区
✅ 不直接用 SFTP 传大量小文件
✅ 检查磁盘 IO
✅ 关闭 DNS / GSSAPI
sshd_config你可以直接贴:
cat /etc/ssh/sshd_config
或说明: