<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>Sam</name>
  </author>
  <generator uri="https://hexo.io/">Hexo</generator>
  <id>https://sam.xx.kg/</id>
  <link href="https://sam.xx.kg/" rel="alternate"/>
  <link href="https://sam.xx.kg/atom.xml" rel="self"/>
  <rights>All rights reserved 2026, Sam</rights>
  <subtitle>虚拟化 · 代理网络 · 服务器运维</subtitle>
  <title>Sam's Blog</title>
  <updated>2026-06-30T11:01:03.499Z</updated>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="服务器运维" scheme="https://sam.xx.kg/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/"/>
    <category term="PVE" scheme="https://sam.xx.kg/tags/PVE/"/>
    <category term="Proxmox" scheme="https://sam.xx.kg/tags/Proxmox/"/>
    <category term="LXC" scheme="https://sam.xx.kg/tags/LXC/"/>
    <category term="Docker" scheme="https://sam.xx.kg/tags/Docker/"/>
    <category term="OCI" scheme="https://sam.xx.kg/tags/OCI/"/>
    <category term="容器" scheme="https://sam.xx.kg/tags/%E5%AE%B9%E5%99%A8/"/>
    <content>
      <![CDATA[<blockquote><p><strong>PVE 9.2</strong> 引入了 <strong>OCI Application Container</strong>（技术预览），可以直接从 Docker Hub 拉取 OCI 镜像并在 LXC 中运行，无需安装 Docker 守护进程。本文对比三种方式，覆盖从原生 OCI 到传统 Docker in VM 的完整方案。</p></blockquote><hr><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li><a href="#%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F%E5%AF%B9%E6%AF%94">三种方式对比</a></li><li><a href="#%E6%96%B9%E5%BC%8F%E4%B8%80%E5%8E%9F%E7%94%9F-oci-application-containerpve-9x-%E6%96%B0%E5%8A%9F%E8%83%BD">方式一：原生 OCI Application Container（PVE 9.x 新功能）</a></li><li><a href="#%E6%96%B9%E5%BC%8F%E4%BA%8Cdocker-in-lxc-%E5%AE%B9%E5%99%A8">方式二：Docker in LXC 容器</a></li><li><a href="#%E6%96%B9%E5%BC%8F%E4%B8%89docker-in-vm-%E8%99%9A%E6%8B%9F%E6%9C%BA">方式三：Docker in VM 虚拟机</a></li><li><a href="#%E5%9C%BA%E6%99%AF%E9%80%89%E6%8B%A9%E6%8C%87%E5%8D%97">场景选择指南</a></li><li><a href="#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">常见问题</a></li></ul><hr><h2 id="三种方式对比"><a href="#三种方式对比" class="headerlink" title="三种方式对比"></a>三种方式对比</h2><table><thead><tr><th>特性</th><th>方式一：OCI App Container</th><th>方式二：Docker in LXC</th><th>方式三：Docker in VM</th></tr></thead><tbody><tr><td><strong>是否需要 Docker daemon</strong></td><td>否（PVE 原生运行）</td><td>是</td><td>是</td></tr><tr><td><strong>隔离性</strong></td><td>中等（共享内核）</td><td>中等（共享内核）</td><td><strong>高</strong>（独立内核）</td></tr><tr><td><strong>性能开销</strong></td><td><strong>极低</strong></td><td>低</td><td>中等</td></tr><tr><td><strong>镜像来源</strong></td><td>Docker Hub &#x2F; 任意 OCI Registry</td><td>Docker Hub</td><td>Docker Hub</td></tr><tr><td><strong>支持 Docker Compose</strong></td><td>否（路线图中）</td><td>是</td><td>是</td></tr><tr><td><strong>PVE 管理集成</strong></td><td><strong>完全集成</strong>（WebUI 管理）</td><td>有限（需进入容器操作）</td><td>有限</td></tr><tr><td><strong>快照&#x2F;备份</strong></td><td>PVE 原生支持</td><td>PVE 原生支持</td><td>PVE 原生支持</td></tr><tr><td><strong>Live Migration</strong></td><td>重启迁移</td><td>重启迁移</td><td>支持</td></tr><tr><td><strong>兼容性</strong></td><td>单进程应用最佳</td><td>多数 Docker 应用</td><td><strong>全部</strong> Docker 应用</td></tr><tr><td><strong>状态</strong></td><td><strong>技术预览</strong></td><td>成熟</td><td>成熟</td></tr></tbody></table><hr><h2 id="方式一：原生-OCI-Application-Container（PVE-9-x-新功能）"><a href="#方式一：原生-OCI-Application-Container（PVE-9-x-新功能）" class="headerlink" title="方式一：原生 OCI Application Container（PVE 9.x 新功能）"></a>方式一：原生 OCI Application Container（PVE 9.x 新功能）</h2><p>PVE 9.x 引入了 <strong>OCI（Open Container Initiative）镜像支持</strong> 作为技术预览。你可以直接从 Docker Hub 或任何 OCI 注册表拉取镜像，PVE 会自动将其转换为 LXC 容器运行——<strong>不需要安装 Docker</strong>。</p><h3 id="适用场景"><a href="#适用场景" class="headerlink" title="适用场景"></a>适用场景</h3><ul><li>运行单进程&#x2F;单服务的 OCI 镜像（Nginx、Redis、MySQL、PostgreSQL 等）</li><li>需要 PVE 原生管理（WebUI 创建&#x2F;监控&#x2F;备份）</li><li>不想在系统里装 Docker daemon</li></ul><h3 id="拉取-OCI-镜像"><a href="#拉取-OCI-镜像" class="headerlink" title="拉取 OCI 镜像"></a>拉取 OCI 镜像</h3><h4 id="方式-A：WebUI-拉取"><a href="#方式-A：WebUI-拉取" class="headerlink" title="方式 A：WebUI 拉取"></a>方式 A：WebUI 拉取</h4><ol><li>左侧选择节点 → 展开 <strong>local (pve1)</strong> 存储</li><li>切换到 <strong>CT Templates</strong> 标签页</li><li>点击 <strong>Pull from OCI registry</strong></li><li>输入镜像名称（如 <code>docker.io/library/nginx:latest</code>）</li><li>点击 <strong>Pull</strong>，等待下载完成</li></ol><h4 id="方式-B：CLI-拉取"><a href="#方式-B：CLI-拉取" class="headerlink" title="方式 B：CLI 拉取"></a>方式 B：CLI 拉取</h4><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 拉取 Nginx 镜像</span></span><br><span class="line">pveam update</span><br><span class="line">pct oci pull docker.io/library/nginx:latest</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看已下载的 OCI 模板</span></span><br><span class="line">pveam list <span class="built_in">local</span> --oci</span><br></pre></td></tr></table></figure><h3 id="支持的镜像格式"><a href="#支持的镜像格式" class="headerlink" title="支持的镜像格式"></a>支持的镜像格式</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">docker.io/library/nginx:latest</span><br><span class="line">docker.io/library/redis:7-alpine</span><br><span class="line">docker.io/library/postgres:16</span><br><span class="line">docker.io/library/mysql:8.0</span><br><span class="line">ghcr.io/owner/image:tag</span><br><span class="line">registry.example.com/myapp:1.0</span><br></pre></td></tr></table></figure><h3 id="创建-Application-Container"><a href="#创建-Application-Container" class="headerlink" title="创建 Application Container"></a>创建 Application Container</h3><ol><li>点击 <strong>Create CT</strong></li><li><strong>General</strong> 页：设置 CT ID、密码</li><li><strong>Template</strong> 页：选择已下载的 OCI 镜像</li><li><strong>Root Disk</strong>：设置磁盘大小</li><li><strong>CPU &#x2F; Memory</strong>：按需分配</li><li><strong>Network</strong>：<ul><li>桥接 <code>vmbr0</code></li><li>勾选 <strong>Host-Managed IP</strong>（让宿主管理 IP 配置，容器内不需要 DHCP 客户端）</li></ul></li><li>确认并 <strong>Finish</strong></li></ol><h3 id="CLI-创建"><a href="#CLI-创建" class="headerlink" title="CLI 创建"></a>CLI 创建</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 从 OCI 镜像直接创建容器</span></span><br><span class="line">pct create 200 <span class="built_in">local</span>:oci/nginx:latest \</span><br><span class="line">  --storage local-zfs \</span><br><span class="line">  --rootfs 4 \</span><br><span class="line">  --hostname nginx-app \</span><br><span class="line">  --net0 name=eth0,bridge=vmbr0,ip=dhcp,host-managed=1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动</span></span><br><span class="line">pct start 200</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看运行状态</span></span><br><span class="line">pct status 200</span><br><span class="line">pct enter 200</span><br></pre></td></tr></table></figure><h3 id="访问应用"><a href="#访问应用" class="headerlink" title="访问应用"></a>访问应用</h3><p>容器启动后，通过 <code>pct enter 200</code> 进入，或通过宿主 IP + 映射端口访问。</p><blockquote><p>由于 Application Container 是单进程容器，PVE 会自动使用 <code>host-managed</code> 网络模式，宿主负责 IP 配置。如需端口映射，可在容器内配置，或结合 PVE Firewall 规则。</p></blockquote><h3 id="PVE-9-2-Application-Container-改进"><a href="#PVE-9-2-Application-Container-改进" class="headerlink" title="PVE 9.2 Application Container 改进"></a>PVE 9.2 Application Container 改进</h3><table><thead><tr><th>改进点</th><th>说明</th></tr></thead><tbody><tr><td><strong>&#x2F;dev&#x2F;shm tmpfs</strong></td><td>自动挂载 tmpfs 到 &#x2F;dev&#x2F;shm，符合 OCI Runtime 规范</td></tr><tr><td><strong>OCI User 属性</strong></td><td>自动识别并应用 OCI 镜像中的 USER 指令</td></tr><tr><td><strong>idmap 挂载选项</strong></td><td>支持对单个挂载点自定义 UID&#x2F;GID 映射</td></tr><tr><td><strong>keepattrs 选项</strong></td><td>继承已有挂载点目录的属主和权限</td></tr></tbody></table><h3 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h3><ul><li>Application Container 是 <strong>技术预览</strong>，不建议用于关键生产环境</li><li>适合单进程应用，复杂多进程&#x2F;有 init 系统的镜像可能不兼容</li><li>Docker Compose 支持在路线图中，暂时不支持</li><li>部分需要特殊内核模块或设备直通的应用可能需要 Docker in VM</li></ul><hr><h2 id="方式二：Docker-in-LXC-容器"><a href="#方式二：Docker-in-LXC-容器" class="headerlink" title="方式二：Docker in LXC 容器"></a>方式二：Docker in LXC 容器</h2><p>在 LXC 容器内安装 Docker daemon，是 PVE 上部署 Docker 应用最常用的方式。PVE 9.2 新增的 <code>idmap</code> 和 <code>keepattrs</code> 挂载选项让权限管理更灵活。</p><h3 id="准备工作：创建-LXC-容器"><a href="#准备工作：创建-LXC-容器" class="headerlink" title="准备工作：创建 LXC 容器"></a>准备工作：创建 LXC 容器</h3><ol><li><strong>创建容器</strong>：使用 Ubuntu 24.04 或 Debian 12 模板</li><li><strong>关键配置</strong>：</li></ol><table><thead><tr><th>配置项</th><th>必须</th><th>说明</th></tr></thead><tbody><tr><td><strong>Unprivileged container</strong></td><td>否</td><td>默认即可，但 Docker 需特殊配置</td></tr><tr><td><strong>Nesting</strong></td><td><strong>是</strong></td><td>必须启用，容器的容器（Docker）需要</td></tr><tr><td><strong>特权容器</strong></td><td>推荐</td><td>非受信环境建议用 VM</td></tr></tbody></table><h3 id="在-WebUI-中配置"><a href="#在-WebUI-中配置" class="headerlink" title="在 WebUI 中配置"></a>在 WebUI 中配置</h3><p>创建 CT 时在 <strong>Options</strong> 标签页：</p><ul><li><strong>Unprivileged</strong> → 取消勾选（使用特权容器，Docker 兼容性更好）</li><li><strong>Nesting</strong> → 勾选</li></ul><p>或创建后用 CLI 修改：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">pct <span class="built_in">set</span> 100 -features nesting=1</span><br><span class="line">pct <span class="built_in">set</span> 100 -unprivileged 0</span><br><span class="line">pct reboot 100</span><br></pre></td></tr></table></figure><h3 id="安装-Docker"><a href="#安装-Docker" class="headerlink" title="安装 Docker"></a>安装 Docker</h3><p>进入容器，安装 Docker：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">pct enter 100</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装 Docker（Ubuntu）</span></span><br><span class="line">apt update</span><br><span class="line">apt install -y docker.io</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或使用官方脚本（Debian/Ubuntu）</span></span><br><span class="line">curl -fsSL https://get.docker.com | sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 验证</span></span><br><span class="line">docker --version</span><br><span class="line">docker run hello-world</span><br></pre></td></tr></table></figure><h3 id="PVE-9-2-新特性：idmap-挂载点"><a href="#PVE-9-2-新特性：idmap-挂载点" class="headerlink" title="PVE 9.2 新特性：idmap 挂载点"></a>PVE 9.2 新特性：idmap 挂载点</h3><p>PVE 9.2 新增 <code>idmap</code> 和 <code>keepattrs</code> 挂载选项，解决 Docker 卷挂载中的权限问题。</p><h4 id="场景：将宿主目录挂载到容器供-Docker-使用"><a href="#场景：将宿主目录挂载到容器供-Docker-使用" class="headerlink" title="场景：将宿主目录挂载到容器供 Docker 使用"></a>场景：将宿主目录挂载到容器供 Docker 使用</h4><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 PVE 宿主机上创建共享目录</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /mnt/bindmounts/docker-data</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加到容器（CLI）</span></span><br><span class="line">pct <span class="built_in">set</span> 100 -mp0 /mnt/bindmounts/docker-data,mp=/data,idmap=passthrough</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或者只映射特定 UID</span></span><br><span class="line">pct <span class="built_in">set</span> 100 -mp1 /mnt/bindmounts/docker-data,mp=/appdata,idmap=u:0:100000:65536;g:0:100000:65536</span><br></pre></td></tr></table></figure><p><code>idmap</code> 参数详解：</p><table><thead><tr><th>值</th><th>效果</th></tr></thead><tbody><tr><td><code>passthrough</code></td><td>直接穿透，容器内 ID &#x3D; 宿主 ID</td></tr><tr><td><code>u:容器UID:宿主UID:数量;g:容器GID:宿主GID:数量</code></td><td>自定义映射范围</td></tr><tr><td><code>u:0:100000:65536</code></td><td>将容器内 UID 0-65535 映射到宿主 UID 100000-165535</td></tr></tbody></table><h4 id="keepattrs-选项"><a href="#keepattrs-选项" class="headerlink" title="keepattrs 选项"></a>keepattrs 选项</h4><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 继承已有目录的属主和权限（而非被容器用户覆盖）</span></span><br><span class="line">pct <span class="built_in">set</span> 100 -mp2 /mnt/bindmounts/data,mp=/persistent,keepattrs=1</span><br></pre></td></tr></table></figure><h3 id="Docker-Compose-示例"><a href="#Docker-Compose-示例" class="headerlink" title="Docker Compose 示例"></a>Docker Compose 示例</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">pct enter 100</span><br><span class="line"></span><br><span class="line">apt install -y docker-compose-plugin</span><br><span class="line"></span><br><span class="line"><span class="built_in">mkdir</span> -p /opt/stack &amp;&amp; <span class="built_in">cd</span> /opt/stack</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建 compose.yml</span></span><br><span class="line"><span class="built_in">cat</span> &gt; compose.yml &lt;&lt; <span class="string">&#x27;EOF&#x27;</span></span><br><span class="line">services:</span><br><span class="line">  nginx:</span><br><span class="line">    image: nginx:alpine</span><br><span class="line">    ports:</span><br><span class="line">      - <span class="string">&quot;80:80&quot;</span></span><br><span class="line">    volumes:</span><br><span class="line">      - ./html:/usr/share/nginx/html</span><br><span class="line"></span><br><span class="line">  redis:</span><br><span class="line">    image: redis:7-alpine</span><br><span class="line"></span><br><span class="line">  app:</span><br><span class="line">    image: your-app:latest</span><br><span class="line">    depends_on:</span><br><span class="line">      - redis</span><br><span class="line">EOF</span><br><span class="line"></span><br><span class="line">docker compose up -d</span><br></pre></td></tr></table></figure><h3 id="性能优化"><a href="#性能优化" class="headerlink" title="性能优化"></a>性能优化</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 使用 overlay2 存储驱动（默认）</span></span><br><span class="line">docker info | grep Storage</span><br><span class="line"></span><br><span class="line"><span class="comment"># 限制 Docker 日志大小</span></span><br><span class="line"><span class="built_in">cat</span> &gt; /etc/docker/daemon.json &lt;&lt; <span class="string">&#x27;EOF&#x27;</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;log-driver&quot;</span>: <span class="string">&quot;json-file&quot;</span>,</span><br><span class="line">  <span class="string">&quot;log-opts&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;max-size&quot;</span>: <span class="string">&quot;10m&quot;</span>,</span><br><span class="line">    <span class="string">&quot;max-file&quot;</span>: <span class="string">&quot;3&quot;</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">EOF</span><br><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure><h3 id="安全性建议"><a href="#安全性建议" class="headerlink" title="安全性建议"></a>安全性建议</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 限制容器资源（PVE 层面）</span></span><br><span class="line">pct <span class="built_in">set</span> 100 -memory 2048 -swap 512 -cores 2</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 使用非 root 运行 Docker</span></span><br><span class="line">groupadd docker</span><br><span class="line">usermod -aG docker your-user</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3. 启用 Docker 内容信任</span></span><br><span class="line"><span class="built_in">export</span> DOCKER_CONTENT_TRUST=1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4. 定期更新</span></span><br><span class="line">pct enter 100 -- apt update &amp;&amp; apt upgrade -y</span><br></pre></td></tr></table></figure><hr><h2 id="方式三：Docker-in-VM-虚拟机"><a href="#方式三：Docker-in-VM-虚拟机" class="headerlink" title="方式三：Docker in VM 虚拟机"></a>方式三：Docker in VM 虚拟机</h2><p>在完整的虚拟机中安装 Docker，获得最高级别的隔离性。适合多租户、不信任的工作负载、需要 Live Migration 的场景。</p><h3 id="创建-VM"><a href="#创建-VM" class="headerlink" title="创建 VM"></a>创建 VM</h3><ol><li><strong>Create VM</strong> → 选择 Ubuntu Server &#x2F; Debian ISO</li><li><strong>System</strong>：BIOS → <code>OVMF (UEFI)</code>，勾选 <strong>Qemu Agent</strong></li><li><strong>Disks</strong>：<code>VirtIO Block</code>，建议 20 GB+</li><li><strong>CPU</strong>：Type → <code>host</code></li><li><strong>Network</strong>：<code>VirtIO (paravirtualized)</code></li></ol><h3 id="安装-Docker-1"><a href="#安装-Docker-1" class="headerlink" title="安装 Docker"></a>安装 Docker</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 进入 VM 控制台</span></span><br><span class="line"><span class="comment"># 安装 Docker</span></span><br><span class="line">curl -fsSL https://get.docker.com | sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装 Compose 插件</span></span><br><span class="line">apt install -y docker-compose-plugin</span><br><span class="line"></span><br><span class="line"><span class="comment"># 验证</span></span><br><span class="line">docker run hello-world</span><br></pre></td></tr></table></figure><h3 id="Docker-Compose-部署完整栈"><a href="#Docker-Compose-部署完整栈" class="headerlink" title="Docker Compose 部署完整栈"></a>Docker Compose 部署完整栈</h3><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="comment"># /opt/project/compose.yml</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">traefik:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">traefik:v3.1</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">traefik</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;80:80&quot;</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;443:443&quot;</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">/var/run/docker.sock:/var/run/docker.sock:ro</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">./traefik.yml:/traefik.yml:ro</span></span><br><span class="line">    <span class="attr">labels:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;traefik.enable=true&quot;</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">portainer:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">portainer/portainer-ce:latest</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">portainer</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;9000:9000&quot;</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">/var/run/docker.sock:/var/run/docker.sock:ro</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">portainer_data:/data</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">watchtower:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">containrrr/watchtower</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">watchtower</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">/var/run/docker.sock:/var/run/docker.sock:ro</span></span><br><span class="line"></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">portainer_data:</span></span><br></pre></td></tr></table></figure><h3 id="VM-专用优化"><a href="#VM-专用优化" class="headerlink" title="VM 专用优化"></a>VM 专用优化</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 安装 QEMU Guest Agent（WebUI 可见 IP、内存等）</span></span><br><span class="line">apt install -y qemu-guest-agent</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 开启 BBPR（Better Business Performance Reporting）</span></span><br><span class="line"><span class="comment"># CPU Type 选 host 即可获得最大性能</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 3. 磁盘使用 VirtIO + iothread</span></span><br><span class="line"><span class="comment"># WebUI → Hardware → 磁盘 → 启用 IO Thread</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 4. VirtIO SCSI single 控制器（性能最佳）</span></span><br><span class="line"><span class="comment"># WebUI → Hardware → 添加 SCSI 控制器 → VirtIO SCSI single</span></span><br></pre></td></tr></table></figure><hr><h2 id="场景选择指南"><a href="#场景选择指南" class="headerlink" title="场景选择指南"></a>场景选择指南</h2><h3 id="选-Application-Container（OCI）"><a href="#选-Application-Container（OCI）" class="headerlink" title="选 Application Container（OCI）"></a>选 Application Container（OCI）</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">你只需要跑一个 Nginx/Redis/PostgreSQL 单服务</span><br><span class="line">→ 不想装 Docker</span><br><span class="line">→ 想用 PVE WebUI 统一管理</span><br><span class="line">→ 愿意接受技术预览的稳定性</span><br><span class="line">→ 选 OCI Application Container</span><br></pre></td></tr></table></figure><h3 id="选-Docker-in-LXC"><a href="#选-Docker-in-LXC" class="headerlink" title="选 Docker in LXC"></a>选 Docker in LXC</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">你需要 Docker Compose 编排多个服务</span><br><span class="line">→ 需要极低开销</span><br><span class="line">→ 不需要 Live Migration</span><br><span class="line">→ 服务在可信环境运行</span><br><span class="line">→ 选 Docker in LXC</span><br></pre></td></tr></table></figure><h3 id="选-Docker-in-VM"><a href="#选-Docker-in-VM" class="headerlink" title="选 Docker in VM"></a>选 Docker in VM</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">多租户 / 不信任的工作负载</span><br><span class="line">→ 需要 Live Migration / 高可用</span><br><span class="line">→ 需要完整内核隔离</span><br><span class="line">→ 需要运行特殊内核模块</span><br><span class="line">→ 生产环境核心服务</span><br><span class="line">→ 选 Docker in VM</span><br></pre></td></tr></table></figure><h3 id="混合使用"><a href="#混合使用" class="headerlink" title="混合使用"></a>混合使用</h3><p>实际部署中，三种方式可以混合使用：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">PVE Host</span><br><span class="line">├── OCI App Container: Nginx (反向代理)</span><br><span class="line">├── LXC + Docker:      Compose 应用栈 (WordPress + MySQL)</span><br><span class="line">├── VM + Docker:       核心业务 + Portainer 管理</span><br><span class="line">└── LXC + Docker:      开发/测试环境</span><br></pre></td></tr></table></figure><p>所有容器&#x2F;虚拟机统一通过 PVE WebUI 管理备份、快照、监控。</p><hr><h2 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h2><h3 id="Q1：Application-Container-拉取镜像失败？"><a href="#Q1：Application-Container-拉取镜像失败？" class="headerlink" title="Q1：Application Container 拉取镜像失败？"></a>Q1：Application Container 拉取镜像失败？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 检查 OCI 注册表地址是否正确</span></span><br><span class="line"><span class="comment"># 公开镜像无需认证，私有镜像需先 docker login 导出认证</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 默认拉取 docker.io 官方库，其他仓库需写全路径</span></span><br><span class="line">pct oci pull ghcr.io/owner/image:tag</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查存储空间</span></span><br><span class="line"><span class="built_in">df</span> -h</span><br></pre></td></tr></table></figure><h3 id="Q2：LXC-内-Docker-报-“failed-to-create-cgroup”？"><a href="#Q2：LXC-内-Docker-报-“failed-to-create-cgroup”？" class="headerlink" title="Q2：LXC 内 Docker 报 “failed to create cgroup”？"></a>Q2：LXC 内 Docker 报 “failed to create cgroup”？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 方案一：确保启用了 nesting</span></span><br><span class="line">pct <span class="built_in">set</span> CTID -features nesting=1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 方案二：在 LXC 配置中追加</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;lxc.cgroup2.memory.max: 1073741824&quot;</span> &gt;&gt; /etc/pve/lxc/CTID.conf</span><br><span class="line">pct reboot CTID</span><br></pre></td></tr></table></figure><h3 id="Q3：Docker-in-LXC-磁盘权限问题？"><a href="#Q3：Docker-in-LXC-磁盘权限问题？" class="headerlink" title="Q3：Docker in LXC 磁盘权限问题？"></a>Q3：Docker in LXC 磁盘权限问题？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 使用 PVE 9.2 的 idmap 功能</span></span><br><span class="line">pct <span class="built_in">set</span> CTID -mp0 /mnt/bindmounts/data,mp=/data,idmap=passthrough</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或者在 Docker Compose 中指定用户</span></span><br><span class="line">services:</span><br><span class="line">  app:</span><br><span class="line">    user: <span class="string">&quot;1000:1000&quot;</span></span><br><span class="line">    volumes:</span><br><span class="line">      - ./data:/data</span><br></pre></td></tr></table></figure><h3 id="Q4：OCI-App-Container-和-Docker-in-LXC-性能对比？"><a href="#Q4：OCI-App-Container-和-Docker-in-LXC-性能对比？" class="headerlink" title="Q4：OCI App Container 和 Docker in LXC 性能对比？"></a>Q4：OCI App Container 和 Docker in LXC 性能对比？</h3><p>OCI App Container 略优（无 Docker daemon 开销），但实际差异通常 &lt; 5%。选择时优先考虑功能和隔离需求，而非性能。</p><h3 id="Q5：Application-Container-的-Compose-支持何时可用？"><a href="#Q5：Application-Container-的-Compose-支持何时可用？" class="headerlink" title="Q5：Application Container 的 Compose 支持何时可用？"></a>Q5：Application Container 的 Compose 支持何时可用？</h3><p>PVE 路线图显示 Compose Specification 支持正在开发中（技术预览阶段），会在后续版本逐步推出。当前可用 <code>pct</code> 命令结合 Shell 脚本编排多容器。</p><h3 id="Q6：Docker-in-VM-性能损耗大吗？"><a href="#Q6：Docker-in-VM-性能损耗大吗？" class="headerlink" title="Q6：Docker in VM 性能损耗大吗？"></a>Q6：Docker in VM 性能损耗大吗？</h3><p>使用 VirtIO 设备 + CPU host 模式 + IO Thread，性能损耗通常在 5-10% 以内。适合绝大多数生产场景。</p><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>Proxmox VE 9.2 提供了三种运行容器化应用的方式，覆盖从轻量到全隔离的全场景：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">OCI App Container</span><br><span class="line">├── 无需 Docker</span><br><span class="line">├── PVE WebUI 原生管理</span><br><span class="line">├── 技术预览</span><br><span class="line">└── 适合单服务</span><br><span class="line"></span><br><span class="line">Docker in LXC</span><br><span class="line">├── 需 Docker daemon</span><br><span class="line">├── PVE 9.2 idmap/keepattrs</span><br><span class="line">├── 成熟稳定</span><br><span class="line">└── 适合 Compose 栈</span><br><span class="line"></span><br><span class="line">Docker in VM</span><br><span class="line">├── 完全隔离</span><br><span class="line">├── Live Migration 支持</span><br><span class="line">├── 最成熟</span><br><span class="line">└── 适合生产关键业务</span><br></pre></td></tr></table></figure><p>对于探索新功能的用户，OCI Application Container 值得一试——它代表了 PVE 容器化管理的未来方向。对于生产环境，Docker in VM 仍然是最稳妥的选择。</p><hr><p><em>本文最后更新于 2026 年 6 月，对应 Proxmox VE 9.2-1。Application Container 为技术预览功能。</em></p>]]>
    </content>
    <id>https://sam.xx.kg/post/PVE9-2%E8%BF%90%E8%A1%8CDocker%E7%9A%84%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F/</id>
    <link href="https://sam.xx.kg/post/PVE9-2%E8%BF%90%E8%A1%8CDocker%E7%9A%84%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F/"/>
    <published>2026-06-30T10:30:00.000Z</published>
    <summary>详解在 Proxmox VE 9.2 中运行容器的三种方式：原生 OCI Application Container（新功能）、Docker in LXC、Docker in VM，涵盖配置步骤与场景选择。</summary>
    <title>PVE 9.2 运行 Docker 的三种方式 — 从原生 OCI 到虚拟机</title>
    <updated>2026-06-30T11:01:03.499Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="代理与网络" scheme="https://sam.xx.kg/categories/%E4%BB%A3%E7%90%86%E4%B8%8E%E7%BD%91%E7%BB%9C/"/>
    <category term="WireGuard" scheme="https://sam.xx.kg/tags/WireGuard/"/>
    <category term="VPN" scheme="https://sam.xx.kg/tags/VPN/"/>
    <category term="内网穿透" scheme="https://sam.xx.kg/tags/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/"/>
    <category term="组网" scheme="https://sam.xx.kg/tags/%E7%BB%84%E7%BD%91/"/>
    <category term="网络安全" scheme="https://sam.xx.kg/tags/%E7%BD%91%E7%BB%9C%E5%AE%89%E5%85%A8/"/>
    <content>
      <![CDATA[<blockquote><p><strong>WireGuard</strong> 是目前最先进的 VPN 协议之一，内核级实现，代码量不到 4000 行，配置简单、性能极高。本文从零开始，覆盖点对点、Hub-and-Spoke、Site-to-Site 三种组网模式，实现多台服务器&#x2F;家庭网络的内网互联。</p></blockquote><hr><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li><a href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E9%80%89%E6%8B%A9-wireguard">为什么选择 WireGuard</a></li><li><a href="#%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86">工作原理</a></li><li><a href="#%E5%AE%89%E8%A3%85-wireguard">安装 WireGuard</a></li><li><a href="#%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE%E7%82%B9%E5%AF%B9%E7%82%B9%E8%BF%9E%E6%8E%A5">基础配置：点对点连接</a></li><li><a href="#hub-and-spoke-%E6%98%9F%E5%9E%8B%E7%BB%84%E7%BD%91">Hub-and-Spoke 星型组网</a></li><li><a href="#site-to-site-%E7%AB%99%E7%82%B9%E5%88%B0%E7%AB%99%E7%82%B9%E7%BB%84%E7%BD%91">Site-to-Site 站点到站点组网</a></li><li><a href="#%E8%B7%AF%E7%94%B1%E8%BD%AC%E5%8F%91%E4%B8%8E-nat">路由转发与 NAT</a></li><li><a href="#%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98">性能调优</a></li><li><a href="#%E5%AE%89%E5%85%A8%E5%8A%A0%E5%9B%BA">安全加固</a></li><li><a href="#pve-92-sdn--wireguard-%E9%9B%86%E6%88%90">PVE 9.2 SDN + WireGuard 集成</a></li><li><a href="#%E5%B8%B8%E7%94%A8%E7%AE%A1%E7%90%86%E5%91%BD%E4%BB%A4">常用管理命令</a></li><li><a href="#%E6%8E%92%E9%94%99%E6%8C%87%E5%8D%97">排错指南</a></li></ul><hr><h2 id="为什么选择-WireGuard"><a href="#为什么选择-WireGuard" class="headerlink" title="为什么选择 WireGuard"></a>为什么选择 WireGuard</h2><table><thead><tr><th>特性</th><th>WireGuard</th><th>OpenVPN</th><th>IPsec</th></tr></thead><tbody><tr><td><strong>代码量</strong></td><td>~4000 行</td><td>~60万行</td><td>极复杂</td></tr><tr><td><strong>延迟</strong></td><td>极低（内核态）</td><td>较高（用户态）</td><td>中等</td></tr><tr><td><strong>配置</strong></td><td>1 个文件，几分钟</td><td>证书链复杂</td><td>繁琐</td></tr><tr><td><strong>加密</strong></td><td>Curve25519 + ChaCha20 + Poly1305</td><td>OpenSSL</td><td>多种可选</td></tr><tr><td><strong>漫游</strong></td><td>原生支持</td><td>需额外配置</td><td>有限</td></tr><tr><td><strong>内核集成</strong></td><td>Linux 5.6+ 内置</td><td>否</td><td>部分</td></tr></tbody></table><p>WireGuard 的核心优势：</p><ul><li><strong>内核级</strong>：直接在 Linux 内核中运行，性能远超用户态 VPN</li><li><strong>无连接</strong>：无传统握手协议，对端离线不影响本端配置</li><li><strong>加密默认</strong>：完美前向保密，所有流量默认加密</li><li><strong>漫游友好</strong>：对端 IP 变化自动重连</li></ul><hr><h2 id="工作原理"><a href="#工作原理" class="headerlink" title="工作原理"></a>工作原理</h2><p>WireGuard 通过 <strong>UDP</strong> 传输加密数据包。每个节点有一个私钥和公钥，通信前通过公钥认证 + 加密。</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">[节点 A: 10.0.0.1/24] ←--- UDP 加密隧道 ---→ [节点 B: 10.0.0.2/24]</span><br><span class="line">      私钥: aAA...                 私钥: bBB...</span><br><span class="line">      公钥: aPUB...                公钥: bPUB...</span><br></pre></td></tr></table></figure><p>术语解释：</p><table><thead><tr><th>术语</th><th>说明</th></tr></thead><tbody><tr><td><strong>Interface</strong></td><td>本地 WireGuard 网卡配置（IP、端口、私钥）</td></tr><tr><td><strong>Peer</strong></td><td>对端节点配置（公钥、允许 IP、端点地址）</td></tr><tr><td><strong>AllowedIPs</strong></td><td>哪些目标 IP 走 WireGuard 隧道</td></tr><tr><td><strong>Endpoint</strong></td><td>对端的公网 IP:端口</td></tr><tr><td><strong>PersistentKeepalive</strong></td><td>保活间隔（NAT 场景必备）</td></tr></tbody></table><hr><h2 id="安装-WireGuard"><a href="#安装-WireGuard" class="headerlink" title="安装 WireGuard"></a>安装 WireGuard</h2><h3 id="Linux（Debian-Ubuntu）"><a href="#Linux（Debian-Ubuntu）" class="headerlink" title="Linux（Debian &#x2F; Ubuntu）"></a>Linux（Debian &#x2F; Ubuntu）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># WireGuard 已内置于 Linux 5.6+ 内核</span></span><br><span class="line"><span class="comment"># 只需安装用户态工具</span></span><br><span class="line">apt update</span><br><span class="line">apt install -y wireguard</span><br><span class="line"></span><br><span class="line"><span class="comment"># 确认安装</span></span><br><span class="line">wg --version</span><br></pre></td></tr></table></figure><h3 id="Linux（CentOS-Rocky-Linux）"><a href="#Linux（CentOS-Rocky-Linux）" class="headerlink" title="Linux（CentOS &#x2F; Rocky Linux）"></a>Linux（CentOS &#x2F; Rocky Linux）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">dnf install -y epel-release</span><br><span class="line">dnf install -y wireguard-tools</span><br></pre></td></tr></table></figure><h3 id="macOS"><a href="#macOS" class="headerlink" title="macOS"></a>macOS</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">brew install wireguard-tools</span><br></pre></td></tr></table></figure><h3 id="Windows"><a href="#Windows" class="headerlink" title="Windows"></a>Windows</h3><p>下载 <a href="https://www.wireguard.com/install/">WireGuard Windows 客户端</a> 安装即可。</p><hr><h2 id="基础配置：点对点连接"><a href="#基础配置：点对点连接" class="headerlink" title="基础配置：点对点连接"></a>基础配置：点对点连接</h2><p>这是最简单的模式，两台服务器直接互联。</p><h3 id="生成密钥对"><a href="#生成密钥对" class="headerlink" title="生成密钥对"></a>生成密钥对</h3><p>在 <strong>两台机器上分别执行</strong>：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 生成私钥</span></span><br><span class="line">wg genkey | <span class="built_in">tee</span> privatekey</span><br><span class="line"></span><br><span class="line"><span class="comment"># 从私钥导出公钥</span></span><br><span class="line"><span class="built_in">cat</span> privatekey | wg pubkey | <span class="built_in">tee</span> publickey</span><br></pre></td></tr></table></figure><h3 id="节点-A-配置（服务器-A，公网-IP-1-2-3-4）"><a href="#节点-A-配置（服务器-A，公网-IP-1-2-3-4）" class="headerlink" title="节点 A 配置（服务器 A，公网 IP: 1.2.3.4）"></a>节点 A 配置（服务器 A，公网 IP: 1.2.3.4）</h3><p>创建 <code>/etc/wireguard/wg0.conf</code>：</p><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.1</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">ListenPort</span> = <span class="number">51820</span></span><br><span class="line"><span class="attr">PrivateKey</span> = aAA...（节点 A 的私钥）</span><br><span class="line"></span><br><span class="line"><span class="comment"># 可选 MTU 优化</span></span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = bPUB...（节点 B 的公钥）</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">32</span></span><br><span class="line"><span class="attr">Endpoint</span> = <span class="number">5.6</span>.<span class="number">7.8</span>:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><h3 id="节点-B-配置（服务器-B，公网-IP-5-6-7-8）"><a href="#节点-B-配置（服务器-B，公网-IP-5-6-7-8）" class="headerlink" title="节点 B 配置（服务器 B，公网 IP: 5.6.7.8）"></a>节点 B 配置（服务器 B，公网 IP: 5.6.7.8）</h3><p>创建 <code>/etc/wireguard/wg0.conf</code>：</p><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">ListenPort</span> = <span class="number">51820</span></span><br><span class="line"><span class="attr">PrivateKey</span> = bBB...（节点 B 的私钥）</span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = aPUB...（节点 A 的公钥）</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.1</span>/<span class="number">32</span></span><br><span class="line"><span class="attr">Endpoint</span> = <span class="number">1.2</span>.<span class="number">3.4</span>:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><h3 id="启动-WireGuard"><a href="#启动-WireGuard" class="headerlink" title="启动 WireGuard"></a>启动 WireGuard</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 启动接口</span></span><br><span class="line">wg-quick up wg0</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看状态</span></span><br><span class="line">wg show</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置开机自启</span></span><br><span class="line">systemctl <span class="built_in">enable</span> wg-quick@wg0</span><br></pre></td></tr></table></figure><h3 id="测试连通性"><a href="#测试连通性" class="headerlink" title="测试连通性"></a>测试连通性</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ping 10.0.0.2   <span class="comment"># 在节点 A 上</span></span><br><span class="line">ping 10.0.0.1   <span class="comment"># 在节点 B 上</span></span><br></pre></td></tr></table></figure><p>如果 ping 通，点对点连接建立成功。</p><hr><h2 id="Hub-and-Spoke-星型组网"><a href="#Hub-and-Spoke-星型组网" class="headerlink" title="Hub-and-Spoke 星型组网"></a>Hub-and-Spoke 星型组网</h2><p>用一台公网服务器作为 Hub，多台内网&#x2F;客户端机器通过它互联。这是最常用的模式，适合多 VPS + 家庭内网组网。</p><h3 id="拓扑"><a href="#拓扑" class="headerlink" title="拓扑"></a>拓扑</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">               [Hub 服务器]</span><br><span class="line">              公网 IP: 1.2.3.4</span><br><span class="line">              虚拟 IP: 10.0.0.1/24</span><br><span class="line">              ┌─────────────┐</span><br><span class="line">              │  10.0.0.1   │</span><br><span class="line">              └──────┬──────┘</span><br><span class="line">         ┌───────────┼───────────┐</span><br><span class="line">         │           │           │</span><br><span class="line">[VPS 香港]    [家庭 NAS]     [手机/笔记本]</span><br><span class="line">10.0.0.2      10.0.0.3      10.0.0.100</span><br></pre></td></tr></table></figure><h3 id="Hub-配置"><a href="#Hub-配置" class="headerlink" title="Hub 配置"></a>Hub 配置</h3><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.1</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">ListenPort</span> = <span class="number">51820</span></span><br><span class="line"><span class="attr">PrivateKey</span> = hub私钥</span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 开启 IP 转发（重要）</span></span><br><span class="line"><span class="comment"># 同时需要在 sysctl 中设置 net.ipv4.ip_forward = 1</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="comment"># VPS 香港</span></span><br><span class="line"><span class="attr">PublicKey</span> = hk公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">32</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="comment"># 家庭 NAS</span></span><br><span class="line"><span class="attr">PublicKey</span> = nas公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.3</span>/<span class="number">32</span>, <span class="number">192.168</span>.<span class="number">1.0</span>/<span class="number">24</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="comment"># 手机/笔记本</span></span><br><span class="line"><span class="attr">PublicKey</span> = mobile公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.100</span>/<span class="number">32</span></span><br></pre></td></tr></table></figure><blockquote><p>Hub 的 <code>AllowedIPs</code> 填写每个 Spoke 的虚拟 IP。如果 Spoke 后面还有局域网，一并加上（如 <code>192.168.1.0/24</code>）。</p></blockquote><h3 id="Spoke-配置（以-VPS-香港为例）"><a href="#Spoke-配置（以-VPS-香港为例）" class="headerlink" title="Spoke 配置（以 VPS 香港为例）"></a>Spoke 配置（以 VPS 香港为例）</h3><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">PrivateKey</span> = hk私钥</span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = hub公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.0</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">Endpoint</span> = <span class="number">1.2</span>.<span class="number">3.4</span>:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><h3 id="开启-IP-转发（所有节点）"><a href="#开启-IP-转发（所有节点）" class="headerlink" title="开启 IP 转发（所有节点）"></a>开启 IP 转发（所有节点）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&quot;net.ipv4.ip_forward = 1&quot;</span> &gt;&gt; /etc/sysctl.conf</span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;net.ipv6.conf.all.forwarding = 1&quot;</span> &gt;&gt; /etc/sysctl.conf</span><br><span class="line">sysctl -p</span><br></pre></td></tr></table></figure><h3 id="Spoke-互通"><a href="#Spoke-互通" class="headerlink" title="Spoke 互通"></a>Spoke 互通</h3><p>通过 Hub 转发，香港 VPS 可以直接访问家庭 NAS 的内网 IP：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 VPS 香港上</span></span><br><span class="line">ping 10.0.0.3       <span class="comment"># 访问家庭 NAS</span></span><br><span class="line">ping 192.168.1.100   <span class="comment"># 访问 NAS 后的局域网设备（如果配置了路由）</span></span><br></pre></td></tr></table></figure><hr><h2 id="Site-to-Site-站点到站点组网"><a href="#Site-to-Site-站点到站点组网" class="headerlink" title="Site-to-Site 站点到站点组网"></a>Site-to-Site 站点到站点组网</h2><p>将两个局域网通过 WireGuard 打通，实现异地局域网互联。</p><h3 id="拓扑-1"><a href="#拓扑-1" class="headerlink" title="拓扑"></a>拓扑</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">[Site A: 上海]                    [Site B: 香港]</span><br><span class="line">┌──────────────┐                ┌──────────────┐</span><br><span class="line">│ PC-A:        │                │ PC-B:         │</span><br><span class="line">│ 192.168.1.10 │                │ 192.168.2.20  │</span><br><span class="line">│              │   WireGuard    │              │</span><br><span class="line">│ Router-A     │◄─────────────►│ Router-B      │</span><br><span class="line">│ 192.168.1.1  │   10.0.0.1     │ 192.168.2.1   │</span><br><span class="line">│ WG: 10.0.0.1 │     ←→        │ WG: 10.0.0.2  │</span><br><span class="line">└──────────────┘                └──────────────┘</span><br></pre></td></tr></table></figure><h3 id="Site-A-配置"><a href="#Site-A-配置" class="headerlink" title="Site A 配置"></a>Site A 配置</h3><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.1</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">ListenPort</span> = <span class="number">51820</span></span><br><span class="line"><span class="attr">PrivateKey</span> = siteA私钥</span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"><span class="attr">PostUp</span> = iptables -A FORWARD -i wg0 -j ACCEPT<span class="comment">; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE</span></span><br><span class="line"><span class="attr">PostDown</span> = iptables -D FORWARD -i wg0 -j ACCEPT<span class="comment">; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = siteB公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">32</span>, <span class="number">192.168</span>.<span class="number">2.0</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">Endpoint</span> = siteB公网IP:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><h3 id="Site-B-配置"><a href="#Site-B-配置" class="headerlink" title="Site B 配置"></a>Site B 配置</h3><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.2</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">ListenPort</span> = <span class="number">51820</span></span><br><span class="line"><span class="attr">PrivateKey</span> = siteB私钥</span><br><span class="line"><span class="attr">MTU</span> = <span class="number">1420</span></span><br><span class="line"><span class="attr">PostUp</span> = iptables -A FORWARD -i wg0 -j ACCEPT<span class="comment">; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE</span></span><br><span class="line"><span class="attr">PostDown</span> = iptables -D FORWARD -i wg0 -j ACCEPT<span class="comment">; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE</span></span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = siteA公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">10.0</span>.<span class="number">0.1</span>/<span class="number">32</span>, <span class="number">192.168</span>.<span class="number">1.0</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">Endpoint</span> = siteA公网IP:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><h3 id="路由表同步"><a href="#路由表同步" class="headerlink" title="路由表同步"></a>路由表同步</h3><p>在 <strong>Site A 的局域网设备</strong> 上，添加去往 Site B 的路由：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 PC-A 上</span></span><br><span class="line">ip route add 192.168.2.0/24 via 192.168.1.1</span><br></pre></td></tr></table></figure><p>或在路由器上添加静态路由，指向运行 WireGuard 的网关。</p><h3 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 Site A 的 PC-A 上</span></span><br><span class="line">ping 192.168.2.20     <span class="comment"># 直通 Site B 的内网设备</span></span><br></pre></td></tr></table></figure><hr><h2 id="路由转发与-NAT"><a href="#路由转发与-NAT" class="headerlink" title="路由转发与 NAT"></a>路由转发与 NAT</h2><h3 id="AllowedIPs-详解"><a href="#AllowedIPs-详解" class="headerlink" title="AllowedIPs 详解"></a>AllowedIPs 详解</h3><p><code>AllowedIPs</code> 既是对端的路由规则，也是防火墙规则：</p><table><thead><tr><th>写法</th><th>含义</th></tr></thead><tbody><tr><td><code>10.0.0.2/32</code></td><td>仅允许对端 WireGuard IP</td></tr><tr><td><code>10.0.0.0/24</code></td><td>整个 WireGuard 子网走隧道</td></tr><tr><td><code>10.0.0.2/32, 192.168.1.0/24</code></td><td>对端 IP + 对端局域网</td></tr><tr><td><code>0.0.0.0/0</code></td><td>全流量走隧道（VPN 模式）</td></tr></tbody></table><h3 id="全流量-VPN-模式（远程办公）"><a href="#全流量-VPN-模式（远程办公）" class="headerlink" title="全流量 VPN 模式（远程办公）"></a>全流量 VPN 模式（远程办公）</h3><figure class="highlight ini"><table><tr><td class="code"><pre><span class="line"><span class="section">[Interface]</span></span><br><span class="line"><span class="attr">Address</span> = <span class="number">10.0</span>.<span class="number">0.100</span>/<span class="number">24</span></span><br><span class="line"><span class="attr">DNS</span> = <span class="number">10.0</span>.<span class="number">0.1</span></span><br><span class="line"><span class="attr">PrivateKey</span> = 客户端私钥</span><br><span class="line"></span><br><span class="line"><span class="section">[Peer]</span></span><br><span class="line"><span class="attr">PublicKey</span> = 服务器公钥</span><br><span class="line"><span class="attr">AllowedIPs</span> = <span class="number">0.0</span>.<span class="number">0.0</span>/<span class="number">0</span>      <span class="comment"># 所有流量走隧道路由</span></span><br><span class="line"><span class="attr">Endpoint</span> = 服务器IP:<span class="number">51820</span></span><br><span class="line"><span class="attr">PersistentKeepalive</span> = <span class="number">25</span></span><br></pre></td></tr></table></figure><p>结合 <code>PostUp</code> 添加 NAT 规则，让客户端流量通过服务器上网。</p><h3 id="Docker-环境下的配置"><a href="#Docker-环境下的配置" class="headerlink" title="Docker 环境下的配置"></a>Docker 环境下的配置</h3><p>Docker 默认创建的 <code>iptables</code> 规则可能干扰 WireGuard。解决方案：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 wg0.conf 中添加 PostUp 规则</span></span><br><span class="line">PostUp = iptables -I FORWARD -i wg0 -j ACCEPT</span><br><span class="line">PostUp = iptables -I FORWARD -o wg0 -j ACCEPT</span><br><span class="line">PostUp = iptables -t nat -I POSTROUTING -o wg0 -j MASQUERADE</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或者让 WireGuard 容器使用 host 网络模式</span></span><br></pre></td></tr></table></figure><p>或者使用 <code>wg-quick</code> 的 <code>Table = auto</code> 功能自动管理路由表。</p><hr><h2 id="性能调优"><a href="#性能调优" class="headerlink" title="性能调优"></a>性能调优</h2><h3 id="MTU-优化"><a href="#MTU-优化" class="headerlink" title="MTU 优化"></a>MTU 优化</h3><p>WireGuard 默认 MTU 为 1420，可根据链路调整：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 测试不同 MTU（在两端执行）</span></span><br><span class="line">ping -M <span class="keyword">do</span> -s 1472 -c 5 10.0.0.2   <span class="comment"># 有线网络</span></span><br><span class="line">ping -M <span class="keyword">do</span> -s 1412 -c 5 10.0.0.2   <span class="comment"># PPPoE</span></span><br><span class="line">ping -M <span class="keyword">do</span> -s 1372 -c 5 10.0.0.2   <span class="comment"># 蜂窝网络</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 在 [Interface] 中设置</span></span><br><span class="line">MTU = 1420</span><br></pre></td></tr></table></figure><table><thead><tr><th>网络类型</th><th>推荐 MTU</th></tr></thead><tbody><tr><td>以太网（无额外封装）</td><td>1420</td></tr><tr><td>PPPoE（ADSL 拨号）</td><td>1412</td></tr><tr><td>4G &#x2F; 5G 蜂窝</td><td>1372</td></tr><tr><td>叠加 IPsec</td><td>1280</td></tr></tbody></table><h3 id="多队列"><a href="#多队列" class="headerlink" title="多队列"></a>多队列</h3><p>多核 CPU 启用多队列：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ethtool -L eth0 combined 4     <span class="comment"># 物理网卡多队列</span></span><br><span class="line"><span class="comment"># WireGuard 自动利用多队列（内核态优势）</span></span><br></pre></td></tr></table></figure><h3 id="内核参数优化"><a href="#内核参数优化" class="headerlink" title="内核参数优化"></a>内核参数优化</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># /etc/sysctl.d/99-wireguard.conf</span></span><br><span class="line">net.core.rmem_default = 262144</span><br><span class="line">net.core.wmem_default = 262144</span><br><span class="line">net.core.rmem_max = 4194304</span><br><span class="line">net.core.wmem_max = 4194304</span><br><span class="line">net.ipv4.conf.all.rp_filter = 0</span><br><span class="line">net.ipv4.conf.default.rp_filter = 0</span><br><span class="line">net.ipv4.tcp_congestion_control = bbr</span><br></pre></td></tr></table></figure><hr><h2 id="安全加固"><a href="#安全加固" class="headerlink" title="安全加固"></a>安全加固</h2><h3 id="1-防火墙规则"><a href="#1-防火墙规则" class="headerlink" title="1. 防火墙规则"></a>1. 防火墙规则</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 只放行 WireGuard 端口</span></span><br><span class="line">iptables -A INPUT -p udp --dport 51820 -j ACCEPT</span><br><span class="line">iptables -A INPUT -i wg0 -j ACCEPT</span><br><span class="line">iptables -A FORWARD -i wg0 -j ACCEPT</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或者使用 ufw</span></span><br><span class="line">ufw allow 51820/udp</span><br></pre></td></tr></table></figure><h3 id="2-限制-Peer-访问"><a href="#2-限制-Peer-访问" class="headerlink" title="2. 限制 Peer 访问"></a>2. 限制 Peer 访问</h3><p>在 <code>AllowedIPs</code> 中仅放行必要的 IP 段，不要滥用 <code>0.0.0.0/0</code>。</p><h3 id="3-密钥管理"><a href="#3-密钥管理" class="headerlink" title="3. 密钥管理"></a>3. 密钥管理</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 定期更换密钥</span></span><br><span class="line">wg genkey | <span class="built_in">tee</span> new_privatekey</span><br><span class="line"><span class="built_in">cat</span> new_privatekey | wg pubkey</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新配置后重启</span></span><br><span class="line">wg setconf wg0 /etc/wireguard/wg0.conf</span><br></pre></td></tr></table></figure><h3 id="4-使用-Pre-shared-Keys（PSK）"><a href="#4-使用-Pre-shared-Keys（PSK）" class="headerlink" title="4. 使用 Pre-shared Keys（PSK）"></a>4. 使用 Pre-shared Keys（PSK）</h3><p>在配置中添加对称密钥，增加一层加密：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 生成 PSK</span></span><br><span class="line">wg genpsk &gt; psk</span><br><span class="line"></span><br><span class="line"><span class="comment"># Peer 中引用</span></span><br><span class="line">[Peer]</span><br><span class="line">PresharedKey = 上面生成的 PSK</span><br></pre></td></tr></table></figure><h3 id="5-日志监控"><a href="#5-日志监控" class="headerlink" title="5. 日志监控"></a>5. 日志监控</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 查看 WireGuard 日志（内核级）</span></span><br><span class="line">modprobe wireguard-dynamic-debug</span><br><span class="line"><span class="built_in">echo</span> module wireguard +p &gt; /sys/kernel/debug/dynamic_debug/control</span><br><span class="line">dmesg -w | grep wireguard</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或使用 systemd journal</span></span><br><span class="line">journalctl -u wg-quick@wg0 -f</span><br></pre></td></tr></table></figure><hr><h2 id="PVE-9-2-SDN-WireGuard-集成"><a href="#PVE-9-2-SDN-WireGuard-集成" class="headerlink" title="PVE 9.2 SDN + WireGuard 集成"></a>PVE 9.2 SDN + WireGuard 集成</h2><p>PVE 9.2 新增 <strong>WireGuard Fabric</strong> 支持，可在 Proxmox WebUI 中直接配置 WireGuard 隧道作为 SDN 底层网络。</p><h3 id="配置步骤"><a href="#配置步骤" class="headerlink" title="配置步骤"></a>配置步骤</h3><ol><li>Datacenter → <strong>SDN</strong> → <strong>Fabrics</strong> → <strong>Add</strong> → <code>WireGuard</code></li><li>配置 WireGuard Fabric：<ul><li>端口：<code>51820</code></li><li>节点列表：选择参与隧道的节点</li></ul></li><li>系统自动生成每个节点的密钥对</li><li>将 Fabric 关联到 VXLAN Zone，实现跨节点虚拟机二层互通</li></ol><h3 id="优势"><a href="#优势" class="headerlink" title="优势"></a>优势</h3><ul><li>WebUI 集中管理，无需手动编辑配置文件</li><li>自动密钥轮换</li><li>与 PVE SDN 生态（VXLAN、EVPN）深度集成</li><li>加密的节点间迁移网络</li></ul><hr><h2 id="常用管理命令"><a href="#常用管理命令" class="headerlink" title="常用管理命令"></a>常用管理命令</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 启动/停止/重启</span></span><br><span class="line">wg-quick up wg0</span><br><span class="line">wg-quick down wg0</span><br><span class="line">systemctl restart wg-quick@wg0</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看状态</span></span><br><span class="line">wg show</span><br><span class="line">wg show wg0</span><br><span class="line">wg showconf wg0</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看流量统计</span></span><br><span class="line">wg show wg0 transfer</span><br><span class="line"></span><br><span class="line"><span class="comment"># 实时监控</span></span><br><span class="line">watch -n1 wg show</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新 Peer 配置（不重启）</span></span><br><span class="line">wg <span class="built_in">set</span> wg0 peer &lt;公钥&gt; endpoint &lt;新IP:端口&gt;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 删除 Peer</span></span><br><span class="line">wg <span class="built_in">set</span> wg0 peer &lt;公钥&gt; remove</span><br></pre></td></tr></table></figure><h3 id="systemd-服务管理"><a href="#systemd-服务管理" class="headerlink" title="systemd 服务管理"></a>systemd 服务管理</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">systemctl <span class="built_in">enable</span> wg-quick@wg0   <span class="comment"># 开机自启</span></span><br><span class="line">systemctl status wg-quick@wg0   <span class="comment"># 查看状态</span></span><br><span class="line">journalctl -u wg-quick@wg0 -f   <span class="comment"># 查看日志</span></span><br></pre></td></tr></table></figure><hr><h2 id="排错指南"><a href="#排错指南" class="headerlink" title="排错指南"></a>排错指南</h2><h3 id="Q1：wg-show-显示对端一直没握手（latest-handshake-很久）"><a href="#Q1：wg-show-显示对端一直没握手（latest-handshake-很久）" class="headerlink" title="Q1：wg show 显示对端一直没握手（latest handshake 很久）"></a>Q1：wg show 显示对端一直没握手（latest handshake 很久）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 检查防火墙是否放行 UDP 51820</span></span><br><span class="line">iptables -L -n | grep 51820</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查对端 Endpoint 配置是否正确</span></span><br><span class="line"><span class="comment"># 确认公网 IP 可达</span></span><br><span class="line">ping 对端公网IP</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 NAT 环境是否需 PersistentKeepalive</span></span><br><span class="line"><span class="comment"># 两端都设置 PersistentKeepalive = 25</span></span><br></pre></td></tr></table></figure><h3 id="Q2：能-Ping-通虚拟-IP，但访问对端局域网不通"><a href="#Q2：能-Ping-通虚拟-IP，但访问对端局域网不通" class="headerlink" title="Q2：能 Ping 通虚拟 IP，但访问对端局域网不通"></a>Q2：能 Ping 通虚拟 IP，但访问对端局域网不通</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 检查 IP 转发是否开启</span></span><br><span class="line">sysctl net.ipv4.ip_forward</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 iptables FORWARD 规则</span></span><br><span class="line">iptables -L FORWARD -n</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 AllowedIPs 是否包含对端局域网段</span></span><br><span class="line"><span class="comment"># 例如：AllowedIPs = 10.0.0.2/32, 192.168.2.0/24</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查对端是否需要添加回程路由</span></span><br><span class="line"><span class="comment"># Site B 也需要在路由表中知道 Site A 的局域网段</span></span><br></pre></td></tr></table></figure><h3 id="Q3：速度慢"><a href="#Q3：速度慢" class="headerlink" title="Q3：速度慢"></a>Q3：速度慢</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 测试裸 TCP 速度（先排除 WireGuard）</span></span><br><span class="line">iperf3 -c 对端IP -p 5201</span><br><span class="line"></span><br><span class="line"><span class="comment"># 测试 WireGuard 隧道速度</span></span><br><span class="line">iperf3 -c 10.0.0.2 -p 5201</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 MTU</span></span><br><span class="line"><span class="comment"># 尝试降低 MTU 到 1280</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 CPU 是否瓶颈</span></span><br><span class="line"><span class="comment"># WireGuard 是 CPU 密集型，弱 CPU 建议单条隧道</span></span><br></pre></td></tr></table></figure><h3 id="Q4：断线重连慢"><a href="#Q4：断线重连慢" class="headerlink" title="Q4：断线重连慢"></a>Q4：断线重连慢</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 降低 PersistentKeepalive 间隔</span></span><br><span class="line">PersistentKeepalive = 10</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查 UDP 超时设置</span></span><br><span class="line"><span class="comment"># 某些运营商 UDP 超时短（如移动宽带）</span></span><br></pre></td></tr></table></figure><h3 id="Q5：Docker-环境中-WireGuard-不工作"><a href="#Q5：Docker-环境中-WireGuard-不工作" class="headerlink" title="Q5：Docker 环境中 WireGuard 不工作"></a>Q5：Docker 环境中 WireGuard 不工作</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 方案一：使用 host 网络模式</span></span><br><span class="line">docker run --network host ...</span><br><span class="line"></span><br><span class="line"><span class="comment"># 方案二：开放必要端口</span></span><br><span class="line"><span class="comment"># 注意 Docker 的 iptables 规则会覆盖 WireGuard 的</span></span><br><span class="line"><span class="comment"># 在 PostUp 中手动插入规则到 DOCKER-USER 链</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 方案三：将 WireGuard 运行在宿主机，而非容器内</span></span><br></pre></td></tr></table></figure><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>WireGuard 的组网模式可以概括为：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">点对点 → 两台机器直接互联（基础）</span><br><span class="line">      ↓</span><br><span class="line">Hub-and-Spoke → 中心节点转发，多 Spoke 互联（最常用）</span><br><span class="line">      ↓</span><br><span class="line">Site-to-Site → 两个局域网全互联（生产环境）</span><br><span class="line">      ↓</span><br><span class="line">PVE SDN WireGuard → 虚拟化平台隧道网络（高级）</span><br></pre></td></tr></table></figure><p>选择指南：</p><table><thead><tr><th>场景</th><th>推荐模式</th></tr></thead><tbody><tr><td>两台 VPS 互联</td><td>点对点</td></tr><tr><td>多台 VPS + 家庭设备</td><td>Hub-and-Spoke</td></tr><tr><td>分公司&#x2F;异地办公室</td><td>Site-to-Site</td></tr><tr><td>PVE 集群跨公网 SDN</td><td>PVE 9.2 WireGuard Fabric</td></tr></tbody></table><p>WireGuard 用极简的设计实现了极高的性能和安全性。配合 PVE 9.2 的原生 SDN 集成，可以轻松构建跨公网的虚拟化集群网络。</p><hr><p><em>本文最后更新于 2026 年 6 月，对应 WireGuard 1.0 稳定版。</em></p>]]>
    </content>
    <id>https://sam.xx.kg/post/WireGuard%E8%87%AA%E5%BB%BA%E5%86%85%E7%BD%91%E4%BA%92%E8%81%94/</id>
    <link href="https://sam.xx.kg/post/WireGuard%E8%87%AA%E5%BB%BA%E5%86%85%E7%BD%91%E4%BA%92%E8%81%94/"/>
    <published>2026-06-30T08:38:28.000Z</published>
    <summary>从零搭建 WireGuard 实现多服务器/多站点内网互联，涵盖点对点、Hub-and-Spoke、Site-to-Site 等多种组网模式及性能优化。</summary>
    <title>WireGuard 自建内网互联 — 多站点组网完整指南</title>
    <updated>2026-06-30T09:53:00.626Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="服务器运维" scheme="https://sam.xx.kg/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/"/>
    <category term="PVE" scheme="https://sam.xx.kg/tags/PVE/"/>
    <category term="虚拟化" scheme="https://sam.xx.kg/tags/%E8%99%9A%E6%8B%9F%E5%8C%96/"/>
    <category term="Proxmox" scheme="https://sam.xx.kg/tags/Proxmox/"/>
    <category term="KVM" scheme="https://sam.xx.kg/tags/KVM/"/>
    <category term="LXC" scheme="https://sam.xx.kg/tags/LXC/"/>
    <category term="教程" scheme="https://sam.xx.kg/tags/%E6%95%99%E7%A8%8B/"/>
    <content>
      <![CDATA[<blockquote><p><strong>Proxmox VE 9.2</strong> 是目前最新的稳定版本（2026年5月发布），基于 Debian 13 (Trixie)，搭载 Linux Kernel 7.0、QEMU 11.0、LXC 7.0、ZFS 2.4 和 Ceph Squid 19.2.3。本文从零开始，带你完成安装、配置到生产部署的全流程。</p></blockquote><p><strong>版本：</strong> Proxmox VE 9.2-1 | <strong>下载：</strong> <a href="https://www.proxmox.com/en/downloads/proxmox-virtual-environment/iso">proxmox.com</a></p><hr><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li><a href="#%E4%B8%80pve-%E6%98%AF%E4%BB%80%E4%B9%88">一、PVE 是什么</a></li><li><a href="#%E4%BA%8C%E7%B3%BB%E7%BB%9F%E8%A6%81%E6%B1%82">二、系统要求</a></li><li><a href="#%E4%B8%89%E5%88%B6%E4%BD%9C%E5%AE%89%E8%A3%85%E7%9B%98">三、制作安装盘</a></li><li><a href="#%E5%9B%9B%E5%AE%89%E8%A3%85-pve-92">四、安装 PVE 9.2</a></li><li><a href="#%E4%BA%94%E9%A6%96%E6%AC%A1%E7%99%BB%E5%BD%95%E4%B8%8E%E5%88%9D%E5%A7%8B%E5%8C%96%E9%85%8D%E7%BD%AE">五、首次登录与初始化配置</a></li><li><a href="#%E5%85%ADwebui-%E6%A6%82%E8%A7%88">六、WebUI 概览</a></li><li><a href="#%E4%B8%83%E5%88%9B%E5%BB%BA%E7%AC%AC%E4%B8%80%E5%8F%B0%E8%99%9A%E6%8B%9F%E6%9C%BA">七、创建第一台虚拟机</a></li><li><a href="#%E5%85%AB%E5%88%9B%E5%BB%BA-lxc-%E5%AE%B9%E5%99%A8">八、创建 LXC 容器</a></li><li><a href="#%E4%B9%9D%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86">九、存储管理</a></li><li><a href="#%E5%8D%81%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE">十、网络配置</a></li><li><a href="#%E5%8D%81%E4%B8%80%E5%A4%87%E4%BB%BD%E4%B8%8E%E8%BF%98%E5%8E%9F">十一、备份与还原</a></li><li><a href="#%E5%8D%81%E4%BA%8C%E9%9B%86%E7%BE%A4%E4%B8%8E%E9%AB%98%E5%8F%AF%E7%94%A8">十二、集群与高可用</a></li><li><a href="#%E5%8D%81%E4%B8%89pve-92-%E6%96%B0%E7%89%B9%E6%80%A7%E4%BA%AE%E7%82%B9">十三、PVE 9.2 新特性亮点</a></li><li><a href="#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">常见问题</a></li></ul><hr><h2 id="一、PVE-是什么"><a href="#一、PVE-是什么" class="headerlink" title="一、PVE 是什么"></a>一、PVE 是什么</h2><p><strong>Proxmox Virtual Environment (PVE)</strong> 是一个开源的企业级虚拟化平台，基于 <strong>QEMU&#x2F;KVM</strong>（全虚拟化虚拟机）和 <strong>LXC</strong>（轻量级容器）双引擎，提供统一的 Web 管理界面。它支持：</p><table><thead><tr><th>特性</th><th>说明</th></tr></thead><tbody><tr><td><strong>双虚拟化引擎</strong></td><td>同时管理 KVM 虚拟机和 LXC 容器</td></tr><tr><td><strong>内置 WebUI</strong></td><td>无需安装第三方管理工具，浏览器直接管理</td></tr><tr><td><strong>集群管理</strong></td><td>多节点集群，统一管理面板</td></tr><tr><td><strong>高可用 (HA)</strong></td><td>自动故障转移，保障业务连续性</td></tr><tr><td><strong>SDN</strong></td><td>软件定义网络，支持 VXLAN、EVPN、WireGuard</td></tr><tr><td><strong>Ceph 集成</strong></td><td>超融合分布式存储</td></tr><tr><td><strong>ZFS 支持</strong></td><td>高级文件系统，支持压缩、去重、快照</td></tr><tr><td><strong>备份与恢复</strong></td><td>内置备份管理器，支持全量&#x2F;增量&#x2F;定期备份</td></tr></tbody></table><hr><h2 id="二、系统要求"><a href="#二、系统要求" class="headerlink" title="二、系统要求"></a>二、系统要求</h2><h3 id="最低配置"><a href="#最低配置" class="headerlink" title="最低配置"></a>最低配置</h3><table><thead><tr><th>组件</th><th>要求</th></tr></thead><tbody><tr><td>CPU</td><td>64 位 x86，支持 Intel VT-x &#x2F; AMD-V</td></tr><tr><td>内存</td><td>2 GB（不含虚拟机）</td></tr><tr><td>磁盘</td><td>32 GB</td></tr><tr><td>网络</td><td>一张网卡</td></tr></tbody></table><h3 id="推荐配置（生产环境）"><a href="#推荐配置（生产环境）" class="headerlink" title="推荐配置（生产环境）"></a>推荐配置（生产环境）</h3><table><thead><tr><th>组件</th><th>推荐</th></tr></thead><tbody><tr><td>CPU</td><td>多核处理器，支持 VT-d &#x2F; AMD IOMMU</td></tr><tr><td>内存</td><td>16 GB+</td></tr><tr><td>磁盘</td><td>SSD + HDD 组合，或全闪存</td></tr><tr><td>网络</td><td>双网卡（管理 + 业务）或更多</td></tr><tr><td>RAID</td><td>硬件 RAID 或 ZFS 软 RAID</td></tr></tbody></table><blockquote><p>支持 Secure Boot（PVE 8.1+ 已支持），安装前可在 BIOS 中关闭或保持开启。</p></blockquote><hr><h2 id="三、制作安装盘"><a href="#三、制作安装盘" class="headerlink" title="三、制作安装盘"></a>三、制作安装盘</h2><h3 id="下载-ISO"><a href="#下载-ISO" class="headerlink" title="下载 ISO"></a>下载 ISO</h3><p>从官网下载 PVE 9.2 ISO：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 直接下载</span></span><br><span class="line">wget https://enterprise.proxmox.com/iso/proxmox-ve_9.2-1.iso</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或用 BitTorrent 加速</span></span><br><span class="line"><span class="comment"># https://enterprise.proxmox.com/iso/proxmox-ve_9.2-1.iso.torrent</span></span><br></pre></td></tr></table></figure><p>SHA256：<code>4e88fe416df9b527624a175f24c9aa07c714d3332afb1ee3dbf3879573ef2c6c</code></p><h3 id="制作-USB-启动盘"><a href="#制作-USB-启动盘" class="headerlink" title="制作 USB 启动盘"></a>制作 USB 启动盘</h3><p><strong>Windows（Rufus）：</strong></p><ul><li>下载 <a href="https://rufus.ie/">Rufus</a></li><li>选择 U 盘 → 选择 ISO → 写入（DD 模式）</li></ul><p><strong>Linux：</strong></p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 确认设备（切勿搞错盘符！）</span></span><br><span class="line">lsblk</span><br><span class="line"></span><br><span class="line"><span class="comment"># 写入 ISO</span></span><br><span class="line"><span class="built_in">dd</span> <span class="keyword">if</span>=proxmox-ve_9.2-1.iso of=/dev/sdX bs=4M status=progress conv=fsync</span><br></pre></td></tr></table></figure><hr><h2 id="四、安装-PVE-9-2"><a href="#四、安装-PVE-9-2" class="headerlink" title="四、安装 PVE 9.2"></a>四、安装 PVE 9.2</h2><h3 id="启动安装程序"><a href="#启动安装程序" class="headerlink" title="启动安装程序"></a>启动安装程序</h3><ol><li>插入 USB 启动盘，从 USB 引导</li><li>出现 GRUB 菜单，选择 **”Install Proxmox VE (Graphical)”**（图形安装）</li><li>若显卡驱动异常，可选择 <strong>“Terminal UI”</strong> 终端模式</li></ol><h3 id="安装步骤"><a href="#安装步骤" class="headerlink" title="安装步骤"></a>安装步骤</h3><h4 id="第-1-步：接受-EULA"><a href="#第-1-步：接受-EULA" class="headerlink" title="第 1 步：接受 EULA"></a>第 1 步：接受 EULA</h4><p>阅读并接受最终用户许可协议。</p><h4 id="第-2-步：选择目标磁盘"><a href="#第-2-步：选择目标磁盘" class="headerlink" title="第 2 步：选择目标磁盘"></a>第 2 步：选择目标磁盘</h4><ul><li>选择安装磁盘</li><li>点击 <strong>Options</strong> 可切换文件系统（ext4 &#x2F; xfs &#x2F; ZFS &#x2F; btrfs）</li></ul><table><thead><tr><th>文件系统</th><th>适用场景</th></tr></thead><tbody><tr><td><strong>ext4 + LVM</strong></td><td>通用场景，稳定可靠</td></tr><tr><td><strong>xfs + LVM</strong></td><td>大文件性能更优</td></tr><tr><td><strong>ZFS</strong></td><td>需要快照、压缩、去重、RAID</td></tr><tr><td><strong>btrfs</strong></td><td>技术预览</td></tr></tbody></table><h4 id="第-3-步：选择地区与键盘布局"><a href="#第-3-步：选择地区与键盘布局" class="headerlink" title="第 3 步：选择地区与键盘布局"></a>第 3 步：选择地区与键盘布局</h4><ul><li>Location：选择 <code>Asia/Shanghai</code> 或离你最近的地区</li><li>Keyboard Layout：<code>U.S. English</code>（中文用户推荐）</li></ul><h4 id="第-4-步：设置密码与邮箱"><a href="#第-4-步：设置密码与邮箱" class="headerlink" title="第 4 步：设置密码与邮箱"></a>第 4 步：设置密码与邮箱</h4><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">Password:   ******** （至少 12 位，大小写+数字+符号）</span><br><span class="line">Email:      admin@example.com</span><br></pre></td></tr></table></figure><h4 id="第-5-步：网络配置"><a href="#第-5-步：网络配置" class="headerlink" title="第 5 步：网络配置"></a>第 5 步：网络配置</h4><table><thead><tr><th>字段</th><th>说明</th><th>示例</th></tr></thead><tbody><tr><td>Management Interface</td><td>管理网口</td><td>enp2s0</td></tr><tr><td>Hostname</td><td>主机名（FQDN）</td><td>pve1.example.com</td></tr><tr><td>IP Address</td><td>管理 IP</td><td>192.168.1.100</td></tr><tr><td>Netmask</td><td>子网掩码</td><td>24</td></tr><tr><td>Gateway</td><td>默认网关</td><td>192.168.1.1</td></tr><tr><td>DNS Server</td><td>DNS 服务器</td><td>8.8.8.8</td></tr></tbody></table><blockquote><p><strong>注意：</strong> 主机名必须是 FQDN 格式（如 <code>pve1.local</code>），否则部分功能会异常。</p></blockquote><h4 id="第-6-步：确认安装"><a href="#第-6-步：确认安装" class="headerlink" title="第 6 步：确认安装"></a>第 6 步：确认安装</h4><p>确认摘要信息无误后，点击 <strong>Install</strong> 开始安装，等待约 5-10 分钟。</p><p>安装完成后移除 U 盘，系统自动重启。</p><hr><h2 id="五、首次登录与初始化配置"><a href="#五、首次登录与初始化配置" class="headerlink" title="五、首次登录与初始化配置"></a>五、首次登录与初始化配置</h2><h3 id="访问-WebUI"><a href="#访问-WebUI" class="headerlink" title="访问 WebUI"></a>访问 WebUI</h3><p>浏览器访问 <code>https://你的IP:8006</code>，使用 <code>root</code> 和安装时设置的密码，Realm 选择 <code>PAM</code>。</p><h3 id="配置软件源"><a href="#配置软件源" class="headerlink" title="配置软件源"></a>配置软件源</h3><p>由于 PVE 默认使用企业源（需要订阅），个人使用需替换为免费源：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 移除企业源</span></span><br><span class="line"><span class="built_in">rm</span> /etc/apt/sources.list.d/pve-enterprise.list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加免费源</span></span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;deb https://mirrors.ustc.edu.cn/proxmox/debian trixie pve-no-subscription&quot;</span> &gt; /etc/apt/sources.list.d/pve-no-subscription.list</span><br><span class="line"></span><br><span class="line"><span class="comment"># Debian 源换成国内镜像</span></span><br><span class="line">sed -i <span class="string">&#x27;s|deb.debian.org|mirrors.ustc.edu.cn|g&#x27;</span> /etc/apt/sources.list</span><br><span class="line">sed -i <span class="string">&#x27;s|security.debian.org|mirrors.ustc.edu.cn/debian-security|g&#x27;</span> /etc/apt/sources.list</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新</span></span><br><span class="line">apt update &amp;&amp; apt upgrade -y</span><br></pre></td></tr></table></figure><h3 id="去除订阅弹窗（可选）"><a href="#去除订阅弹窗（可选）" class="headerlink" title="去除订阅弹窗（可选）"></a>去除订阅弹窗（可选）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 方法一：直接注释 JS 检测</span></span><br><span class="line">sed -Ezi.bak <span class="string">&#x27;s/(Ext.Msg.show\(\s+)\&#123;title:\s*gettext\(&quot;No valid subscription)/\1\/\/ \2/&#x27;</span> /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js</span><br><span class="line"></span><br><span class="line">systemctl restart pveproxy</span><br></pre></td></tr></table></figure><h3 id="设置时区"><a href="#设置时区" class="headerlink" title="设置时区"></a>设置时区</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">timedatectl set-timezone Asia/Shanghai</span><br></pre></td></tr></table></figure><h3 id="检查安装"><a href="#检查安装" class="headerlink" title="检查安装"></a>检查安装</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">pveversion -v          <span class="comment"># 查看版本</span></span><br><span class="line">pvesh get /version     <span class="comment"># API 版本信息</span></span><br></pre></td></tr></table></figure><hr><h2 id="六、WebUI-概览"><a href="#六、WebUI-概览" class="headerlink" title="六、WebUI 概览"></a>六、WebUI 概览</h2><p>登录后界面分为以下几个核心区域：</p><table><thead><tr><th>区域</th><th>说明</th></tr></thead><tbody><tr><td><strong>左侧树</strong></td><td>数据中心 → 节点 → 存储 → 虚拟机&#x2F;容器</td></tr><tr><td><strong>中央面板</strong></td><td>选中资源的详细信息与操作区域</td></tr><tr><td><strong>顶部栏</strong></td><td>搜索、任务日志、通知、用户菜单</td></tr><tr><td><strong>右侧摘要</strong></td><td>选中节点的 CPU、内存、磁盘实时监控</td></tr></tbody></table><h3 id="主要功能入口"><a href="#主要功能入口" class="headerlink" title="主要功能入口"></a>主要功能入口</h3><ul><li><strong>Datacenter</strong> → 集群级别设置（HA、SDN、权限、备份）</li><li><strong>节点 (pve1)</strong> → 节点级别管理（Shell、网络、存储、更新、防火墙）</li><li><strong>存储</strong> → 各类存储的管理</li><li><strong>虚拟机&#x2F;容器</strong> → 资源创建与管理</li></ul><hr><h2 id="七、创建第一台虚拟机"><a href="#七、创建第一台虚拟机" class="headerlink" title="七、创建第一台虚拟机"></a>七、创建第一台虚拟机</h2><h3 id="准备工作：上传-ISO"><a href="#准备工作：上传-ISO" class="headerlink" title="准备工作：上传 ISO"></a>准备工作：上传 ISO</h3><ol><li>在左侧选择你的节点 → 点击 <code>local (pve1)</code> 存储</li><li>切换到 <strong>ISO Images</strong> 标签页</li><li>点击 <strong>Upload</strong> 上传系统 ISO，或使用 URL 下载</li></ol><p>常用镜像源：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># Ubuntu</span></span><br><span class="line">https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso</span><br><span class="line"></span><br><span class="line"><span class="comment"># Debian</span></span><br><span class="line">https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.9.0-amd64-netinst.iso</span><br><span class="line"></span><br><span class="line"><span class="comment"># Windows</span></span><br><span class="line"><span class="comment"># 自行从 Microsoft 官方下载</span></span><br></pre></td></tr></table></figure><h3 id="创建虚拟机"><a href="#创建虚拟机" class="headerlink" title="创建虚拟机"></a>创建虚拟机</h3><ol><li>点击右上角 <strong>Create VM</strong></li><li><strong>General</strong> 页：<ul><li>VM ID：自动生成或手动指定</li><li>Name：自定义名称</li><li>Start at boot：按需勾选</li></ul></li><li><strong>OS</strong> 页：<ul><li>ISO image：选择已上传的 ISO</li><li>Type：Linux &#x2F; Microsoft Windows &#x2F; Other</li></ul></li><li><strong>System</strong> 页：<ul><li><strong>Graphics card</strong>：<code>SPICE</code> 或 <code>VirtIO-GPU</code></li><li><strong>BIOS</strong>：<code>OVMF (UEFI)</code>（推荐，支持 Secure Boot）</li><li><strong>SCSI Controller</strong>：<code>VirtIO SCSI single</code></li><li><strong>Qemu Agent</strong>：勾选</li></ul></li><li><strong>Disks</strong> 页：<ul><li>Bus&#x2F;Device：<code>VirtIO Block</code>（性能最好）</li><li>Storage：选择存储位置</li><li>Disk size：按需设置</li><li>Cache：<code>Write back (unsafe)</code> 可提升性能</li></ul></li><li><strong>CPU</strong> 页：<ul><li>Type：<code>host</code>（直通宿主 CPU 特性）</li><li>Cores：按需分配</li></ul></li><li><strong>Memory</strong> 页：<ul><li>Memory (MiB)：按需分配</li><li>Ballooning Device：勾选（动态内存调整）</li></ul></li><li><strong>Network</strong> 页：<ul><li>Bridge：<code>vmbr0</code></li><li>Model：<code>VirtIO (paravirtualized)</code></li></ul></li><li><strong>Confirm</strong> 页确认，点击 <strong>Finish</strong></li></ol><h3 id="安装系统"><a href="#安装系统" class="headerlink" title="安装系统"></a>安装系统</h3><ol><li>在 VM 列表中右键 → <strong>Start</strong></li><li>点击 <strong>Console</strong> 进入 VNC 控制台</li><li>按常规方式安装操作系统</li><li>安装完成后安装 QEMU Guest Agent：</li></ol><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># Debian/Ubuntu</span></span><br><span class="line">apt install qemu-guest-agent</span><br><span class="line"></span><br><span class="line"><span class="comment"># Windows</span></span><br><span class="line"><span class="comment"># 挂载 VirtIO ISO → 安装 guest-agent 驱动</span></span><br></pre></td></tr></table></figure><blockquote><p>安装 QEMU Guest Agent 后，WebUI 可显示 VM 的 IP、内存使用等信息，并支持优雅关机。</p></blockquote><h3 id="安装-VirtIO-驱动（Windows）"><a href="#安装-VirtIO-驱动（Windows）" class="headerlink" title="安装 VirtIO 驱动（Windows）"></a>安装 VirtIO 驱动（Windows）</h3><ol><li>下载 <a href="https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso">VirtIO ISO</a></li><li>上传到 PVE 存储</li><li>在 VM 的 Hardware 中添加 CD&#x2F;DVD 驱动，挂载 VirtIO ISO</li><li>进入 Windows，运行 <code>virtio-win-guest-tools.exe</code> 安装所有驱动</li></ol><hr><h2 id="八、创建-LXC-容器"><a href="#八、创建-LXC-容器" class="headerlink" title="八、创建 LXC 容器"></a>八、创建 LXC 容器</h2><p>PVE 的 LXC 容器比虚拟机更轻量，共享宿主机内核，启动只需秒级。</p><h3 id="下载容器模板"><a href="#下载容器模板" class="headerlink" title="下载容器模板"></a>下载容器模板</h3><ol><li>左侧选择节点 → 展开 <code>local (pve1)</code> 存储</li><li>切换到 <strong>CT Templates</strong> 标签页</li><li>点击 <strong>Templates</strong>，选择所需模板（如 <code>ubuntu-24.04-standard</code>）→ <strong>Download</strong></li></ol><p>也可以手动下载模板：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">pveam update</span><br><span class="line">pveam available --section system</span><br><span class="line">pveam download <span class="built_in">local</span> ubuntu-24.04-standard_24.04-2_amd64.tar.zst</span><br></pre></td></tr></table></figure><h3 id="创建容器"><a href="#创建容器" class="headerlink" title="创建容器"></a>创建容器</h3><ol><li>点击 <strong>Create CT</strong></li><li><strong>General</strong>：设置 CT ID、Hostname、密码或 SSH key</li><li><strong>Template</strong>：选择已下载的模板</li><li><strong>Root Disk</strong>：设置磁盘大小和存储位置</li><li><strong>CPU</strong>：分配核心数</li><li><strong>Memory</strong>：分配内存（可勾选 Swap &#x2F; Ballooning）</li><li><strong>Network</strong>：<ul><li>Bridge：<code>vmbr0</code></li><li>IPv4：<code>DHCP</code> 或手动 <code>Static</code></li></ul></li><li><strong>DNS</strong>：默认使用宿主机 DNS</li><li>确认并 <strong>Finish</strong></li></ol><h3 id="容器常用操作"><a href="#容器常用操作" class="headerlink" title="容器常用操作"></a>容器常用操作</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 启动/停止/重启容器</span></span><br><span class="line">pct start 100</span><br><span class="line">pct stop 100</span><br><span class="line">pct restart 100</span><br><span class="line"></span><br><span class="line"><span class="comment"># 进入容器</span></span><br><span class="line">pct enter 100</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看容器信息</span></span><br><span class="line">pct status 100</span><br><span class="line">pct config 100</span><br></pre></td></tr></table></figure><hr><h2 id="九、存储管理"><a href="#九、存储管理" class="headerlink" title="九、存储管理"></a>九、存储管理</h2><p>PVE 支持多种存储后端，统一通过 <strong>Storage</strong> 管理。</p><h3 id="支持的存储类型"><a href="#支持的存储类型" class="headerlink" title="支持的存储类型"></a>支持的存储类型</h3><table><thead><tr><th>类型</th><th>说明</th><th>适用场景</th></tr></thead><tbody><tr><td><strong>Directory</strong></td><td>目录存储（本地文件系统）</td><td>单节点测试</td></tr><tr><td><strong>LVM &#x2F; LVM-thin</strong></td><td>逻辑卷管理</td><td>高性能本地存储</td></tr><tr><td><strong>ZFS</strong></td><td>高级文件系统</td><td>需要快照、压缩、RAID</td></tr><tr><td><strong>NFS</strong></td><td>网络文件系统</td><td>共享存储</td></tr><tr><td><strong>Ceph&#x2F;RBD</strong></td><td>分布式存储</td><td>超融合集群</td></tr><tr><td><strong>Proxmox Backup Server</strong></td><td>专用备份存储</td><td>异地备份</td></tr><tr><td><strong>iSCSI</strong></td><td>块存储</td><td>SAN 对接</td></tr></tbody></table><h3 id="添加存储"><a href="#添加存储" class="headerlink" title="添加存储"></a>添加存储</h3><ol><li>左侧选择 <strong>Datacenter</strong> → <strong>Storage</strong></li><li>点击 <strong>Add</strong>，选择类型</li><li>填写配置（如 NFS 需填服务器 IP 和导出路径）</li></ol><h3 id="存储内容类型"><a href="#存储内容类型" class="headerlink" title="存储内容类型"></a>存储内容类型</h3><table><thead><tr><th>Content</th><th>说明</th></tr></thead><tbody><tr><td>VM images</td><td>虚拟机磁盘镜像</td></tr><tr><td>ISO images</td><td>ISO 镜像</td></tr><tr><td>CT templates</td><td>容器模板</td></tr><tr><td>Backups</td><td>备份文件</td></tr><tr><td>Container</td><td>容器根目录</td></tr><tr><td>Snippets</td><td>脚本片段</td></tr><tr><td>Import</td><td>导入文件</td></tr></tbody></table><hr><h2 id="十、网络配置"><a href="#十、网络配置" class="headerlink" title="十、网络配置"></a>十、网络配置</h2><h3 id="默认网络"><a href="#默认网络" class="headerlink" title="默认网络"></a>默认网络</h3><p>安装时创建的 <code>vmbr0</code> 是 Linux Bridge，虚拟机&#x2F;容器通过它连接物理网络。查看网络配置：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cat</span> /etc/network/interfaces</span><br></pre></td></tr></table></figure><h3 id="常见网络模式"><a href="#常见网络模式" class="headerlink" title="常见网络模式"></a>常见网络模式</h3><table><thead><tr><th>模式</th><th>说明</th><th>配置方式</th></tr></thead><tbody><tr><td><strong>Linux Bridge</strong></td><td>桥接到物理网卡</td><td>安装时自动创建 <code>vmbr0</code></td></tr><tr><td><strong>Linux Bond</strong></td><td>多网卡绑定（冗余&#x2F;负载均衡）</td><td>创建 bond，再创建 bridge</td></tr><tr><td><strong>VLAN</strong></td><td>网络隔离</td><td>Bridge 上启用 VLAN Aware</td></tr><tr><td><strong>OVS</strong></td><td>Open vSwitch，高级 SDN</td><td>安装 <code>openvswitch-switch</code></td></tr><tr><td><strong>SDN</strong></td><td>PVE 9.2 原生 SDN</td><td>Datacenter → SDN</td></tr></tbody></table><h3 id="配置-Bond-网卡"><a href="#配置-Bond-网卡" class="headerlink" title="配置 Bond 网卡"></a>配置 Bond 网卡</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># Interfaces 文件示例</span></span><br><span class="line">auto bond0</span><br><span class="line">iface bond0 inet manual</span><br><span class="line">    bond-slaves enp2s0 enp3s0</span><br><span class="line">    bond-miimon 100</span><br><span class="line">    bond-mode 802.3ad</span><br><span class="line">    bond-xmit-hash-policy layer2+3</span><br><span class="line"></span><br><span class="line">auto vmbr0</span><br><span class="line">iface vmbr0 inet static</span><br><span class="line">    address 192.168.1.100/24</span><br><span class="line">    gateway 192.168.1.1</span><br><span class="line">    bridge-ports bond0</span><br><span class="line">    bridge-stp off</span><br><span class="line">    bridge-fd 0</span><br></pre></td></tr></table></figure><h3 id="VLAN-Aware-Bridge"><a href="#VLAN-Aware-Bridge" class="headerlink" title="VLAN Aware Bridge"></a>VLAN Aware Bridge</h3><p>在 WebUI 中编辑 <code>vmbr0</code>，勾选 <strong>VLAN Aware</strong>，即可在 VM 网卡中指定 VLAN Tag，实现网络隔离。</p><hr><h2 id="十一、备份与还原"><a href="#十一、备份与还原" class="headerlink" title="十一、备份与还原"></a>十一、备份与还原</h2><h3 id="手动备份"><a href="#手动备份" class="headerlink" title="手动备份"></a>手动备份</h3><p>在 VM&#x2F;CT 上右键 → <strong>Backup</strong> → 选择存储位置，支持快照模式（无需停机）。</p><h3 id="定时备份"><a href="#定时备份" class="headerlink" title="定时备份"></a>定时备份</h3><ol><li>Datacenter → <strong>Backup</strong></li><li>点击 <strong>Add</strong>，配置备份计划：</li></ol><table><thead><tr><th>配置项</th><th>说明</th></tr></thead><tbody><tr><td>Storage</td><td>备份存储位置</td></tr><tr><td>Schedule</td><td>cron 表达式（如 <code>0 3 * * *</code> 凌晨 3 点）</td></tr><tr><td>Selection Mode</td><td>全选 &#x2F; 排除 &#x2F; 仅选</td></tr><tr><td>Mode</td><td><code>Snapshot</code>（推荐，不影响运行）</td></tr><tr><td>Compression</td><td><code>Zstd</code>（压缩率高）</td></tr><tr><td>Retention</td><td>保留策略（最后 N 天&#x2F;周&#x2F;月）</td></tr></tbody></table><h3 id="备份到-Proxmox-Backup-Server"><a href="#备份到-Proxmox-Backup-Server" class="headerlink" title="备份到 Proxmox Backup Server"></a>备份到 Proxmox Backup Server</h3><p>PBS 是 PVE 生态的专用备份方案，支持数据去重和增量备份：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 添加 PBS 存储（WebUI 或 CLI）</span></span><br><span class="line">pvesm add pbs backup-pbs \</span><br><span class="line">    --server 192.168.1.200 \</span><br><span class="line">    --datastore main \</span><br><span class="line">    --username root@pam \</span><br><span class="line">    --password ********</span><br></pre></td></tr></table></figure><h3 id="还原"><a href="#还原" class="headerlink" title="还原"></a>还原</h3><ol><li>左侧选择备份存储 → <strong>Backups</strong></li><li>选中备份 → <strong>Restore</strong></li></ol><hr><h2 id="十二、集群与高可用"><a href="#十二、集群与高可用" class="headerlink" title="十二、集群与高可用"></a>十二、集群与高可用</h2><h3 id="创建集群"><a href="#创建集群" class="headerlink" title="创建集群"></a>创建集群</h3><ol><li>在第一个节点上：Datacenter → <strong>Cluster</strong> → <strong>Create Cluster</strong></li><li>输入集群名称</li><li>在其他节点上：Datacenter → <strong>Cluster</strong> → <strong>Join Cluster</strong></li><li>输入第一个节点的 IP 和 root 密码</li></ol><h3 id="集群网络要求"><a href="#集群网络要求" class="headerlink" title="集群网络要求"></a>集群网络要求</h3><ul><li>节点间延迟 &lt; 2ms</li><li>建议配置专用心跳网络（corosync）</li><li>NTP 时间必须同步</li></ul><h3 id="配置-HA（高可用）"><a href="#配置-HA（高可用）" class="headerlink" title="配置 HA（高可用）"></a>配置 HA（高可用）</h3><ol><li>Datacenter → <strong>HA</strong> → <strong>Groups</strong> → 添加 HA 组，指定节点优先级</li><li>Datacenter → <strong>HA</strong> → <strong>Resources</strong> → <strong>Add</strong>，选择要保护的 VM&#x2F;CT</li></ol><p>PVE 9.2 新增 <strong>动态负载均衡</strong>，HA Manager 可根据实时资源使用情况自动迁移虚拟机，实现集群负载均衡。</p><h3 id="集群维护"><a href="#集群维护" class="headerlink" title="集群维护"></a>集群维护</h3><p>PVE 9.2 新增 <code>disarm-ha</code> &#x2F; <code>arm-ha</code> 命令，可在集群维护前安全解除 HA 仲裁，避免误触发节点隔离：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 解除 HA 仲裁（维护前执行）</span></span><br><span class="line">ha-manager disarm-ha</span><br><span class="line"></span><br><span class="line"><span class="comment"># 执行维护操作...</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 恢复 HA 仲裁（维护后执行）</span></span><br><span class="line">ha-manager arm-ha</span><br></pre></td></tr></table></figure><hr><h2 id="十三、PVE-9-2-新特性亮点"><a href="#十三、PVE-9-2-新特性亮点" class="headerlink" title="十三、PVE 9.2 新特性亮点"></a>十三、PVE 9.2 新特性亮点</h2><h3 id="1-动态负载均衡"><a href="#1-动态负载均衡" class="headerlink" title="1. 动态负载均衡"></a>1. 动态负载均衡</h3><p>CRS（Cluster Resource Scheduler）新增动态调度模式，基于实时节点和虚拟机的资源利用率，自动迁移 HA 托管的虚拟机以平衡集群负载。</p><h3 id="2-SDN-重大升级"><a href="#2-SDN-重大升级" class="headerlink" title="2. SDN 重大升级"></a>2. SDN 重大升级</h3><ul><li><strong>WireGuard 支持</strong>：加密隧道协议作为 SDN Fabric</li><li><strong>BGP Fabric</strong>：基于 eBGP 无编号 Underlay</li><li><strong>路由映射与前缀列表</strong>：细粒度 BGP&#x2F;EVPN 路由过滤</li><li><strong>OSPF 路由重分发</strong>：多协议路由架构</li><li><strong>EVPN IPv6 Underlay</strong>：全面支持 IPv6</li><li><strong>自定义 CPU 模型</strong>：在 WebUI 中创建和管理自定义 CPU 模型</li></ul><h3 id="3-HA-维护模式"><a href="#3-HA-维护模式" class="headerlink" title="3. HA 维护模式"></a>3. HA 维护模式</h3><p><code>disarm-ha</code> &#x2F; <code>arm-ha</code> 命令，在集群网络维护时安全暂停 HA 仲裁，完成后自动恢复。</p><h3 id="4-Ceph-Tentacle-20-2"><a href="#4-Ceph-Tentacle-20-2" class="headerlink" title="4. Ceph Tentacle 20.2"></a>4. Ceph Tentacle 20.2</h3><p>新安装默认使用 Ceph Tentacle 20.2，同时支持 Ceph Squid 19.2.3。</p><h3 id="5-Linux-Kernel-7-0"><a href="#5-Linux-Kernel-7-0" class="headerlink" title="5. Linux Kernel 7.0"></a>5. Linux Kernel 7.0</h3><p>基于最新的 7.0 内核，QEMU 11.0，LXC 7.0，ZFS 2.4。</p><h3 id="6-安装器增强"><a href="#6-安装器增强" class="headerlink" title="6. 安装器增强"></a>6. 安装器增强</h3><ul><li>支持 PXE&#x2F;iPXE 自动安装</li><li>支持 Embed 认证令牌</li><li>支持引导时 <code>Ctrl-C</code> 进入调试 Shell</li></ul><hr><h2 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h2><h3 id="Q1：安装后无法访问-WebUI？"><a href="#Q1：安装后无法访问-WebUI？" class="headerlink" title="Q1：安装后无法访问 WebUI？"></a>Q1：安装后无法访问 WebUI？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 检查 PVE 服务状态</span></span><br><span class="line">systemctl status pveproxy</span><br><span class="line">systemctl status pvedaemon</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查防火墙</span></span><br><span class="line">iptables -L -n</span><br><span class="line"></span><br><span class="line"><span class="comment"># 确认端口监听</span></span><br><span class="line">ss -tlnp | grep 8006</span><br></pre></td></tr></table></figure><p>PVE 默认安装 <code>fail2ban</code>，多次输错密码可能被临时封禁。</p><h3 id="Q2：虚拟机无法联网？"><a href="#Q2：虚拟机无法联网？" class="headerlink" title="Q2：虚拟机无法联网？"></a>Q2：虚拟机无法联网？</h3><ul><li>确认 VM 网卡桥接到 <code>vmbr0</code></li><li>检查物理网卡是否正常：<code>ip a</code></li><li>检查 PVE 防火墙配置：Datacenter → Firewall → Options → <code>Enable: No</code></li></ul><h3 id="Q3：如何扩展现有磁盘？"><a href="#Q3：如何扩展现有磁盘？" class="headerlink" title="Q3：如何扩展现有磁盘？"></a>Q3：如何扩展现有磁盘？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 先在 PVE WebUI 中调整磁盘大小</span></span><br><span class="line"><span class="comment"># Hardware → 磁盘 → Resize</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 在 VM 内识别新大小</span></span><br><span class="line"><span class="comment"># Linux：resize2fs /dev/sda1 或 lvextend + xfs_growfs</span></span><br><span class="line"><span class="comment"># Windows：磁盘管理 → 扩展卷</span></span><br></pre></td></tr></table></figure><h3 id="Q4：PVE-经常弹出”无有效订阅”提示？"><a href="#Q4：PVE-经常弹出”无有效订阅”提示？" class="headerlink" title="Q4：PVE 经常弹出”无有效订阅”提示？"></a>Q4：PVE 经常弹出”无有效订阅”提示？</h3><p>参考本文第五节中的去订阅弹窗脚本。</p><h3 id="Q5：如何迁移虚拟机到另一台-PVE？"><a href="#Q5：如何迁移虚拟机到另一台-PVE？" class="headerlink" title="Q5：如何迁移虚拟机到另一台 PVE？"></a>Q5：如何迁移虚拟机到另一台 PVE？</h3><ul><li><strong>在线迁移</strong>：右键 VM → <strong>Migrate</strong>（需集群环境）</li><li><strong>离线迁移</strong>：备份 → 还原到目标节点</li><li><strong>远程迁移</strong>：PVE 9.x 支持跨集群远程迁移</li></ul><h3 id="Q6：如何从-PVE-8-x-升级到-9-2？"><a href="#Q6：如何从-PVE-8-x-升级到-9-2？" class="headerlink" title="Q6：如何从 PVE 8.x 升级到 9.2？"></a>Q6：如何从 PVE 8.x 升级到 9.2？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 确认当前版本</span></span><br><span class="line">pveversion</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新到最新 8.x</span></span><br><span class="line">apt update &amp;&amp; apt upgrade -y</span><br><span class="line"></span><br><span class="line"><span class="comment"># 通过 WebUI 或 CLI 执行升级</span></span><br><span class="line"><span class="comment"># 官方文档：https://pve.proxmox.com/wiki/Upgrade_from_8_to_9</span></span><br></pre></td></tr></table></figure><blockquote><p><strong>注意：</strong> 跨大版本升级前务必做好完整备份，并在测试环境先行验证。</p></blockquote><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>Proxmox VE 9.2 作为最新的稳定版本，在虚拟化性能、SDN 网络、高可用调度和易用性方面都有显著提升。无论你是个人开发者搭建家庭实验室，还是运维人员部署生产环境，PVE 都是一个功能强大且完全开源的选择。</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">PVE 部署流程总结：</span><br><span class="line"></span><br><span class="line">下载 ISO → 制作启动盘 → 安装 PVE → 换源/更新 → 上传镜像 → 创建 VM/CT</span><br><span class="line">→ 配置存储/网络 → 设置备份 → (可选)组建集群 → 配置 HA</span><br></pre></td></tr></table></figure><p>建议后续进一步学习：</p><ul><li><strong>ZFS 存储优化</strong>（ARC 缓存、压缩、去重）</li><li><strong>Ceph 超融合部署</strong></li><li><strong>SDN 与 EVPN 组网</strong></li><li><strong>Terraform&#x2F;Ansible 自动化管理</strong></li><li><strong>Proxmox Datacenter Manager</strong> 多数据中心管理</li></ul><hr><p><em>本文最后更新于 2026 年 6 月，对应 Proxmox VE 9.2-1 版本。</em></p>]]>
    </content>
    <id>https://sam.xx.kg/post/PVE9-2%E5%AE%8C%E6%95%B4%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/</id>
    <link href="https://sam.xx.kg/post/PVE9-2%E5%AE%8C%E6%95%B4%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/"/>
    <published>2026-06-30T07:30:00.000Z</published>
    <summary>最新版 Proxmox VE 9.2 从零开始完整教程，涵盖 ISO 安装、初始化配置、WebUI 管理、创建 VM/LXC、存储网络、备份恢复、集群与 HA 等核心内容。</summary>
    <title>Proxmox VE 9.2 完整使用教程 — 从安装到生产部署</title>
    <updated>2026-06-30T08:30:44.906Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="代理与网络" scheme="https://sam.xx.kg/categories/%E4%BB%A3%E7%90%86%E4%B8%8E%E7%BD%91%E7%BB%9C/"/>
    <category term="MiGate" scheme="https://sam.xx.kg/tags/MiGate/"/>
    <category term="VPS" scheme="https://sam.xx.kg/tags/VPS/"/>
    <category term="Xray" scheme="https://sam.xx.kg/tags/Xray/"/>
    <category term="sing-box" scheme="https://sam.xx.kg/tags/sing-box/"/>
    <category term="代理" scheme="https://sam.xx.kg/tags/%E4%BB%A3%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p><strong>MiGate</strong> 是一款 Go 单二进制轻量级 VPS 面板，使用本地 SQLite 数据库和嵌入式 React WebUI，管理 Xray 和 sing-box 的入站节点、客户端、共享出站配置、路由规则以及核心配置的生成与应用。</p></blockquote><p><strong>版本：</strong> v1.5.4 | <strong>仓库：</strong> <a href="https://github.com/imzyb/MiGate">github.com&#x2F;imzyb&#x2F;MiGate</a></p><hr><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li><a href="#%E5%8A%9F%E8%83%BD%E6%A6%82%E8%A7%88">功能概览</a></li><li><a href="#%E4%B8%80%E9%94%AE%E5%AE%89%E8%A3%85">一键安装</a></li><li><a href="#%E9%9D%A2%E6%9D%BF%E9%85%8D%E7%BD%AE">面板配置</a></li><li><a href="#%E6%97%A5%E5%B8%B8%E7%AE%A1%E7%90%86">日常管理</a></li><li><a href="#%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3">配置详解</a></li><li><a href="#%E5%AE%89%E5%85%A8%E5%BB%BA%E8%AE%AE">安全建议</a></li><li><a href="#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">常见问题</a></li></ul><hr><h2 id="功能概览"><a href="#功能概览" class="headerlink" title="功能概览"></a>功能概览</h2><table><thead><tr><th>功能</th><th>说明</th></tr></thead><tbody><tr><td>单二进制部署</td><td>无需 Python&#x2F;Node 运行时，一个 Go 二进制文件搞定</td></tr><tr><td>React WebUI</td><td>管理入站、客户端、出站、路由、TLS 证书、设置等</td></tr><tr><td>双核心支持</td><td>同时管理 Xray 和 sing-box，面板配置自动同步</td></tr><tr><td>多协议入站</td><td>VLESS、VMess、Trojan、Shadowsocks、Hysteria2、TUIC、ShadowTLS</td></tr><tr><td>SOCKS5 池</td><td>导入 SOCKS5 代理池，灵活分配出站</td></tr><tr><td>路由管理</td><td>可视化配置路由规则，按需分流</td></tr><tr><td>TLS 证书</td><td>内置 ACME 证书申请与管理</td></tr><tr><td>订阅分享</td><td>生成客户端订阅链接，一键导入</td></tr><tr><td>备份恢复</td><td>内置备份&#x2F;恢复功能，数据安全无忧</td></tr><tr><td>systemd 管理</td><td>自动注册服务，支持开机自启</td></tr></tbody></table><hr><h2 id="一键安装"><a href="#一键安装" class="headerlink" title="一键安装"></a>一键安装</h2><h3 id="环境要求"><a href="#环境要求" class="headerlink" title="环境要求"></a>环境要求</h3><ul><li><strong>系统：</strong> Linux（推荐 Debian 11&#x2F;12、Ubuntu 22.04+）</li><li><strong>权限：</strong> root 用户</li><li><strong>架构：</strong> amd64 &#x2F; arm64</li></ul><h3 id="安装命令"><a href="#安装命令" class="headerlink" title="安装命令"></a>安装命令</h3><p>在 VPS 上以 root 用户执行：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -Ls https://raw.githubusercontent.com/imzyb/MiGate/main/packaging/install.sh)</span><br></pre></td></tr></table></figure><h3 id="指定版本安装"><a href="#指定版本安装" class="headerlink" title="指定版本安装"></a>指定版本安装</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">MIGATE_VERSION=v1.0.21 bash &lt;(curl -Ls https://raw.githubusercontent.com/imzyb/MiGate/main/packaging/install.sh)</span><br></pre></td></tr></table></figure><h3 id="安装流程"><a href="#安装流程" class="headerlink" title="安装流程"></a>安装流程</h3><p>首次安装时，安装程序会依次进行：</p><ol><li>环境检测（检查系统、架构、依赖）</li><li>检测现有 MiGate 安装</li><li>询问面板配置信息：</li></ol><table><thead><tr><th>配置项</th><th>说明</th><th>默认值</th></tr></thead><tbody><tr><td>面板端口</td><td>WebUI 访问端口</td><td><code>9999</code></td></tr><tr><td>用户名</td><td>管理员用户名</td><td><code>admin</code></td></tr><tr><td>密码</td><td>管理员密码，留空自动生成</td><td>随机密码</td></tr><tr><td>Web 路径</td><td>面板访问路径</td><td><code>/panel</code></td></tr><tr><td>安装核心</td><td>是否安装&#x2F;修复 Xray 和 sing-box</td><td>是</td></tr></tbody></table><h3 id="非交互式安装"><a href="#非交互式安装" class="headerlink" title="非交互式安装"></a>非交互式安装</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 安装或升级，保留现有配置</span></span><br><span class="line">bash &lt;(curl -Ls https://raw.githubusercontent.com/imzyb/MiGate/main/packaging/install.sh) --install --<span class="built_in">yes</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 预览安装操作（不实际执行）</span></span><br><span class="line">bash &lt;(curl -Ls https://raw.githubusercontent.com/imzyb/MiGate/main/packaging/install.sh) --install --<span class="built_in">yes</span> --dry-run</span><br></pre></td></tr></table></figure><h3 id="访问面板"><a href="#访问面板" class="headerlink" title="访问面板"></a>访问面板</h3><p>安装完成后，通过浏览器访问：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">http://&lt;你的VPS_IP&gt;:9999/panel</span><br></pre></td></tr></table></figure><blockquote><p>面板服务默认绑定 <code>0.0.0.0</code>，方便直接访问。生产环境建议使用 Nginx&#x2F;Caddy 反向代理并开启 HTTPS。</p></blockquote><hr><h2 id="面板配置"><a href="#面板配置" class="headerlink" title="面板配置"></a>面板配置</h2><h3 id="基本配置"><a href="#基本配置" class="headerlink" title="基本配置"></a>基本配置</h3><p>配置文件位于 <code>/etc/migate/panel.json</code>：</p><figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;port&quot;</span><span class="punctuation">:</span> <span class="number">9999</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;username&quot;</span><span class="punctuation">:</span> <span class="string">&quot;admin&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;web_path&quot;</span><span class="punctuation">:</span> <span class="string">&quot;/panel&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;public_host&quot;</span><span class="punctuation">:</span> <span class="string">&quot;your-domain.com&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;trust_proxy&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><table><thead><tr><th>配置项</th><th>说明</th></tr></thead><tbody><tr><td><code>port</code></td><td>面板监听端口</td></tr><tr><td><code>username</code></td><td>管理员用户名</td></tr><tr><td><code>web_path</code></td><td>面板访问路径</td></tr><tr><td><code>public_host</code></td><td>公共域名，用于生成订阅链接</td></tr><tr><td><code>trust_proxy</code></td><td>是否信任反向代理（使用 <code>X-Forwarded-Proto</code>）</td></tr></tbody></table><h3 id="核心配置路径"><a href="#核心配置路径" class="headerlink" title="核心配置路径"></a>核心配置路径</h3><table><thead><tr><th>文件</th><th>说明</th></tr></thead><tbody><tr><td><code>/etc/migate/panel.json</code></td><td>面板配置</td></tr><tr><td><code>/etc/migate/cores/xray.json</code></td><td>Xray 核心配置</td></tr><tr><td><code>/etc/migate/cores/sing-box.json</code></td><td>sing-box 核心配置</td></tr><tr><td><code>/var/lib/migate/migate.db</code></td><td>SQLite 数据库</td></tr><tr><td><code>/var/lib/migate/versions.json</code></td><td>安装状态</td></tr><tr><td><code>/var/lib/migate/backups/</code></td><td>备份目录</td></tr></tbody></table><hr><h2 id="日常管理"><a href="#日常管理" class="headerlink" title="日常管理"></a>日常管理</h2><h3 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h3><p>MiGate 提供了 <code>mg</code> 命令方便日常操作：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 查看面板状态</span></span><br><span class="line">mg status</span><br><span class="line">mg doctor</span><br><span class="line">mg info</span><br><span class="line">mg ports</span><br><span class="line"></span><br><span class="line"><span class="comment"># 重启面板</span></span><br><span class="line">mg restart</span><br><span class="line">mg restart all</span><br><span class="line">systemctl restart migate</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看日志</span></span><br><span class="line">mg logs -f</span><br><span class="line">journalctl -u migate -f</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新面板</span></span><br><span class="line">mg update</span><br><span class="line">mg update --check</span><br><span class="line"></span><br><span class="line"><span class="comment"># 备份与恢复</span></span><br><span class="line">mg backup</span><br><span class="line">mg restore /var/lib/migate/backups/migate-backup-20260629-120000.tar.gz</span><br></pre></td></tr></table></figure><h3 id="核心管理"><a href="#核心管理" class="headerlink" title="核心管理"></a>核心管理</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 安装或修复运行核心</span></span><br><span class="line">migate-install --install-xray --<span class="built_in">yes</span></span><br><span class="line">migate-install --install-singbox --<span class="built_in">yes</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 系统服务</span></span><br><span class="line">systemctl status migate</span><br><span class="line">systemctl status migate-xray</span><br><span class="line">systemctl status migate-sing-box</span><br></pre></td></tr></table></figure><h3 id="卸载"><a href="#卸载" class="headerlink" title="卸载"></a>卸载</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 仅卸载面板（保留核心和配置）</span></span><br><span class="line">migate-install --uninstall --<span class="built_in">yes</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 卸载面板及核心（保留配置和数据）</span></span><br><span class="line">migate-install --uninstall -- --with-cores --<span class="built_in">yes</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 完全卸载（清除所有数据和配置）</span></span><br><span class="line">migate-install --uninstall -- --purge --<span class="built_in">yes</span></span><br></pre></td></tr></table></figure><hr><h2 id="安全建议"><a href="#安全建议" class="headerlink" title="安全建议"></a>安全建议</h2><ol><li><strong>设置强密码</strong> — 安装时设置高强度管理员密码</li><li><strong>使用反向代理</strong> — 通过 Nginx&#x2F;Caddy 反向代理并配置 HTTPS</li><li><strong>配置 <code>public_host</code></strong> — 在 <code>/etc/migate/panel.json</code> 中设置公共域名</li><li><strong>启用 <code>trust_proxy</code></strong> — 使用 HTTPS 反向代理时设为 <code>true</code></li><li><strong>限制访问来源</strong> — 通过防火墙限制面板端口的访问 IP</li><li><strong>定期备份</strong> — 使用 <code>mg backup</code> 定期备份数据库和配置</li></ol><hr><h2 id="反向代理配置示例"><a href="#反向代理配置示例" class="headerlink" title="反向代理配置示例"></a>反向代理配置示例</h2><h3 id="Nginx"><a href="#Nginx" class="headerlink" title="Nginx"></a>Nginx</h3><figure class="highlight nginx"><table><tr><td class="code"><pre><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span> <span class="number">443</span> ssl;</span><br><span class="line">    <span class="attribute">server_name</span> your-domain.com;</span><br><span class="line"></span><br><span class="line">    <span class="attribute">ssl_certificate</span> /path/to/cert.pem;</span><br><span class="line">    <span class="attribute">ssl_certificate_key</span> /path/to/key.pem;</span><br><span class="line"></span><br><span class="line">    <span class="section">location</span> /panel &#123;</span><br><span class="line">        <span class="attribute">proxy_pass</span> http://127.0.0.1:9999;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> Host <span class="variable">$host</span>;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> X-Real-IP <span class="variable">$remote_addr</span>;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> X-Forwarded-Proto <span class="variable">$scheme</span>;</span><br><span class="line">        <span class="attribute">proxy_http_version</span> <span class="number">1</span>.<span class="number">1</span>;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> Upgrade <span class="variable">$http_upgrade</span>;</span><br><span class="line">        <span class="attribute">proxy_set_header</span> Connection <span class="string">&quot;upgrade&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="Caddy"><a href="#Caddy" class="headerlink" title="Caddy"></a>Caddy</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">your-domain.com &#123;</span><br><span class="line">    reverse_proxy /panel* 127.0.0.1:9999</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><hr><h2 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h2><h3 id="Q1：安装后无法访问面板？"><a href="#Q1：安装后无法访问面板？" class="headerlink" title="Q1：安装后无法访问面板？"></a>Q1：安装后无法访问面板？</h3><ul><li>检查面板是否运行：<code>systemctl status migate</code></li><li>检查防火墙是否放行了端口：<code>ufw status</code> 或 <code>iptables -L</code></li><li>检查面板绑定地址：<code>ss -tlnp | grep 9999</code></li></ul><h3 id="Q2：如何修改面板端口？"><a href="#Q2：如何修改面板端口？" class="headerlink" title="Q2：如何修改面板端口？"></a>Q2：如何修改面板端口？</h3><p>编辑 <code>/etc/migate/panel.json</code> 修改 <code>port</code> 值，然后执行 <code>mg restart</code>。</p><h3 id="Q3：忘记管理员密码？"><a href="#Q3：忘记管理员密码？" class="headerlink" title="Q3：忘记管理员密码？"></a>Q3：忘记管理员密码？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在 panel.json 中修改 password 字段</span></span><br><span class="line">nano /etc/migate/panel.json</span><br><span class="line"></span><br><span class="line"><span class="comment"># 重启面板</span></span><br><span class="line">systemctl restart migate</span><br></pre></td></tr></table></figure><h3 id="Q4：如何升级-MiGate？"><a href="#Q4：如何升级-MiGate？" class="headerlink" title="Q4：如何升级 MiGate？"></a>Q4：如何升级 MiGate？</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 在线升级</span></span><br><span class="line">mg update</span><br><span class="line"></span><br><span class="line"><span class="comment"># 或重新执行安装脚本</span></span><br><span class="line">bash &lt;(curl -Ls https://raw.githubusercontent.com/imzyb/MiGate/main/packaging/install.sh) --install --<span class="built_in">yes</span></span><br></pre></td></tr></table></figure><h3 id="Q5：订阅链接无法使用？"><a href="#Q5：订阅链接无法使用？" class="headerlink" title="Q5：订阅链接无法使用？"></a>Q5：订阅链接无法使用？</h3><ul><li>确认 <code>public_host</code> 已设置为正确的域名或 IP</li><li>确认对应端口已放行</li><li>检查证书是否有效</li></ul><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>MiGate 的部署流程可以概括为：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">执行一键安装 → 配置面板 → 添加入站节点 → 配置客户端 → 生成订阅链接</span><br></pre></td></tr></table></figure><p>整个安装过程仅需一条命令，几分钟内即可完成。部署完成后，你就能通过 WebUI 直观地管理你的 VPS 代理节点、客户端和路由规则。</p><p>如果你在部署过程中遇到任何问题，欢迎在项目 <a href="https://github.com/imzyb/MiGate/issues">GitHub Issues</a> 中提出。</p><hr><p><em>本文档最后更新于 2026 年 6 月，对应 MiGate v1.5.4 版本。</em></p>]]>
    </content>
    <id>https://sam.xx.kg/post/MiGate%E9%83%A8%E7%BD%B2%E6%95%99%E7%A8%8B/</id>
    <link href="https://sam.xx.kg/post/MiGate%E9%83%A8%E7%BD%B2%E6%95%99%E7%A8%8B/"/>
    <published>2026-06-29T15:11:28.000Z</published>
    <summary>MiGate 是一款 Go 单二进制文件轻量级 VPS 面板，通过本地 SQLite 和嵌入式 WebUI 管理 Xray 和 sing-box 的入站、客户端、共享出站配置、路由和核心配置。</summary>
    <title>MiGate 部署教程 — 轻量级 VPS 代理管理面板</title>
    <updated>2026-06-30T03:29:37.626Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <content>
      <![CDATA[<blockquote><p><strong>MiSub</strong> 是一款部署在 Cloudflare Pages 上的轻量级代理订阅管理面板。它可以帮你管理多个上游订阅链接和手动节点，自由组合成不同场景的订阅配置，并通过可视化的<strong>算子链</strong>（Operator Chain）对节点进行过滤、重命名、排序、去重等处理，最终生成 Clash、Sing-Box、Surge、Loon、Quantumult X、Shadowrocket 等主流客户端可直接使用的订阅链接。</p></blockquote><p><strong>版本：</strong> v2.7.0 | <strong>协议：</strong> MIT | <strong>仓库：</strong> <a href="https://github.com/imzyb/MiSub">github.com&#x2F;imzyb&#x2F;MiSub</a></p><hr><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li><a href="#%E5%8A%9F%E8%83%BD%E6%A6%82%E8%A7%88">功能概览</a></li><li><a href="#%E5%89%8D%E7%BD%AE%E5%87%86%E5%A4%87">前置准备</a></li><li><a href="#%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2cloudflare-pages--git">一键部署（Cloudflare Pages + Git）</a></li><li><a href="#%E9%85%8D%E7%BD%AE%E5%AD%98%E5%82%A8%E7%BB%91%E5%AE%9A">配置存储绑定</a><ul><li><a href="#kv-%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E5%BF%85%E9%9C%80">KV 命名空间（必需）</a></li><li><a href="#d1-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%8E%A8%E8%8D%90">D1 数据库（推荐）</a></li></ul></li><li><a href="#%E8%AE%BE%E7%BD%AE%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F">设置环境变量</a></li><li><a href="#%E9%85%8D%E7%BD%AE-cron-%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1">配置 Cron 定时任务</a></li><li><a href="#%E5%AE%8C%E6%88%90%E9%83%A8%E7%BD%B2%E4%B8%8E%E7%99%BB%E5%BD%95">完成部署与登录</a></li><li><a href="#%E6%9C%AC%E5%9C%B0%E5%BC%80%E5%8F%91%E9%80%89%E8%AF%BB">本地开发（选读）</a></li><li><a href="#%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98">常见问题</a></li></ul><hr><h2 id="功能概览"><a href="#功能概览" class="headerlink" title="功能概览"></a>功能概览</h2><table><thead><tr><th>功能</th><th>说明</th></tr></thead><tbody><tr><td>订阅管理</td><td>管理多个机场订阅链接，自动获取节点信息</td></tr><tr><td>手动节点</td><td>支持 Shadowsocks &#x2F; VMess &#x2F; VLESS &#x2F; Trojan &#x2F; Hysteria2 &#x2F; TUIC 等十余种协议</td></tr><tr><td>节点分组</td><td>可将节点分组排序，添加备注、流量、到期时间等信息</td></tr><tr><td>场景配置（Profiles）</td><td>自由组合订阅源和手动节点分组，按场景产出不同配置</td></tr><tr><td>算子链（Operator Chain）</td><td>可视化流水线：过滤 → 正则重命名 → 脚本&#x2F;DSL → 排序 → 智能去重</td></tr><tr><td>多客户端输出</td><td>Clash&#x2F;Mihomo、Sing-Box、Surge、Loon、Quantumult X、Shadowrocket、V2rayN&#x2F;Ng、base64</td></tr><tr><td>内置模板</td><td>ACL4SSR 风格规则集、区域分组、策略组、自定义规则模板</td></tr><tr><td>自定义公开页</td><td>发布公开浏览页或沉浸式伪装页，支持 HTML 渲染</td></tr><tr><td>存储可选</td><td>Cloudflare KV（简单）或 D1（高写入、结构化存储）</td></tr><tr><td>通知与运维</td><td>Telegram 通知、定时刷新、备份恢复、操作日志、系统诊断</td></tr><tr><td>现代 UI</td><td>响应式 Vue 3 界面，支持亮&#x2F;暗主题、中&#x2F;英文切换</td></tr></tbody></table><hr><h2 id="前置准备"><a href="#前置准备" class="headerlink" title="前置准备"></a>前置准备</h2><p>在开始部署之前，你需要准备好以下内容：</p><ol><li><strong>一个 GitHub 账号</strong> — 用来 Fork 项目仓库</li><li><strong>一个 Cloudflare 账号</strong> — 用来部署 Pages 和创建 KV&#x2F;D1</li><li><strong>一个域名（可选）</strong> — 可在 Cloudflare 上绑定自定义域名</li></ol><blockquote><p>所有操作都可在免费额度内完成，Cloudflare Pages 的免费计划足够个人和小团队使用。</p></blockquote><hr><h2 id="一键部署（Cloudflare-Pages-Git）"><a href="#一键部署（Cloudflare-Pages-Git）" class="headerlink" title="一键部署（Cloudflare Pages + Git）"></a>一键部署（Cloudflare Pages + Git）</h2><p>这是官方推荐的部署方式，只需在 Cloudflare 控制台中点几下即可完成。</p><h3 id="第-1-步：Fork-项目仓库"><a href="#第-1-步：Fork-项目仓库" class="headerlink" title="第 1 步：Fork 项目仓库"></a>第 1 步：Fork 项目仓库</h3><ol><li>访问项目地址：<a href="https://github.com/imzyb/MiSub">https://github.com/imzyb/MiSub</a></li><li>点击右上角的 <strong>Fork</strong> 按钮，将仓库 Fork 到自己的 GitHub 账号下</li></ol><h3 id="第-2-步：连接到-Cloudflare-Pages"><a href="#第-2-步：连接到-Cloudflare-Pages" class="headerlink" title="第 2 步：连接到 Cloudflare Pages"></a>第 2 步：连接到 Cloudflare Pages</h3><ol><li>登录 <a href="https://dash.cloudflare.com/">Cloudflare Dashboard</a></li><li>左侧菜单选择 <strong>Workers &amp; Pages</strong></li><li>点击 <strong>Create application</strong> → 选择 <strong>Pages</strong> 标签页</li><li>点击 <strong>Connect to Git</strong></li></ol><h3 id="第-3-步：选择仓库"><a href="#第-3-步：选择仓库" class="headerlink" title="第 3 步：选择仓库"></a>第 3 步：选择仓库</h3><ol><li>授权 Cloudflare 访问你的 GitHub 账号（首次需要）</li><li>在仓库列表中找到你刚才 Fork 的 <code>MiSub</code> 仓库</li><li>点击 <strong>Begin setup</strong></li></ol><h3 id="第-4-步：配置构建设置"><a href="#第-4-步：配置构建设置" class="headerlink" title="第 4 步：配置构建设置"></a>第 4 步：配置构建设置</h3><p>在 <strong>Set up builds and deployments</strong> 页面，填写以下内容：</p><table><thead><tr><th>配置项</th><th>值</th></tr></thead><tbody><tr><td><strong>Framework preset</strong></td><td><code>Vue</code></td></tr><tr><td><strong>Build command</strong></td><td><code>npm run build</code></td></tr><tr><td><strong>Build output directory</strong></td><td><code>dist</code></td></tr><tr><td><strong>Root directory</strong></td><td>（留空，使用仓库根目录）</td></tr></tbody></table><p>保持其他选项为默认值，点击 <strong>Save and Deploy</strong>。</p><h3 id="第-5-步：等待首次部署"><a href="#第-5-步：等待首次部署" class="headerlink" title="第 5 步：等待首次部署"></a>第 5 步：等待首次部署</h3><p>Cloudflare 会自动拉取代码、安装依赖并执行构建。首次部署大约需要 1-2 分钟。</p><p>部署完成后，你会得到一个 <code>https://&lt;project-name&gt;.pages.dev</code> 的域名。此时访问会看到登录页面，但还没有配置存储绑定，<strong>不要急着登录</strong>，继续下一步。</p><hr><h2 id="配置存储绑定"><a href="#配置存储绑定" class="headerlink" title="配置存储绑定"></a>配置存储绑定</h2><p>MiSub 需要至少一个 KV 命名空间来存储数据，同时强烈建议创建 D1 数据库以获得更好的性能和结构化存储。</p><h3 id="KV-命名空间（必需）"><a href="#KV-命名空间（必需）" class="headerlink" title="KV 命名空间（必需）"></a>KV 命名空间（必需）</h3><h4 id="创建-KV-命名空间"><a href="#创建-KV-命名空间" class="headerlink" title="创建 KV 命名空间"></a>创建 KV 命名空间</h4><p>在 Cloudflare Dashboard 中：</p><ol><li>左侧菜单选择 <strong>Workers &amp; Pages</strong> → <strong>KV</strong></li><li>点击 <strong>Create a namespace</strong></li><li>命名空间名称填入 <code>misub-kv</code>（或你喜欢的名字）</li><li>点击 <strong>Create</strong></li></ol><h4 id="绑定到-Pages-项目"><a href="#绑定到-Pages-项目" class="headerlink" title="绑定到 Pages 项目"></a>绑定到 Pages 项目</h4><ol><li>进入你的 Pages 项目页面</li><li>点击 <strong>Settings</strong> → <strong>Functions</strong> → <strong>KV namespace bindings</strong></li><li>点击 <strong>Add binding</strong></li><li>填写：<ul><li><strong>Variable name:</strong> <code>MISUB_KV</code></li><li><strong>KV namespace:</strong> 选择刚才创建的 <code>misub-kv</code></li></ul></li><li>点击 <strong>Save</strong></li></ol><h3 id="D1-数据库（推荐）"><a href="#D1-数据库（推荐）" class="headerlink" title="D1 数据库（推荐）"></a>D1 数据库（推荐）</h3><p>D1 是 Cloudflare 的原生 SQLite 数据库，写入性能优于 KV，适合订阅条目较多的场景。</p><h4 id="创建-D1-数据库"><a href="#创建-D1-数据库" class="headerlink" title="创建 D1 数据库"></a>创建 D1 数据库</h4><p>有两种方式创建：</p><p><strong>方式一：使用 Wrangler CLI（推荐）</strong></p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 安装 wrangler（如果还没有）</span></span><br><span class="line">npm install -g wrangler</span><br><span class="line"></span><br><span class="line"><span class="comment"># 登录 Cloudflare</span></span><br><span class="line">wrangler login</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建 D1 数据库</span></span><br><span class="line">wrangler d1 create misub</span><br><span class="line"></span><br><span class="line"><span class="comment"># 初始化表结构</span></span><br><span class="line">wrangler d1 execute misub --file=schema.sql --remote</span><br></pre></td></tr></table></figure><p><strong>方式二：在 Cloudflare Dashboard 中创建</strong></p><ol><li>左侧菜单选择 <strong>Workers &amp; Pages</strong> → <strong>D1</strong></li><li>点击 <strong>Create database</strong></li><li>名称填入 <code>misub</code>，点击 <strong>Create</strong></li><li>创建完成后，进入数据库页面</li><li>点击 <strong>Console</strong>（控制台）标签页</li><li>将 <code>schema.sql</code> 中的 SQL 语句复制粘贴到控制台中执行：</li></ol><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> subscriptions (</span><br><span class="line">    id TEXT <span class="keyword">PRIMARY</span> KEY,</span><br><span class="line">    data TEXT <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">    created_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span>,</span><br><span class="line">    updated_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> profiles (</span><br><span class="line">    id TEXT <span class="keyword">PRIMARY</span> KEY,</span><br><span class="line">    data TEXT <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">    created_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span>,</span><br><span class="line">    updated_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> settings (</span><br><span class="line">    key TEXT <span class="keyword">PRIMARY</span> KEY,</span><br><span class="line">    <span class="keyword">value</span> TEXT <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">    created_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span>,</span><br><span class="line">    updated_at DATETIME <span class="keyword">DEFAULT</span> <span class="built_in">CURRENT_TIMESTAMP</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">CREATE</span> INDEX IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> idx_subscriptions_updated_at <span class="keyword">ON</span> subscriptions(updated_at);</span><br><span class="line"><span class="keyword">CREATE</span> INDEX IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> idx_profiles_updated_at <span class="keyword">ON</span> profiles(updated_at);</span><br><span class="line"><span class="keyword">CREATE</span> INDEX IF <span class="keyword">NOT</span> <span class="keyword">EXISTS</span> idx_settings_updated_at <span class="keyword">ON</span> settings(updated_at);</span><br></pre></td></tr></table></figure><h4 id="绑定-D1-到-Pages-项目"><a href="#绑定-D1-到-Pages-项目" class="headerlink" title="绑定 D1 到 Pages 项目"></a>绑定 D1 到 Pages 项目</h4><ol><li>进入你的 Pages 项目 → <strong>Settings</strong> → <strong>Functions</strong> → <strong>D1 database bindings</strong></li><li>点击 <strong>Add binding</strong></li><li>填写：<ul><li><strong>Variable name:</strong> <code>MISUB_DB</code></li><li><strong>D1 database:</strong> 选择刚才创建的 <code>misub</code></li></ul></li><li>点击 <strong>Save</strong></li></ol><hr><h2 id="设置环境变量"><a href="#设置环境变量" class="headerlink" title="设置环境变量"></a>设置环境变量</h2><p>环境变量在 Pages 项目的 <strong>Settings</strong> → <strong>Environment variables</strong> 中设置。</p><h3 id="必需的环境变量"><a href="#必需的环境变量" class="headerlink" title="必需的环境变量"></a>必需的环境变量</h3><table><thead><tr><th>变量名</th><th>说明</th><th>建议值</th></tr></thead><tbody><tr><td><code>ADMIN_PASSWORD</code></td><td>管理员登录密码</td><td>设置一个强密码，留空则默认密码为 <code>admin</code></td></tr><tr><td><code>COOKIE_SECRET</code></td><td>Session 签名密钥</td><td>生成一个随机字符串，如 <code>openssl rand -hex 32</code></td></tr></tbody></table><h3 id="推荐设置的环境变量"><a href="#推荐设置的环境变量" class="headerlink" title="推荐设置的环境变量"></a>推荐设置的环境变量</h3><table><thead><tr><th>变量名</th><th>说明</th><th>建议值</th></tr></thead><tbody><tr><td><code>MISUB_PUBLIC_URL</code></td><td>公开访问地址，用于生成订阅转换回调 URL</td><td><code>https://你的项目名.pages.dev</code></td></tr><tr><td><code>MISUB_CALLBACK_URL</code></td><td>回调 URL 基础地址，优先级高于 <code>MISUB_PUBLIC_URL</code></td><td>同上或自定义域名</td></tr><tr><td><code>CRON_SECRET</code></td><td>外部 Cron 触发器的密钥</td><td>生成一个随机字符串</td></tr><tr><td><code>CORS_ORIGINS</code></td><td>允许跨域访问的来源（逗号分隔）</td><td>一般留空</td></tr></tbody></table><h3 id="Cron-相关环境变量（可选）"><a href="#Cron-相关环境变量（可选）" class="headerlink" title="Cron 相关环境变量（可选）"></a>Cron 相关环境变量（可选）</h3><table><thead><tr><th>变量名</th><th>默认值</th><th>说明</th></tr></thead><tbody><tr><td><code>ENVIRONMENT</code></td><td><code>production</code></td><td>运行环境标识</td></tr><tr><td><code>ENABLE_CRON</code></td><td><code>true</code></td><td>是否启用 Cron 定时同步</td></tr><tr><td><code>CRON_TYPE</code></td><td><code>hourly-subscription-sync</code></td><td>Cron 任务类型</td></tr><tr><td><code>CRON_MAX_SYNC_COUNT</code></td><td><code>50</code></td><td>每次 Cron 最多同步的订阅数</td></tr><tr><td><code>CRON_SYNC_TIMEOUT</code></td><td><code>30000</code></td><td>单个订阅同步超时时间（毫秒）</td></tr><tr><td><code>CRON_ENABLE_PARALLEL</code></td><td><code>true</code></td><td>是否启用并行同步</td></tr></tbody></table><h3 id="设置步骤"><a href="#设置步骤" class="headerlink" title="设置步骤"></a>设置步骤</h3><ol><li>进入 Pages 项目 → <strong>Settings</strong> → <strong>Environment variables</strong></li><li>在 <strong>Production</strong> 标签下，点击 <strong>Add variable</strong></li><li>逐个添加上述变量名和值</li><li>添加完成后，点击 <strong>Save</strong></li></ol><blockquote><p><strong>注意：</strong> 修改环境变量后，需要<strong>重新部署</strong>才能生效。可以在 Pages 项目页面点击 <strong>Deployments</strong> → <strong>Deploy latest commit</strong> 来触发重新部署。</p></blockquote><hr><h2 id="配置-Cron-定时任务"><a href="#配置-Cron-定时任务" class="headerlink" title="配置 Cron 定时任务"></a>配置 Cron 定时任务</h2><p>Cron 触发器可以让 MiSub 定时自动同步订阅内容，保持节点数据最新。</p><h3 id="方式一：Cloudflare-Cron-Triggers（推荐，需付费计划）"><a href="#方式一：Cloudflare-Cron-Triggers（推荐，需付费计划）" class="headerlink" title="方式一：Cloudflare Cron Triggers（推荐，需付费计划）"></a>方式一：Cloudflare Cron Triggers（推荐，需付费计划）</h3><p>Cloudflare Pages 的 Cron Triggers 功能需要 <strong>Paid Plan</strong>（Workers Paid 计划）。</p><ol><li>进入 Pages 项目 → <strong>Settings</strong> → <strong>Functions</strong> → <strong>Cron Triggers</strong></li><li>点击 <strong>Add Cron Trigger</strong></li><li>输入 Cron 表达式：<ul><li><code>0 * * * *</code> — 每小时同步一次（推荐）</li><li><code>*/30 * * * *</code> — 每 30 分钟同步一次</li><li><code>0 8 * * *</code> — 每天早上 8 点同步一次</li></ul></li><li>点击 <strong>Save</strong></li></ol><h3 id="方式二：外部-Cron-服务（免费）"><a href="#方式二：外部-Cron-服务（免费）" class="headerlink" title="方式二：外部 Cron 服务（免费）"></a>方式二：外部 Cron 服务（免费）</h3><p>如果不想升级到付费计划，可以使用免费的第三方 Cron 服务来触发同步：</p><p><strong>支持的触发方式：</strong></p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">GET https://你的项目.pages.dev/cron?secret=你的CRON_SECRET</span><br></pre></td></tr></table></figure><p>或带 Bearer Token 的请求：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -H <span class="string">&quot;Authorization: Bearer 你的CRON_SECRET&quot;</span> https://你的项目.pages.dev/cron</span><br></pre></td></tr></table></figure><p><strong>推荐的外部 Cron 服务：</strong></p><ul><li><a href="https://uptimerobot.com/">UptimeRobot</a> — 免费计划支持 5 分钟间隔的监控&#x2F;请求</li><li><a href="https://cron-job.org/">Cron-Job.org</a> — 免费计划支持每分钟执行</li><li><a href="https://www.easycron.com/">EasyCron</a> — 免费计划支持一定数量的定时任务</li></ul><hr><h2 id="完成部署与登录"><a href="#完成部署与登录" class="headerlink" title="完成部署与登录"></a>完成部署与登录</h2><p>所有配置完成后，访问你的 Pages 项目地址（如 <code>https://misub.pages.dev</code>）：</p><ol><li><p>页面会自动跳转到登录页 <code>/login</code></p></li><li><p>使用你设置的管理员密码登录（默认密码为 <code>admin</code>）</p></li><li><p>登录后进入仪表盘，即可开始配置：</p><ul><li><strong>订阅管理</strong> — 添加你的机场订阅链接</li><li><strong>手动节点</strong> — 添加手动搭建的节点</li><li><strong>场景配置</strong> — 组合订阅源和节点分组，生成订阅配置</li><li><strong>算子链</strong> — 配置节点过滤、重命名、排序规则</li><li><strong>系统设置</strong> — 配置公开页、回调地址、Telegram 通知等</li></ul></li></ol><h2 id="绑定自定义域名（可选）"><a href="#绑定自定义域名（可选）" class="headerlink" title="绑定自定义域名（可选）"></a>绑定自定义域名（可选）</h2><p>如果你有自己的域名，可以将它绑定到 Cloudflare Pages：</p><ol><li>在 Cloudflare Dashboard 中将你的域名接入 Cloudflare（DNS 托管）</li><li>进入 Pages 项目 → <strong>Custom domains</strong> → <strong>Set up a custom domain</strong></li><li>输入你的域名（如 <code>misub.example.com</code>）</li><li>Cloudflare 会自动添加 DNS 记录并下发 SSL 证书</li><li>等待证书生效（通常 1-2 分钟）</li><li>将 <code>MISUB_PUBLIC_URL</code> 环境变量更新为你的自定义域名</li><li>重新部署</li></ol><hr><h2 id="本地开发（选读）"><a href="#本地开发（选读）" class="headerlink" title="本地开发（选读）"></a>本地开发（选读）</h2><p>如果你想在本地开发和调试 MiSub，可以按以下步骤操作。</p><h3 id="环境要求"><a href="#环境要求" class="headerlink" title="环境要求"></a>环境要求</h3><ul><li>Node.js 20 或更高版本</li><li>npm 或 pnpm</li></ul><h3 id="安装依赖"><a href="#安装依赖" class="headerlink" title="安装依赖"></a>安装依赖</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/imzyb/MiSub.git</span><br><span class="line"><span class="built_in">cd</span> MiSub</span><br><span class="line">npm install</span><br></pre></td></tr></table></figure><h3 id="配置本地环境变量"><a href="#配置本地环境变量" class="headerlink" title="配置本地环境变量"></a>配置本地环境变量</h3><p>在项目根目录创建 <code>.dev.vars</code> 文件：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">ADMIN_PASSWORD=admin123</span><br><span class="line">JWT_SECRET=supersecretkey123</span><br><span class="line">COOKIE_SECRET=supersecretkey123</span><br></pre></td></tr></table></figure><h3 id="启动开发服务器"><a href="#启动开发服务器" class="headerlink" title="启动开发服务器"></a>启动开发服务器</h3><p>需要同时启动两个终端：</p><p><strong>终端 1 — 后端（Cloudflare Pages Functions）：</strong></p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm run dev:server -- --ip 0.0.0.0 --kv MISUB_KV --persist-to .wrangler/state-local</span><br></pre></td></tr></table></figure><p>后端将在 <code>http://localhost:8787</code> 运行。</p><p><strong>终端 2 — 前端（Vite 开发服务器）：</strong></p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm run dev</span><br></pre></td></tr></table></figure><p>前端将在 <code>http://localhost:5173</code> 运行，Vite 会自动将 <code>/api</code> 和 <code>/sub/</code> 路径的请求代理到后端。</p><h3 id="生产构建预览"><a href="#生产构建预览" class="headerlink" title="生产构建预览"></a>生产构建预览</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm run build     <span class="comment"># 构建生产版本到 dist/</span></span><br><span class="line">npm run preview   <span class="comment"># 本地预览生产构建</span></span><br></pre></td></tr></table></figure><h3 id="运行测试"><a href="#运行测试" class="headerlink" title="运行测试"></a>运行测试</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm <span class="built_in">test</span> -- --run        <span class="comment"># 运行所有测试</span></span><br><span class="line">npm run <span class="built_in">test</span>:coverage    <span class="comment"># 运行测试并生成覆盖率报告</span></span><br></pre></td></tr></table></figure><hr><h2 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h2><h3 id="Q1：部署完成后访问页面空白或报错？"><a href="#Q1：部署完成后访问页面空白或报错？" class="headerlink" title="Q1：部署完成后访问页面空白或报错？"></a>Q1：部署完成后访问页面空白或报错？</h3><ul><li>确认 <strong>KV 命名空间绑定</strong> 已正确配置，变量名必须是 <code>MISUB_KV</code></li><li>检查 <strong>环境变量</strong> 是否已保存并重新部署</li><li>查看 Cloudflare Pages 的 <strong>Functions 日志</strong> 排查错误</li></ul><h3 id="Q2：如何更新到最新版本？"><a href="#Q2：如何更新到最新版本？" class="headerlink" title="Q2：如何更新到最新版本？"></a>Q2：如何更新到最新版本？</h3><p>如果你的部署是连接 Git 仓库的方式，只需在 Fork 的仓库中同步上游代码：</p><ol><li>在 GitHub 上同步 upstream 的最新代码</li><li>Cloudflare Pages 会自动检测到新的提交并重新部署</li><li>也可以在 Pages 项目页面手动点击 <strong>Deploy latest commit</strong></li></ol><p>也可以配置 GitHub Actions 自动同步上游（项目已自带 <code>fork-sync.yml</code> 工作流）。</p><h3 id="Q3：KV-和-D1-应该选哪个？"><a href="#Q3：KV-和-D1-应该选哪个？" class="headerlink" title="Q3：KV 和 D1 应该选哪个？"></a>Q3：KV 和 D1 应该选哪个？</h3><table><thead><tr><th>对比项</th><th>KV</th><th>D1</th></tr></thead><tbody><tr><td>写入性能</td><td>一般（最终一致性）</td><td>较高（强一致性）</td></tr><tr><td>查询能力</td><td>按键查询</td><td>完整 SQL 查询</td></tr><tr><td>免费额度</td><td>每天 1000 次写入</td><td>每月 500 万行读取</td></tr><tr><td>推荐场景</td><td>订阅少、使用频率低</td><td>订阅多、频繁刷新</td></tr></tbody></table><blockquote><p><strong>建议：</strong> 大多数用户同时绑定 KV 和 D1。MiSub 会优先使用 D1，D1 不可用时回退到 KV。</p></blockquote><h3 id="Q4：订阅链接无法获取节点？"><a href="#Q4：订阅链接无法获取节点？" class="headerlink" title="Q4：订阅链接无法获取节点？"></a>Q4：订阅链接无法获取节点？</h3><ul><li>检查网络环境，上游订阅链接是否可访问</li><li>可在系统设置中配置 <strong>外部抓取代理</strong>（Vercel Fetch Proxy）来解决网络限制问题</li><li>查看操作日志中的详细错误信息</li></ul><h3 id="Q5：如何导入外部订阅转换器？"><a href="#Q5：如何导入外部订阅转换器？" class="headerlink" title="Q5：如何导入外部订阅转换器？"></a>Q5：如何导入外部订阅转换器？</h3><p>MiSub 支持对接 subconverter 或 FatSheep 等外部转换后端，在 <strong>系统设置</strong> → <strong>订阅设置</strong> 中配置外部转换器地址即可。</p><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>MiSub 的部署流程可以概括为以下几步：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">Fork 仓库 → Cloudflare Pages 连接 Git → 创建 KV 绑定</span><br><span class="line">→ （可选）创建 D1 数据库并初始化 → 设置环境变量</span><br><span class="line">→ （可选）配置 Cron 触发器 → 重新部署 → 登录使用</span><br></pre></td></tr></table></figure><p>整个部署过程在 Cloudflare 免费计划内即可完成，不需要购买任何付费服务。部署完成后，你就能拥有一个功能完整的私有订阅管理面板，随时随地管理你的代理节点和订阅配置。</p><p>如果你在部署过程中遇到任何问题，欢迎在项目 <a href="https://github.com/imzyb/MiSub/issues">GitHub Issues</a> 中提出。</p><hr><p><em>本文档最后更新于 2026 年 6 月，对应 MiSub v2.7.0 版本。</em></p>]]>
    </content>
    <id>https://sam.xx.kg/post/MiSub%E9%83%A8%E7%BD%B2%E6%95%99%E7%A8%8B/</id>
    <link href="https://sam.xx.kg/post/MiSub%E9%83%A8%E7%BD%B2%E6%95%99%E7%A8%8B/"/>
    <published>2026-06-29T13:19:16.000Z</published>
    <summary>MiSub 是一款部署在 Cloudflare Pages 上的轻量级代理订阅管理面板，本文详细介绍了从 Fork 仓库到完成部署的完整流程。</summary>
    <title>MiSub 部署教程 — 轻量级代理订阅管理面板</title>
    <updated>2026-06-30T03:30:02.749Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="代理与网络" scheme="https://sam.xx.kg/categories/%E4%BB%A3%E7%90%86%E4%B8%8E%E7%BD%91%E7%BB%9C/"/>
    <category term="代理" scheme="https://sam.xx.kg/tags/%E4%BB%A3%E7%90%86/"/>
    <category term="Docker" scheme="https://sam.xx.kg/tags/Docker/"/>
    <category term="Linux" scheme="https://sam.xx.kg/tags/Linux/"/>
    <category term="Mihomo" scheme="https://sam.xx.kg/tags/Mihomo/"/>
    <content>
      <![CDATA[<blockquote><p>本文介绍如何在 Debian 虚拟机上使用 Docker 和 macvlan 网络部署 <strong>Mihomo</strong>（原 Clash Meta）透明代理网关，让局域网内所有设备无需任何配置即可自动使用代理。</p></blockquote><h2 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h2><h3 id="创建-Debian-虚拟机"><a href="#创建-Debian-虚拟机" class="headerlink" title="创建 Debian 虚拟机"></a>创建 Debian 虚拟机</h3><p>在 Proxmox VE 上一键创建 Debian 虚拟机：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash -c <span class="string">&quot;<span class="subst">$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/debian-vm.sh)</span>&quot;</span></span><br></pre></td></tr></table></figure><p>推荐使用 Debian，因为它轻量、稳定、易用。</p><h3 id="启用-SSH-远程管理"><a href="#启用-SSH-远程管理" class="headerlink" title="启用 SSH 远程管理"></a>启用 SSH 远程管理</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 安装 SSH 服务</span></span><br><span class="line">apt install -y openssh-server</span><br><span class="line">systemctl <span class="built_in">enable</span> ssh</span><br><span class="line">systemctl start ssh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装编辑器</span></span><br><span class="line">apt install -y vim</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改 SSH 配置</span></span><br><span class="line">vim /etc/ssh/sshd_config</span><br></pre></td></tr></table></figure><p>修改以下参数：</p><ul><li><code>PermitRootLogin</code> → <code>yes</code></li><li><code>PasswordAuthentication</code> → <code>yes</code></li></ul><p>重启 SSH 服务并设置 root 密码：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">systemctl restart ssh</span><br><span class="line">passwd root</span><br></pre></td></tr></table></figure><h3 id="安装-Docker"><a href="#安装-Docker" class="headerlink" title="安装 Docker"></a>安装 Docker</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">apt update &amp;&amp; apt install -y docker.io</span><br><span class="line">systemctl <span class="built_in">enable</span> docker</span><br></pre></td></tr></table></figure><hr><h2 id="网络配置"><a href="#网络配置" class="headerlink" title="网络配置"></a>网络配置</h2><h3 id="查看网卡信息"><a href="#查看网卡信息" class="headerlink" title="查看网卡信息"></a>查看网卡信息</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ip addr</span><br></pre></td></tr></table></figure><p>记录主网卡名称（如 <code>enp0s18</code>）。</p><h3 id="设置网卡混杂模式"><a href="#设置网卡混杂模式" class="headerlink" title="设置网卡混杂模式"></a>设置网卡混杂模式</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ip <span class="built_in">link</span> <span class="built_in">set</span> enp0s18 promisc on</span><br></pre></td></tr></table></figure><blockquote><p>持久化配置需将上述命令写入 <code>/etc/rc.local</code>。</p></blockquote><h3 id="创建-macvlan-网络"><a href="#创建-macvlan-网络" class="headerlink" title="创建 macvlan 网络"></a>创建 macvlan 网络</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker network create -d macvlan \</span><br><span class="line">  --subnet=192.168.88.0/24 \</span><br><span class="line">  --gateway=192.168.88.1 \</span><br><span class="line">  -o parent=enp0s18 \</span><br><span class="line">  opnet</span><br></pre></td></tr></table></figure><p>参数说明：</p><table><thead><tr><th>参数</th><th>说明</th></tr></thead><tbody><tr><td><code>--subnet</code></td><td>局域网网段，与你的主路由一致</td></tr><tr><td><code>--gateway</code></td><td>网关 IP，即主路由 IP</td></tr><tr><td><code>-o parent</code></td><td>物理网卡名称</td></tr><tr><td><code>opnet</code></td><td>自定义 Docker 网络名称</td></tr></tbody></table><hr><h2 id="部署-Mihomo"><a href="#部署-Mihomo" class="headerlink" title="部署 Mihomo"></a>部署 Mihomo</h2><h3 id="准备配置文件"><a href="#准备配置文件" class="headerlink" title="准备配置文件"></a>准备配置文件</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">mkdir</span> -p /etc/mihomo</span><br></pre></td></tr></table></figure><p>准备 <code>config.yaml</code> 配置文件，放置到 <code>/etc/mihomo/</code> 目录下：</p><ul><li><strong>机场用户</strong>：替换为机场提供的订阅配置，或使用订阅转换工具生成</li><li><strong>自建 VPS 用户</strong>：配置代理节点信息（地址、端口、密码、加密方式等）</li></ul><p>可通过 SFTP 工具上传配置文件到 <code>/etc/mihomo/</code>。</p><h3 id="启动-Mihomo-容器"><a href="#启动-Mihomo-容器" class="headerlink" title="启动 Mihomo 容器"></a>启动 Mihomo 容器</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">docker run -d --privileged \</span><br><span class="line">  --name=mihomo \</span><br><span class="line">  --restart=always \</span><br><span class="line">  --network opnet \</span><br><span class="line">  --ip 192.168.88.10 \</span><br><span class="line">  -v /etc/mihomo:/root/.config/mihomo/ \</span><br><span class="line">  metacubex/mihomo:latest</span><br></pre></td></tr></table></figure><p>参数说明：</p><table><thead><tr><th>参数</th><th>说明</th></tr></thead><tbody><tr><td><code>--privileged</code></td><td>需要特权模式以修改网络</td></tr><tr><td><code>--name</code></td><td>容器名称</td></tr><tr><td><code>--network opnet</code></td><td>连接到刚创建的 macvlan 网络</td></tr><tr><td><code>--ip</code></td><td>分配给 Mihomo 的固定 IP</td></tr><tr><td><code>-v</code></td><td>挂载配置目录</td></tr></tbody></table><hr><h2 id="客户端配置"><a href="#客户端配置" class="headerlink" title="客户端配置"></a>客户端配置</h2><h3 id="设置-DNS"><a href="#设置-DNS" class="headerlink" title="设置 DNS"></a>设置 DNS</h3><p>将局域网设备的 DNS 服务器设置为 Mihomo 容器的 IP（<code>192.168.88.10</code>）：</p><ul><li><strong>路由器 DHCP 设置</strong>：在 DHCP 选项中设置 DNS 为 <code>192.168.88.10</code></li><li><strong>手动设置</strong>：在设备网络设置中修改 DNS</li></ul><h3 id="设置路由"><a href="#设置路由" class="headerlink" title="设置路由"></a>设置路由</h3><p>Mihomo 的 TUN 模式会处理 <code>198.18.0.0/16</code> 网段的流量路由，确保数据包正确转发到 Mihomo 进程。</p><hr><h2 id="验证部署"><a href="#验证部署" class="headerlink" title="验证部署"></a>验证部署</h2><ol><li>检查容器运行状态：<code>docker ps | grep mihomo</code></li><li>查看实时日志：<code>docker logs -f mihomo</code></li><li>在局域网设备上访问 <code>http://192.168.88.10:9090</code>（默认面板端口），确认 Mihomo 控制面板可访问</li><li>访问 <a href="https://ip.sb/">ip.sb</a> 检查出口 IP 是否已变更</li></ol><hr><h2 id="视频教程"><a href="#视频教程" class="headerlink" title="视频教程"></a>视频教程</h2><iframe src="//player.bilibili.com/player.html" width="100%" height="400" frameborder="no" scrolling="no" allowfullscreen="true"></iframe>]]>
    </content>
    <id>https://sam.xx.kg/post/%E7%94%A8Mihomo%E6%89%93%E9%80%A0%E6%9C%80%E5%BC%BA%E4%BB%A3%E7%90%86%E6%9C%BA/</id>
    <link href="https://sam.xx.kg/post/%E7%94%A8Mihomo%E6%89%93%E9%80%A0%E6%9C%80%E5%BC%BA%E4%BB%A3%E7%90%86%E6%9C%BA/"/>
    <published>2025-05-22T12:55:59.000Z</published>
    <summary>使用 Docker + macvlan 部署 Mihomo 透明代理网关，实现局域网设备无缝科学上网。</summary>
    <title>在 Linux 上用 Mihomo 打造透明代理网关</title>
    <updated>2026-06-29T17:24:16.495Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="服务器运维" scheme="https://sam.xx.kg/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/"/>
    <category term="VPS" scheme="https://sam.xx.kg/tags/VPS/"/>
    <category term="Linux" scheme="https://sam.xx.kg/tags/Linux/"/>
    <category term="脚本" scheme="https://sam.xx.kg/tags/%E8%84%9A%E6%9C%AC/"/>
    <category term="运维" scheme="https://sam.xx.kg/tags/%E8%BF%90%E7%BB%B4/"/>
    <content>
      <![CDATA[<blockquote><p>整理自日常 VPS 运维中的常用脚本，涵盖系统重装、性能测试、网络测速、流媒体检测、环境安装等场景。持续更新中。</p></blockquote><hr><h2 id="一、系统重装"><a href="#一、系统重装" class="headerlink" title="一、系统重装"></a>一、系统重装</h2><h3 id="史上最强-DD-脚本（推荐）"><a href="#史上最强-DD-脚本（推荐）" class="headerlink" title="史上最强 DD 脚本（推荐）"></a>史上最强 DD 脚本（推荐）</h3><p>支持重装多种 Linux 发行版和 Windows，功能最全面：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget --no-check-certificate -qO InstallNET.sh <span class="string">&#x27;https://raw.githubusercontent.com/leitbogioro/Tools/master/Linux_reinstall/InstallNET.sh&#x27;</span> \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> a+x InstallNET.sh \</span><br><span class="line">  &amp;&amp; bash InstallNET.sh -debian 12 -<span class="built_in">pwd</span> <span class="string">&#x27;password&#x27;</span></span><br></pre></td></tr></table></figure><h3 id="萌咖-DD-脚本"><a href="#萌咖-DD-脚本" class="headerlink" title="萌咖 DD 脚本"></a>萌咖 DD 脚本</h3><p>经典脚本，稳定可靠：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(wget --no-check-certificate -qO- <span class="string">&#x27;https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh&#x27;</span>) \</span><br><span class="line">  -d 11 -v 64 -p 密码 -port 端口 -a -firmware</span><br></pre></td></tr></table></figure><h3 id="beta-gs-DD-脚本"><a href="#beta-gs-DD-脚本" class="headerlink" title="beta.gs DD 脚本"></a>beta.gs DD 脚本</h3><p>交互式菜单，可视化操作：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget --no-check-certificate -O NewReinstall.sh \</span><br><span class="line">  https://raw.githubusercontent.com/fcurrk/reinstall/master/NewReinstall.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> a+x NewReinstall.sh &amp;&amp; bash NewReinstall.sh</span><br></pre></td></tr></table></figure><h3 id="DD-Windows-系统"><a href="#DD-Windows-系统" class="headerlink" title="DD Windows 系统"></a>DD Windows 系统</h3><p>使用最强 DD 脚本安装 Windows：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sSL https://raw.githubusercontent.com/leitbogioro/Tools/master/Linux_reinstall/InstallNET.sh) \</span><br><span class="line">  -windows 10 -lang <span class="string">&quot;cn&quot;</span></span><br></pre></td></tr></table></figure><blockquote><p>默认账户：<code>Administrator</code>，密码：<code>Teddysun.com</code></p></blockquote><hr><h2 id="二、综合性能测试"><a href="#二、综合性能测试" class="headerlink" title="二、综合性能测试"></a>二、综合性能测试</h2><h3 id="LemonBench（快速版）"><a href="#LemonBench（快速版）" class="headerlink" title="LemonBench（快速版）"></a>LemonBench（快速版）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -qO- https://raw.githubusercontent.com/LemonBench/LemonBench/main/LemonBench.sh | bash -s -- --fast</span><br></pre></td></tr></table></figure><h3 id="融合怪（推荐）"><a href="#融合怪（推荐）" class="headerlink" title="融合怪（推荐）"></a>融合怪（推荐）</h3><p>功能全面，包含 CPU、内存、磁盘、网络、流媒体等：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(wget -qO- --no-check-certificate https://gitlab.com/spiritysdx/za/-/raw/main/ecs.sh)</span><br></pre></td></tr></table></figure><h3 id="NodeBench"><a href="#NodeBench" class="headerlink" title="NodeBench"></a>NodeBench</h3><p>轻量快速测试：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sL https://raw.githubusercontent.com/LloydAsp/NodeBench/main/NodeBench.sh)</span><br></pre></td></tr></table></figure><h3 id="YABS（Yet-Another-Bench-Script）"><a href="#YABS（Yet-Another-Bench-Script）" class="headerlink" title="YABS（Yet Another Bench Script）"></a>YABS（Yet Another Bench Script）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 标准测试</span></span><br><span class="line">curl -sL yabs.sh | bash</span><br><span class="line"></span><br><span class="line"><span class="comment"># 使用 Geekbench 5 测试</span></span><br><span class="line">curl -sL yabs.sh | bash -s -- -5</span><br></pre></td></tr></table></figure><h3 id="GB5-专项测试"><a href="#GB5-专项测试" class="headerlink" title="GB5 专项测试"></a>GB5 专项测试</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sL bash.icu/gb5)</span><br></pre></td></tr></table></figure><hr><h2 id="三、流媒体及-IP-质量检测"><a href="#三、流媒体及-IP-质量检测" class="headerlink" title="三、流媒体及 IP 质量检测"></a>三、流媒体及 IP 质量检测</h2><h3 id="流媒体解锁检测"><a href="#流媒体解锁检测" class="headerlink" title="流媒体解锁检测"></a>流媒体解锁检测</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 最常用版本</span></span><br><span class="line">bash &lt;(curl -L -s check.unlock.media)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 原生检测脚本</span></span><br><span class="line">bash &lt;(curl -sL Media.Check.Place)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 准确度最高（RegionRestrictionCheck）</span></span><br><span class="line">bash &lt;(curl -L -s https://github.com/1-stream/RegionRestrictionCheck/raw/main/check.sh)</span><br></pre></td></tr></table></figure><h3 id="IP-质量体检"><a href="#IP-质量体检" class="headerlink" title="IP 质量体检"></a>IP 质量体检</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sL IP.Check.Place)</span><br></pre></td></tr></table></figure><hr><h2 id="四、网络测速"><a href="#四、网络测速" class="headerlink" title="四、网络测速"></a>四、网络测速</h2><h3 id="Speedtest"><a href="#Speedtest" class="headerlink" title="Speedtest"></a>Speedtest</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sL bash.icu/speedtest)</span><br></pre></td></tr></table></figure><h3 id="Taier"><a href="#Taier" class="headerlink" title="Taier"></a>Taier</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -sL res.yserver.ink/taier.sh)</span><br></pre></td></tr></table></figure><h3 id="Hyperspeed"><a href="#Hyperspeed" class="headerlink" title="Hyperspeed"></a>Hyperspeed</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -Lso- https://bench.im/hyperspeed | bash</span><br></pre></td></tr></table></figure><h3 id="全球测速"><a href="#全球测速" class="headerlink" title="全球测速"></a>全球测速</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -sL network-speed.xyz | bash</span><br></pre></td></tr></table></figure><hr><h2 id="五、路由回程测试"><a href="#五、路由回程测试" class="headerlink" title="五、路由回程测试"></a>五、路由回程测试</h2><h3 id="一键回程测试（小白友好）"><a href="#一键回程测试（小白友好）" class="headerlink" title="一键回程测试（小白友好）"></a>一键回程测试（小白友好）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl https://raw.githubusercontent.com/ludashi2020/backtrace/main/install.sh -sSf | sh</span><br></pre></td></tr></table></figure><h3 id="详细回程测试"><a href="#详细回程测试" class="headerlink" title="详细回程测试"></a>详细回程测试</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -N --no-check-certificate https://raw.githubusercontent.com/Chennhaoo/Shell_Bash/master/AutoTrace.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x AutoTrace.sh &amp;&amp; bash AutoTrace.sh</span><br></pre></td></tr></table></figure><h3 id="北京电信回程测试"><a href="#北京电信回程测试" class="headerlink" title="北京电信回程测试"></a>北京电信回程测试</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget https://ghproxy.com/https://raw.githubusercontent.com/vpsxb/testrace/main/testrace.sh \</span><br><span class="line">  -O testrace.sh &amp;&amp; bash testrace.sh</span><br></pre></td></tr></table></figure><hr><h2 id="六、系统优化脚本"><a href="#六、系统优化脚本" class="headerlink" title="六、系统优化脚本"></a>六、系统优化脚本</h2><h3 id="添加-SWAP"><a href="#添加-SWAP" class="headerlink" title="添加 SWAP"></a>添加 SWAP</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget https://www.moerats.com/usr/shell/swap.sh &amp;&amp; bash swap.sh</span><br></pre></td></tr></table></figure><h3 id="Fail2ban-安装（防暴力破解）"><a href="#Fail2ban-安装（防暴力破解）" class="headerlink" title="Fail2ban 安装（防暴力破解）"></a>Fail2ban 安装（防暴力破解）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget --no-check-certificate https://raw.githubusercontent.com/FunctionClub/Fail2ban/master/fail2ban.sh \</span><br><span class="line">  &amp;&amp; bash fail2ban.sh 2&gt;&amp;1 | <span class="built_in">tee</span> fail2ban.log</span><br></pre></td></tr></table></figure><h3 id="一键开启-BBR（适用于较新内核）"><a href="#一键开启-BBR（适用于较新内核）" class="headerlink" title="一键开启 BBR（适用于较新内核）"></a>一键开启 BBR（适用于较新内核）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&quot;net.core.default_qdisc=fq&quot;</span> &gt;&gt; /etc/sysctl.conf</span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;net.ipv4.tcp_congestion_control=bbr&quot;</span> &gt;&gt; /etc/sysctl.conf</span><br><span class="line">sysctl -p</span><br><span class="line">sysctl net.ipv4.tcp_available_congestion_control</span><br><span class="line">lsmod | grep bbr</span><br></pre></td></tr></table></figure><h3 id="多功能-BBR-安装脚本"><a href="#多功能-BBR-安装脚本" class="headerlink" title="多功能 BBR 安装脚本"></a>多功能 BBR 安装脚本</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -N --no-check-certificate <span class="string">&quot;https://gist.githubusercontent.com/zeruns/a0ec603f20d1b86de6a774a8ba27588f/raw/4f9957ae23f5efb2bb7c57a198ae2cffebfb1c56/tcp.sh&quot;</span> \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x tcp.sh &amp;&amp; ./tcp.sh</span><br></pre></td></tr></table></figure><h3 id="锐速-BBRPLUS-BBR2-BBR3-一键脚本"><a href="#锐速-BBRPLUS-BBR2-BBR3-一键脚本" class="headerlink" title="锐速 &#x2F; BBRPLUS &#x2F; BBR2 &#x2F; BBR3 一键脚本"></a>锐速 &#x2F; BBRPLUS &#x2F; BBR2 &#x2F; BBR3 一键脚本</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -O tcpx.sh <span class="string">&quot;https://github.com/ylx2016/Linux-NetSpeed/raw/master/tcpx.sh&quot;</span> \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x tcpx.sh &amp;&amp; ./tcpx.sh</span><br></pre></td></tr></table></figure><h3 id="TCP-窗口调优"><a href="#TCP-窗口调优" class="headerlink" title="TCP 窗口调优"></a>TCP 窗口调优</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget http://sh.nekoneko.cloud/tools.sh -O tools.sh &amp;&amp; bash tools.sh</span><br></pre></td></tr></table></figure><h3 id="25-端口开放测试"><a href="#25-端口开放测试" class="headerlink" title="25 端口开放测试"></a>25 端口开放测试</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">telnet smtp.aol.com 25</span><br></pre></td></tr></table></figure><hr><h2 id="七、环境及软件一键安装"><a href="#七、环境及软件一键安装" class="headerlink" title="七、环境及软件一键安装"></a>七、环境及软件一键安装</h2><h3 id="Docker"><a href="#Docker" class="headerlink" title="Docker"></a>Docker</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -sSL https://get.daocloud.io/docker | sh</span><br></pre></td></tr></table></figure><h3 id="Python"><a href="#Python" class="headerlink" title="Python"></a>Python</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -O https://raw.githubusercontent.com/lx969788249/lxspacepy/master/pyinstall.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x pyinstall.sh &amp;&amp; ./pyinstall.sh</span><br></pre></td></tr></table></figure><h3 id="iperf3（带宽测试工具）"><a href="#iperf3（带宽测试工具）" class="headerlink" title="iperf3（带宽测试工具）"></a>iperf3（带宽测试工具）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">apt install iperf3</span><br></pre></td></tr></table></figure><h3 id="Realm（流量转发）"><a href="#Realm（流量转发）" class="headerlink" title="Realm（流量转发）"></a>Realm（流量转发）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -L https://raw.githubusercontent.com/zhouh047/realm-oneclick-install/main/realm.sh) -i</span><br></pre></td></tr></table></figure><h3 id="Gost（隧道代理）"><a href="#Gost（隧道代理）" class="headerlink" title="Gost（隧道代理）"></a>Gost（隧道代理）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget --no-check-certificate -O gost.sh https://raw.githubusercontent.com/qqrrooty/EZgost/main/gost.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x gost.sh &amp;&amp; ./gost.sh</span><br></pre></td></tr></table></figure><h3 id="极光面板（Aurora-Panel）"><a href="#极光面板（Aurora-Panel）" class="headerlink" title="极光面板（Aurora Panel）"></a>极光面板（Aurora Panel）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(curl -fsSL https://raw.githubusercontent.com/Aurora-Admin-Panel/deploy/main/install.sh)</span><br></pre></td></tr></table></figure><h3 id="哪吒监控"><a href="#哪吒监控" class="headerlink" title="哪吒监控"></a>哪吒监控</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x nezha.sh &amp;&amp; <span class="built_in">sudo</span> ./nezha.sh</span><br></pre></td></tr></table></figure><h3 id="Cloudflare-WARP"><a href="#Cloudflare-WARP" class="headerlink" title="Cloudflare WARP"></a>Cloudflare WARP</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -N https://gitlab.com/fscarmen/warp/-/raw/main/menu.sh &amp;&amp; bash menu.sh</span><br></pre></td></tr></table></figure><h3 id="Aria2（下载工具）"><a href="#Aria2（下载工具）" class="headerlink" title="Aria2（下载工具）"></a>Aria2（下载工具）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -N git.io/aria2.sh &amp;&amp; <span class="built_in">chmod</span> +x aria2.sh &amp;&amp; ./aria2.sh</span><br></pre></td></tr></table></figure><h3 id="宝塔面板（国产运维面板）"><a href="#宝塔面板（国产运维面板）" class="headerlink" title="宝塔面板（国产运维面板）"></a>宝塔面板（国产运维面板）</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -O install.sh http://v7.hostcli.com/install/install-ubuntu_6.0.sh &amp;&amp; <span class="built_in">sudo</span> bash install.sh</span><br></pre></td></tr></table></figure><h3 id="PVE-虚拟化一键安装"><a href="#PVE-虚拟化一键安装" class="headerlink" title="PVE 虚拟化一键安装"></a>PVE 虚拟化一键安装</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">bash &lt;(wget -qO- --no-check-certificate https://raw.githubusercontent.com/oneclickvirt/pve/main/scripts/build_backend.sh)</span><br></pre></td></tr></table></figure><hr><h2 id="八、综合工具箱"><a href="#八、综合工具箱" class="headerlink" title="八、综合工具箱"></a>八、综合工具箱</h2><h3 id="科技-lion-脚本"><a href="#科技-lion-脚本" class="headerlink" title="科技 lion 脚本"></a>科技 lion 脚本</h3><p>多功能 Linux 运维工具箱：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">curl -sS -O https://kejilion.pro/kejilion.sh &amp;&amp; <span class="built_in">chmod</span> +x kejilion.sh &amp;&amp; ./kejilion.sh</span><br></pre></td></tr></table></figure><h3 id="SKY-BOX"><a href="#SKY-BOX" class="headerlink" title="SKY-BOX"></a>SKY-BOX</h3><p>蓝眼云工具箱，功能丰富：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget -O box.sh https://raw.githubusercontent.com/BlueSkyXN/SKY-BOX/main/box.sh \</span><br><span class="line">  &amp;&amp; <span class="built_in">chmod</span> +x box.sh &amp;&amp; clear &amp;&amp; ./box.sh</span><br></pre></td></tr></table></figure><hr><blockquote><p>大部分脚本整理自网络，在此感谢各位大佬的贡献。本贴会持续更新和补充实用脚本。</p></blockquote>]]>
    </content>
    <id>https://sam.xx.kg/post/%E5%B8%B8%E7%94%A8VPS%E8%84%9A%E6%9C%AC/</id>
    <link href="https://sam.xx.kg/post/%E5%B8%B8%E7%94%A8VPS%E8%84%9A%E6%9C%AC/"/>
    <published>2024-10-27T14:13:16.000Z</published>
    <summary>整理日常 VPS 运维中最常用的脚本，涵盖系统重装、性能测试、网络测速、环境安装等场景。</summary>
    <title>常用 VPS 脚本合集</title>
    <updated>2026-06-29T17:24:09.815Z</updated>
  </entry>
  <entry>
    <author>
      <name>Sam</name>
    </author>
    <category term="服务器运维" scheme="https://sam.xx.kg/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%90%E7%BB%B4/"/>
    <category term="PVE" scheme="https://sam.xx.kg/tags/PVE/"/>
    <category term="N100" scheme="https://sam.xx.kg/tags/N100/"/>
    <category term="SR-IOV" scheme="https://sam.xx.kg/tags/SR-IOV/"/>
    <category term="虚拟化" scheme="https://sam.xx.kg/tags/%E8%99%9A%E6%8B%9F%E5%8C%96/"/>
    <category term="显卡直通" scheme="https://sam.xx.kg/tags/%E6%98%BE%E5%8D%A1%E7%9B%B4%E9%80%9A/"/>
    <content>
      <![CDATA[<blockquote><p>本文介绍在 <strong>Proxmox VE 8.1</strong> 系统上直通 Intel N100 核显并开启 SR-IOV（Single Root I&#x2F;O Virtualization）的完整步骤，让多个虚拟机可以共享 GPU 硬件解码能力。</p></blockquote><h2 id="前置条件"><a href="#前置条件" class="headerlink" title="前置条件"></a>前置条件</h2><ul><li>硬件：Intel N100 或类似支持 SR-IOV 的处理器</li><li>系统：Proxmox VE 8.1+</li><li>BIOS 中已开启 <strong>VT-D</strong>（Intel Virtualization Technology for Directed I&#x2F;O）</li></ul><hr><h2 id="一、开启-IOMMU"><a href="#一、开启-IOMMU" class="headerlink" title="一、开启 IOMMU"></a>一、开启 IOMMU</h2><h3 id="修改-GRUB-配置"><a href="#修改-GRUB-配置" class="headerlink" title="修改 GRUB 配置"></a>修改 GRUB 配置</h3><p>编辑 GRUB 配置文件：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">nano /etc/default/grub</span><br></pre></td></tr></table></figure><p>找到 <code>GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet&quot;</code>，修改为：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">GRUB_CMDLINE_LINUX_DEFAULT=<span class="string">&quot;quiet intel_iommu=on i915.enable_guc=3 i915.max_vfs=7&quot;</span></span><br></pre></td></tr></table></figure><p>参数说明：</p><table><thead><tr><th>参数</th><th>说明</th></tr></thead><tbody><tr><td><code>intel_iommu=on</code></td><td>开启 Intel IOMMU</td></tr><tr><td><code>i915.enable_guc=3</code></td><td>启用 GuC&#x2F;HuC 固件，硬件编解码必需</td></tr><tr><td><code>i915.max_vfs=7</code></td><td>最大虚拟功能数量（根据需求调整）</td></tr></tbody></table><h3 id="更新-GRUB-并重启"><a href="#更新-GRUB-并重启" class="headerlink" title="更新 GRUB 并重启"></a>更新 GRUB 并重启</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">update-grub</span><br><span class="line">reboot</span><br></pre></td></tr></table></figure><h3 id="验证-IOMMU-是否开启"><a href="#验证-IOMMU-是否开启" class="headerlink" title="验证 IOMMU 是否开启"></a>验证 IOMMU 是否开启</h3><p>重启后运行：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">dmesg | grep -e DMAR -e IOMMU</span><br></pre></td></tr></table></figure><p>正常输出应包含 <code>DMAR: IOMMU enabled</code>，例如：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">[    0.014745] ACPI: DMAR 0x00000000734DC000 000088 (v02 INTEL  EDK2     00000002      01000013)</span><br><span class="line">[    0.046876] DMAR: IOMMU enabled</span><br><span class="line">[    0.106676] DMAR: Host address width 39</span><br></pre></td></tr></table></figure><hr><h2 id="二、加载-VFIO-内核模块"><a href="#二、加载-VFIO-内核模块" class="headerlink" title="二、加载 VFIO 内核模块"></a>二、加载 VFIO 内核模块</h2><p>编辑 <code>/etc/modules</code>：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">nano /etc/modules</span><br></pre></td></tr></table></figure><p>添加以下内容：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">vfio</span><br><span class="line">vfio_iommu_type1</span><br><span class="line">vfio_pci</span><br><span class="line">vfio_virqfd</span><br></pre></td></tr></table></figure><p>这些模块用于将 PCIe 设备 passthrough 给虚拟机时启用 IOMMU 分组转换，提高未使用 PCIe 设备的性能。</p><hr><h2 id="三、安装-SR-IOV-驱动"><a href="#三、安装-SR-IOV-驱动" class="headerlink" title="三、安装 SR-IOV 驱动"></a>三、安装 SR-IOV 驱动</h2><h3 id="查询内核版本"><a href="#查询内核版本" class="headerlink" title="查询内核版本"></a>查询内核版本</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">uname</span> -r</span><br></pre></td></tr></table></figure><p>示例输出：<code>6.5.11-7-pve</code></p><h3 id="安装内核-Headers"><a href="#安装内核-Headers" class="headerlink" title="安装内核 Headers"></a>安装内核 Headers</h3><p>到 <a href="http://mirrors.ustc.edu.cn/proxmox/debian/dists/bookworm/pve-no-subscription/binary-amd64/">中科大 PVE 镜像源</a> 下载对应版本的 headers 包：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">wget http://mirrors.ustc.edu.cn/proxmox/debian/dists/bookworm/pve-no-subscription/binary-amd64/proxmox-headers-6.5.11-7-pve_6.5.11-7_amd64.deb</span><br><span class="line">dpkg -i proxmox-headers-6.5.11-7-pve_6.5.11-7_amd64.deb</span><br></pre></td></tr></table></figure><h3 id="安装依赖"><a href="#安装依赖" class="headerlink" title="安装依赖"></a>安装依赖</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">apt install -y build-essential git unzip dkms</span><br></pre></td></tr></table></figure><h3 id="下载-SR-IOV-DKMS-驱动"><a href="#下载-SR-IOV-DKMS-驱动" class="headerlink" title="下载 SR-IOV DKMS 驱动"></a>下载 SR-IOV DKMS 驱动</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/strongtz/i915-sriov-dkms.git</span><br><span class="line"><span class="built_in">mv</span> i915-sriov-dkms /usr/src</span><br></pre></td></tr></table></figure><h3 id="修改-DKMS-配置"><a href="#修改-DKMS-配置" class="headerlink" title="修改 DKMS 配置"></a>修改 DKMS 配置</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">nano /usr/src/i915-sriov-dkms/dkms.conf</span><br></pre></td></tr></table></figure><p>按实际内核版本修改：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">PACKAGE_NAME=&quot;i915-sriov-dkms&quot;</span><br><span class="line">PACKAGE_VERSION=&quot;6.5&quot;</span><br></pre></td></tr></table></figure><h3 id="安装驱动"><a href="#安装驱动" class="headerlink" title="安装驱动"></a>安装驱动</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">dkms install -m i915-sriov -v dkms --force</span><br></pre></td></tr></table></figure><h3 id="验证安装"><a href="#验证安装" class="headerlink" title="验证安装"></a>验证安装</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">dkms status</span><br></pre></td></tr></table></figure><p>正常输出：</p><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">i915-sriov-dkms/6.5, 6.5.11-7-pve, x86_64: installed</span><br></pre></td></tr></table></figure><h3 id="重启"><a href="#重启" class="headerlink" title="重启"></a>重启</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">reboot</span><br></pre></td></tr></table></figure><hr><h2 id="四、配置开机启动-SR-IOV"><a href="#四、配置开机启动-SR-IOV" class="headerlink" title="四、配置开机启动 SR-IOV"></a>四、配置开机启动 SR-IOV</h2><p>创建开机脚本，自动创建虚拟功能：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&#x27;#!/bin/bash&#x27;</span> &gt;&gt; /etc/rc.local</span><br><span class="line"><span class="built_in">echo</span> <span class="string">&quot;echo 7 &gt; /sys/devices/pci0000:00/0000:00:02.0/sriov_numvfs&quot;</span> &gt;&gt; /etc/rc.local</span><br><span class="line"><span class="built_in">chmod</span> +x /etc/rc.local</span><br></pre></td></tr></table></figure><blockquote><p><code>echo 7</code> 表示开启 7 个 VF（Virtual Function），可根据需求改为其他数值。</p></blockquote><h3 id="验证-SR-IOV"><a href="#验证-SR-IOV" class="headerlink" title="验证 SR-IOV"></a>验证 SR-IOV</h3><p>重启后使用 <code>lspci</code> 查看是否出现多个 <code>0000:00:02</code> 设备：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">lspci | grep 00:02</span><br></pre></td></tr></table></figure><p>若能列出多个虚拟功能设备，即代表成功。</p><hr><h2 id="五、虚拟机配置要求"><a href="#五、虚拟机配置要求" class="headerlink" title="五、虚拟机配置要求"></a>五、虚拟机配置要求</h2><h3 id="通用要求"><a href="#通用要求" class="headerlink" title="通用要求"></a>通用要求</h3><ul><li><strong>BIOS 类型</strong>：<code>OVMF (UEFI)</code></li><li><strong>机器类型</strong>：<code>q35</code></li><li><strong>显卡</strong>：设置为 <code>无</code>（不使用虚拟显卡，直接直通 VF）</li></ul><h3 id="Linux-虚拟机"><a href="#Linux-虚拟机" class="headerlink" title="Linux 虚拟机"></a>Linux 虚拟机</h3><p>直通后可使用 <code>renderD128</code> 设备进行硬件编解码。如果未出现该设备，运行以下命令排查：</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">dmesg | grep i915</span><br></pre></td></tr></table></figure><h3 id="Windows-虚拟机"><a href="#Windows-虚拟机" class="headerlink" title="Windows 虚拟机"></a>Windows 虚拟机</h3><ol><li>虚拟机配置必须为 OVMF + q35</li><li>显卡设置为 <code>无</code></li><li>安装最新 Intel 显卡驱动（以下二选一自行测试）：<ul><li><a href="https://www.intel.com/content/www/us/en/download/785597/">Intel Arc &amp; Iris Xe Graphics Driver</a></li><li><a href="https://www.intel.com/content/www/us/en/download/19344/">Intel Graphics Driver for Windows</a></li></ul></li></ol><hr><h2 id="排错参考"><a href="#排错参考" class="headerlink" title="排错参考"></a>排错参考</h2><table><thead><tr><th>问题</th><th>排查方法</th></tr></thead><tbody><tr><td>IOMMU 未开启</td><td>检查 BIOS VT-D 设置，确认 GRUB 参数正确</td></tr><tr><td>i915 模块未加载</td><td>&#96;lsmod</td></tr><tr><td>renderD128 未出现</td><td>&#96;dmesg</td></tr><tr><td>SR-IOV 设备未创建</td><td>检查 <code>/sys/devices/pci0000:00/0000:00:02.0/sriov_numvfs</code> 文件读写权限</td></tr></tbody></table><hr><h2 id="视频教程"><a href="#视频教程" class="headerlink" title="视频教程"></a>视频教程</h2><iframe src="//player.bilibili.com/player.html" width="100%" height="400" frameborder="no" scrolling="no" allowfullscreen="true"></iframe>]]>
    </content>
    <id>https://sam.xx.kg/post/PVE8%E7%9B%B4%E9%80%9A%E6%A0%B8%E6%98%BE%EF%BC%88N100%EF%BC%89%EF%BC%8C%E5%B9%B6%E5%BC%80%E5%90%AF%E8%99%9A%E6%8B%9F%E5%8C%96Sriov/</id>
    <link href="https://sam.xx.kg/post/PVE8%E7%9B%B4%E9%80%9A%E6%A0%B8%E6%98%BE%EF%BC%88N100%EF%BC%89%EF%BC%8C%E5%B9%B6%E5%BC%80%E5%90%AF%E8%99%9A%E6%8B%9F%E5%8C%96Sriov/"/>
    <published>2024-09-24T15:20:35.000Z</published>
    <summary>在 Proxmox VE 8 上直通 Intel N100 核显并启用 SR-IOV，实现多个虚拟机共享 GPU 硬件解码能力。</summary>
    <title>PVE 8 直通 N100 核显并开启 SR-IOV 虚拟化</title>
    <updated>2026-06-30T03:44:09.716Z</updated>
  </entry>
</feed>
