---
title: "搬瓦工 VPS 速度慢？揭秘让网速满血复活的内核魔法"
date: 2018-11-30T13:25:06.000Z
author: Z.SHINCHVEN
tags: [Bandwagonhost, VPS]
canonical: https://atlassc.net/2018/12/01/bandwagonhost-full-power-activated
---
入了一个年付 27.6 刀的搬瓦工黑五特别折扣版 VPS（2018 Black Friday Special V3 CN2），登录后发现官方已移除“一键部署服务”功能，原因是官方推出了专门的科学上网服务。既然如此，只能动手自己搭建。

然而，使用 Docker 搭建后发现性能与原先的一键版天差地别——从 4K 秒开跌落至 480P 卡顿。经过一番排查，终于找回了性能满血复活的关键配置。

## ⚡ 快速优化 (Quick Start)

如果你也遇到了同样的速度问题，请直接使用以下完整的优化配置。

### 1. 内核参数优化 (sysctl.conf)

将以下内容写入 `/etc/sysctl.conf` 文件，并执行 `sysctl -p` 生效。这份配置结合了官方文档的基础优化与搬瓦工旧版脚本的“魔法”参数（特别是 BBR 和网络邻居表配置）。

```conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536

# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 4294967295

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456

# --- Magic Configuration Starts Here ---
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr

net.ipv4.neigh.default.base_reachable_time_ms = 600000
net.ipv4.neigh.default.mcast_solicit = 20
net.ipv4.neigh.default.retrans_time_ms = 250
```

### 2. 文件描述符限制 (limits.conf)

编辑 `/etc/security/limits.conf`，增加以下配置以提升最大打开文件数：

```conf
root soft nofile 4096
root hard nofile 10000
```

如果您使用 Docker 部署，建议同时修改 `/etc/docker/daemon.json`：

```json
{
  "default-ulimits": {
    "nofile": {
      "Name": "nofile",
      "Hard": 10000,
      "Soft": 4096
    }
  }
}
```

---

## 性能骤降的排查过程

我自己使用热门的 Docker 镜像搭建服务，编写好 Shell 脚本和 Docker Compose 后，服务虽然跑起来了，但速度极慢。

### 怀疑方向

我最初怀疑了以下几个方面：

1.  **线路问题**：CN2 机房网络波动？
2.  **Docker 开销**：容器化带来的性能损耗？
3.  **软件版本**：安装程序或 OS 版本不匹配？

为了验证，我重置了老版本 VPS 的系统，尝试了多种一键脚本和手动安装，结果依然无法达到 KiwiVM 后台一键版的速度。这说明问题不在软件本身，而在**系统环境配置**。

## 官方文档与“魔法”的差异

在排查过程中，我查阅了官方文档的高级配置章节，并对比了**KiwiVM 一键安装过的 VPS** 与 **我自己手配的 VPS** 的内核参数。

虽然官方文档给出了一些标准的 Linux 优化参数（如 `shmmax`, `tcp_syncookies` 等），但我发现在 DigitalOcean 上这些配置效果并不显著。

真正起作用的，是旧版一键脚本中**未在文档中提及**的额外配置（即上方配置列表底部的 `bbr` 和 `neigh` 相关参数）。

## 最终效果

将这份提取出的 [完整配置](https://gist.github.com/ShinChven/5bcef1735dacabd8fae66a37ba622689#file-sysctl-conf) 应用到新 VPS 后，魔法终于生效，连接速度瞬间满血复活。

<div style="display: flex; justify-content: center;">
  <img src="https://blogimgs.atlassc.net/images/connection-speed-full-power-activated.jpg" alt="Connection Speed Full Power Activated" style="max-width: 100%; height: auto;">
</div>
