提升 Ubuntu 的收发速度(网络吞吐、文件传输、系统响应等)可以从网络、磁盘、系统配置、应用层几个方向来优化。下面按常见场景给你一套实用方案。
ip a
ethtool eth0 # 查看网卡速率
ping -c 10 8.8.8.8
speedtest-cli # 网络测速
sudo ethtool -K eth0 gro on
sudo ethtool -K eth0 gso on
sudo ethtool -K eth0 tso on
sudo ethtool -G eth0 rx 4096 tx 4096
编辑:
sudo nano /etc/sysctl.conf
加入或修改:
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.core.rmem_default = 67108864
net.core.wmem_default = 67108864
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_congestion_control = cubic
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_fastopen = 3
生效:
sudo sysctl -p
sudo nano /etc/systemd/resolved.conf
DNS=8.8.8.8 1.1.1.1
sudo systemctl restart systemd-resolved
sudo nano /etc/fstab
UUID=xxxx / ext4 defaults,noatime 0 1
cat /sys/block/sda/queue/scheduler
推荐:
none 或 mq-deadlinebfq临时设置:
echo mq-deadline | sudo tee /sys/block/sda/queue/scheduler
free -h
如果 swap 太小:
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
ulimit -n
永久修改:
sudo nano /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
systemctl list-unit-files --type=service | grep enabled
sudo systemctl disable bluetooth
sudo nano /etc/ssh/sshd_config
Compression no
sudo systemctl restart ssh
rsync -ah --progress source/ user@ip:/dest/
echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
检查:
lsmod | grep bbr
top
htop
iotop
iftop
nload
| 场景 | 建议 |
|---|---|
| 下载慢 | DNS + TCP 参数 |
| 文件传输慢 | rsync + MTU |
| SSH 卡 | 关闭压缩 |
| 高并发 | BBR |
| 磁盘慢 | IO 调度 + noatime |
如果你愿意,可以告诉我:
我可以帮你精准定制一套优化方案。