VPS 性能优化指南 - Linux 内核调优、网络加速、系统优化
让你的 VPS 发挥最大性能
中文 | English
# 编辑配置文件
vim /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_congestion_control = bbr
net.core.default_qdisc = fq
# TCP 优化
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
# 文件描述符
fs.file-max = 65535
fs.nr_open = 65535
# 内存优化
vm.swappiness = 10
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
# 应用配置
sysctl -p# 查看 TCP 参数
sysctl -a | grep tcp
# 修改 TCP 缓冲区大小
sysctl -w net.ipv4.tcp_rmem='4096 87380 16777216'
sysctl -w net.ipv4.tcp_wmem='4096 65536 16777216'# 查看网卡队列
ethtool -l eth0
# 设置队列数量
ethtool -L eth0 combined 4
# 查看中断分布
cat /proc/interrupts | grep eth0# 创建 SWAP (2GB)
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# 添加到 fstab
echo '/swapfile none swap sw 0 0' >> /etc/fstab
# 调整 swappiness (越小越少使用 SWAP)
sysctl vm.swappiness=10# 启用 ZRAM (压缩内存)
modprobe zram
zramctl --find --size 2G
mkswap /dev/zram0
swapon /dev/zram0# 查看当前调度器
cat /sys/block/sda/queue/scheduler
# 设置为 deadline (适合 SSD)
echo deadline > /sys/block/sda/queue/scheduler
# 或者设置为 noop (适合虚拟化环境)
echo noop > /sys/block/sda/queue/scheduler# 挂载参数优化 (ext4)
mount -o remount,noatime,nodiratime /
# /etc/fstab 添加
/dev/sda1 / ext4 defaults,noatime,nodiratime 0 1# 检查是否支持 BBR
modprobe tcp_bbr
lsmod | grep bbr
# 开启 BBR
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
# 验证
sysctl net.ipv4.tcp_congestion_control
lsmod | grep bbr# BBR 相关参数
net.ipv4.tcp_bbr_budget = 0
net.ipv4.tcp_bbr_cwnd_gain = 2
net.ipv4.tcp_bbr_drain_gain = 1
net.ipv4.tcp_bbr_min_gain = 1| 名称 | 说明 | 链接 |
|---|---|---|
| VPSVIP | VPS 主机测评与推荐 | 官网 |
MIT License - 2026