<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[游魂博客]]></title> 
<description><![CDATA[技术交流,资源共享,分享点滴。]]></description>
<link>https://www.iyouhun.com/</link>
<language>zh-cn</language>
<generator>www.iyouhun.com</generator>
<item>
	<title>玩转OpenClaw：主配置文件参数详解指南手册</title>
	<link>https://www.iyouhun.com/post-309.html</link>
	<description><![CDATA[<p><img src="https://oss.iyouhun.com/md/%E7%8E%A9%E8%BD%ACOpenClaw%E4%B8%BB%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%8F%82%E6%95%B0%E8%AF%A6%E8%A7%A3%E6%8C%87%E5%8D%97%E6%89%8B%E5%86%8C.png" alt="玩转OpenClaw主配置文件参数详解指南手册">
<h2 id="h2-u914Du7F6Eu6587u4EF6u6982u8FF0"><a name="配置文件概述" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置文件概述</h2><p>OpenClaw 使用 JSON / JSON5 格式的配置文件来管理系统所有组件的设置。配置文件采用分层结构，支持灵活的配置覆盖和环境变量注入。</p>
<h3 id="h3-u4E3Bu8981u7279u6027"><a name="主要特性" class="reference-link"></a><span class="header-link octicon octicon-link"></span>主要特性</h3><ul>
<li><strong>JSON5 支持</strong>：支持注释、尾随逗号、单引号等扩展语法</li><li><strong>环境变量</strong>：可通过 env 字段或者 <code>.env</code>文件注入环境变量</li><li><strong>配置合并</strong>：支持多配置文件合并（主配置 + 环境配置）</li><li><strong>热重载</strong>：部分配置支持运行时重载（需重启网关）</li></ul>
<h2 id="h2-u6587u4EF6u683Cu5F0Fu4E0Eu4F4Du7F6E"><a name="文件格式与位置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>文件格式与位置</h2><h3 id="h3-u4E3Bu914Du7F6Eu6587u4EF6"><a name="主配置文件" class="reference-link"></a><span class="header-link octicon octicon-link"></span>主配置文件</h3><pre><code class="lang-bash"># 主配置文件路径
~/.openclaw/openclaw.json

# 配置文件备份
~/.openclaw/openclaw.json.bak
</code></pre>
<h3 id="h3-u914Du7F6Eu6587u4EF6u683Cu5F0F"><a name="配置文件格式" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置文件格式</h3><p>OpenClaw 支持标准的 JSON 和 JSON5 格式</p>
<pre><code class="lang-json">// JSON5 示例（支持注释）
{
  // 模型配置
  models: {
    // 提供商列表
    providers: {
      openai: {
        apiKey: "${OPENAI_API_KEY}",  // 环境变量引用
      },
    },
  },

  // 代理配置
  agents: {
    defaults: {
      model: {
        primary: "openai/gpt-4o",
      },
    },
  },
}
</code></pre>
<h3 id="h3-u73AFu5883u53D8u91CFu5F15u7528"><a name="环境变量引用" class="reference-link"></a><span class="header-link octicon octicon-link"></span>环境变量引用</h3><pre><code class="lang-json">{
  env: {
    // 设置环境变量
    "OPENAI_API_KEY": "sk-xxx",
  },

  models: {
    providers: {
      openai: {
        // 引用环境变量
        apiKey: "${OPENAI_API_KEY}",
      },
    },
  },
}
</code></pre>
<h2 id="h2-u914Du7F6Eu6587u4EF6u7ED3u6784u603Bu89C8"><a name="配置文件结构总览" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置文件结构总览</h2><pre><code class="lang-json">{
  "meta": {},                    // 元数据
  "wizard": {},                  // 向导记录
  "auth": {},                    // 认证配置
  "models": {},                  // 模型配置
  "agents": {},                  // 代理配置
  "channels": {},                // 频道配置
  "gateway": {},                 // 网关配置
  "memory": {},                  // 内存配置
  "plugins": {},                 // 插件配置
  "commands": {},                // 命令配置
  "messages": {},                // 消息配置
  "env": {},                     // 环境变量（可选）
  "tools": {},                   // 工具配置（可选）
  "bindings": [],                // 代理绑定（可选）
}
</code></pre>
<h2 id="h2-meta-"><a name="meta - 元数据" class="reference-link"></a><span class="header-link octicon octicon-link"></span>meta - 元数据</h2><blockquote>
<p>记录配置文件的元数据信息，由系统自动维护。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>lastTouchedVersion</code></td>
<td>string</td>
<td>-</td>
<td>最后修改配置的 OpenClaw 版本</td>
</tr>
<tr>
<td><code>lastTouchedAt</code></td>
<td>string</td>
<td>-</td>
<td>最后修改时间 (ISO 8601)</td>
</tr>
</tbody>
</table>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "meta": {
    "lastTouchedVersion": "2026.3.11",
    "lastTouchedAt": "2026-03-13T01:42:30.878Z"
  }
}
</code></pre>
<h2 id="h2-wizard-"><a name="wizard - 向导记录" class="reference-link"></a><span class="header-link octicon octicon-link"></span>wizard - 向导记录</h2><blockquote>
<p>记录配置向导的运行状态。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>lastRunAt</code></td>
<td>string</td>
<td>-</td>
<td>最后运行向导的时间</td>
</tr>
<tr>
<td><code>lastRunVersion</code></td>
<td>string</td>
<td>-</td>
<td>运行向导时的版本</td>
</tr>
<tr>
<td><code>lastRunCommand</code></td>
<td>string</td>
<td>-</td>
<td>最后运行的命令</td>
</tr>
<tr>
<td><code>lastRunMode</code></td>
<td>string</td>
<td>-</td>
<td>运行模式 (local/remote)</td>
</tr>
</tbody>
</table>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "wizard": {
    "lastRunAt": "2026-02-25T12:06:39.761Z",
    "lastRunVersion": "2026.2.24",
    "lastRunCommand": "configure",
    "lastRunMode": "local"
  }
}
</code></pre>
<h2 id="h2-auth-"><a name="auth - 认证配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>auth - 认证配置</h2><blockquote>
<p>管理模型提供商的认证信息。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>profiles</code></td>
<td>object</td>
<td>{}</td>
<td>认证配置集合</td>
</tr>
</tbody>
</table>
<h4 id="h4-u8BA4u8BC1u914Du7F6Eu5BF9u8C61"><a name="认证配置对象" class="reference-link"></a><span class="header-link octicon octicon-link"></span>认证配置对象</h4><pre><code class="lang-json">{
  "auth": {
    "profiles": {
      "&lt;provider&gt;:&lt;profile&gt;": {
        "provider": "openai",        // 提供商名称
        "mode": "api_key",          // 认证模式
        "apiKey": "sk-xxx",         // API密钥
        "baseUrl": "https://api.openai.com/v1"  // API基础URL
      }
    }
  }
}
</code></pre>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "auth": {
    "profiles": {
      "minimax-cn:default": {
        "provider": "minimax-cn",
        "mode": "api_key"
      },
      "openai:default": {
        "provider": "openai",
        "mode": "api_key"
      }
    }
  }
}
</code></pre>
<h2 id="h2-models-"><a name="models - 模型配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>models - 模型配置</h2><blockquote>
<p>配置模型提供商和可用模型。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mode</code></td>
<td>string</td>
<td>“merge”</td>
<td>配置模式 (merge/replace)</td>
</tr>
<tr>
<td><code>providers</code></td>
<td>object</td>
<td>{}</td>
<td>模型提供商配置</td>
</tr>
</tbody>
</table>
<h4 id="h4-u63D0u4F9Bu5546u914Du7F6Eu7ED3u6784"><a name="提供商配置结构" class="reference-link"></a><span class="header-link octicon octicon-link"></span>提供商配置结构</h4><pre><code class="lang-json">{
  "models": {
    "providers": {
      "&lt;provider-name&gt;": {
        "baseUrl": "https://api.example.com",  // API基础URL
        "apiKey": "sk-xxx",                    // API密钥
        "api": "openai-completions",          // API类型
        "models": [                           // 可用模型列表
          {
            "id": "model-name",               // 模型ID
            "name": "显示名称",               // 模型显示名称
            "reasoning": true,                // 是否支持推理
            "input": ["text", "image"],       // 支持的输入类型
            "cost": {                         // 成本配置
              "input": 0.1,                   // 输入token成本
              "output": 0.3,                  // 输出token成本
              "cacheRead": 0.01,              // 缓存读取成本
              "cacheWrite": 0.05              // 缓存写入成本
            },
            "contextWindow": 128000,          // 上下文窗口大小
            "maxTokens": 4096                 // 最大输出token数
          }
        ]
      }
    }
  }
}
</code></pre>
<h3 id="h3--api-"><a name="支持的 API 类型" class="reference-link"></a><span class="header-link octicon octicon-link"></span>支持的 API 类型</h3><ul>
<li><code>openai-completions</code> - OpenAI 兼容的补全API</li><li><code>anthropic-messages</code> - Anthropic Messages API</li><li><code>openrouter</code> - OpenRouter API</li></ul>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "models": {
    "mode": "merge",
    "providers": {
      "deepseek": {
        "baseUrl": "https://api.deepseek.com",
        "api": "openai-completions",
        "models": [
          {
            "id": "deepseek-reasoner",
            "name": "DeepSeek Reasoner",
            "reasoning": true,
            "input": ["text"],
            "cost": {
              "input": 0.14,
              "output": 2.19
            },
            "contextWindow": 64000,
            "maxTokens": 8192
          }
        ]
      },
      "openai": {
        "baseUrl": "https://api.openai.com/v1",
        "api": "openai-completions",
        "models": [
          {
            "id": "gpt-4o",
            "name": "GPT-4o",
            "input": ["text", "image"],
            "contextWindow": 128000,
            "maxTokens": 4096
          }
        ]
      }
    }
  }
}
</code></pre>
<h2 id="h2-agents-"><a name="agents - 代理配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>agents - 代理配置</h2><blockquote>
<p>配置代理（agent）的默认设置和实例列表。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>defaults</code></td>
<td>object</td>
<td>{}</td>
<td>默认代理配置</td>
</tr>
<tr>
<td><code>list</code></td>
<td>array</td>
<td>[]</td>
<td>代理实例列表</td>
</tr>
</tbody>
</table>
<h4 id="h4-u9ED8u8BA4u4EE3u7406u914Du7F6E"><a name="默认代理配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>默认代理配置</h4><pre><code class="lang-json">{
  "agents": {
    "defaults": {
      "model": {
        "primary": "openai/gpt-4o",       // 主要模型
        "fallbacks": [                    // 回退模型列表
          "anthropic/claude-3-5-sonnet",
          "deepseek/deepseek-chat"
        ]
      },
      "models": {                         // 模型别名和参数
        "openai/gpt-4o": {
          "alias": "GPT-4o",
          "params": {
            "temperature": 0.7,
            "max_tokens": 4096
          }
        }
      },
      "workspace": "~/.openclaw/workspace",  // 工作区路径
      "compaction": {                        // 压缩配置
        "mode": "safeguard"                  // 模式：safeguard/aggressive/off
      },
      "maxConcurrent": 4,                    // 最大并发数
      "subagents": {                         // 子代理配置
        "maxConcurrent": 8,                  // 子代理最大并发数
        "allowAgents": []                    // 允许的子代理列表
      }
    }
  }
}
</code></pre>
<h4 id="h4-u4EE3u7406u5B9Eu4F8Bu914Du7F6E"><a name="代理实例配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>代理实例配置</h4><pre><code class="lang-json">{
  "agents": {
    "list": [
      {
        "id": "main",                      // 代理ID
        "name": "主代理",                  // 显示名称（可选）
        "model": "deepseek/deepseek-chat", // 模型覆盖
        "workspace": "/path/to/workspace", // 工作区覆盖
        "subagents": {                     // 子代理配置
          "allowAgents": [                 // 允许的子代理ID
            "prompt-engineer",
            "media-generator"
          ]
        }
      }
    ]
  }
}
</code></pre>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "agents": {
    "defaults": {
      "model": {
        "primary": "minimax/MiniMax-M2.5",
        "fallbacks": [
          "minimax-cn/MiniMax-M2.5",
          "deepseek/deepseek-reasoner"
        ]
      },
      "models": {
        "minimax/MiniMax-M2.5": {
          "alias": "Minimax"
        }
      },
      "workspace": "~/.openclaw/workspace",
      "compaction": {
        "mode": "safeguard"
      },
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      }
    },
    "list": [
      {
        "id": "main",
        "model": "deepseek/deepseek-reasoner"
      },
      {
        "id": "support",
        "name": "支持代理",
        "workspace": "/path/to/support-workspace"
      }
    ]
  }
}
</code></pre>
<h2 id="h2-channels-"><a name="channels - 频道配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>channels - 频道配置</h2><blockquote>
<p> 配置聊天频道（如 Telegram、飞书、QQ、Discord 等）。</p>
</blockquote>
<h3 id="h3-u901Au7528u9891u9053u53C2u6570"><a name="通用频道参数" class="reference-link"></a><span class="header-link octicon octicon-link"></span>通用频道参数</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>enabled</code></td>
<td>boolean</td>
<td>true</td>
<td>是否启用频道</td>
</tr>
<tr>
<td><code>dmPolicy</code></td>
<td>string</td>
<td>“pairing”</td>
<td>私聊策略 (pairing/allowlist/open/disabled)</td>
</tr>
<tr>
<td><code>groupPolicy</code></td>
<td>string</td>
<td>“open”</td>
<td>群聊策略 (allowlist/open/disabled)</td>
</tr>
<tr>
<td><code>streaming</code></td>
<td>string/boolean</td>
<td>“partial”</td>
<td>流式输出 (true/false/“partial”)</td>
</tr>
<tr>
<td><code>allowFrom</code></td>
<td>array</td>
<td>[]</td>
<td>允许的用户/群组列表</td>
</tr>
<tr>
<td><code>textChunkLimit</code></td>
<td>number</td>
<td>2000</td>
<td>文本块大小限制</td>
</tr>
<tr>
<td><code>mediaMaxMb</code></td>
<td>number</td>
<td>30</td>
<td>媒体文件大小限制 (MB)</td>
</tr>
</tbody>
</table>
<h3 id="h3-telegram-"><a name="Telegram 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Telegram 配置</h3><pre><code class="lang-json">{
  "channels": {
    "telegram": {
      "enabled": true,
      "dmPolicy": "pairing",
      "botToken": "YOUR_BOT_TOKEN",  // Telegram Bot Token
      "groupPolicy": "allowlist",
      "streaming": "partial",
      "allowFrom": ["@username", "chat_id"]
    }
  }
}
</code></pre>
<h3 id="h3--feishu-"><a name="飞书 (Feishu) 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>飞书 (Feishu) 配置</h3><pre><code class="lang-json">{
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxx",           // 飞书应用ID
      "appSecret": "xxx",           // 飞书应用Secret
      "domain": "feishu",           // 域名 (feishu/lark)
      "dmPolicy": "allow",
      "accounts": {
        "default": {
          "appId": "cli_xxx"
        }
      }
    }
  }
}
</code></pre>
<h3 id="h3-qq-"><a name="QQ 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>QQ 配置</h3><pre><code class="lang-json">{
  "channels": {
    "qqbot": {
      "enabled": true,
      "allowFrom": [
        "*"
      ],
      "appId": "12345xxxx",           // 机器人AppId
      "clientSecret": "xxx",           // 机器人AppSecret
    }
  }
}
</code></pre>
<h3 id="h3-discord-"><a name="Discord 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Discord 配置</h3><pre><code class="lang-json">{
  "channels": {
    "discord": {
      "enabled": true,
      "botToken": "YOUR_DISCORD_TOKEN",
      "clientId": "YOUR_CLIENT_ID",
      "dmPolicy": "pairing",
      "groupPolicy": "open"
    }
  }
}
</code></pre>
<h3 id="h3-whatsapp-"><a name="WhatsApp 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>WhatsApp 配置</h3><pre><code class="lang-json">{
  "channels": {
    "whatsapp": {
      "enabled": true,
      "sessionPath": "~/.openclaw/whatsapp-session",
      "dmPolicy": "pairing",
      "qrTimeout": 300000  // QR码超时时间(ms)
    }
  }
}
</code></pre>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "channels": {
    "telegram": {
      "enabled": true,
      "dmPolicy": "pairing",
      "groupPolicy": "allowlist",
      "streaming": "partial"
    },
    "feishu": {
      "enabled": true,
      "appId": "cli_xxx",
      "domain": "feishu",
      "dmPolicy": "allow",
      "allowFrom": ["*"]
    }
  }
}
</code></pre>
<h2 id="h2-gateway-"><a name="gateway - 网关配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>gateway - 网关配置</h2><blockquote>
<p> 配置 OpenClaw 网关服务。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>port</code></td>
<td>number</td>
<td>18789</td>
<td>WebSocket 端口</td>
</tr>
<tr>
<td style="text-align:left"><code>mode</code></td>
<td>string</td>
<td>“local”</td>
<td>网关模式 (local/remote)</td>
</tr>
<tr>
<td style="text-align:left"><code>bind</code></td>
<td>string</td>
<td>“loopback”</td>
<td>绑定模式 (loopback/lan/tailnet/auto)</td>
</tr>
<tr>
<td style="text-align:left"><code>auth</code></td>
<td>object</td>
<td>{}</td>
<td>网关认证配置</td>
</tr>
<tr>
<td style="text-align:left"><code>controlUi</code></td>
<td>object</td>
<td>{}</td>
<td>控制UI配置</td>
</tr>
<tr>
<td style="text-align:left"><code>tailscale</code></td>
<td>object</td>
<td>{}</td>
<td>Tailscale 集成配置</td>
</tr>
</tbody>
</table>
<h4 id="h4-u8BA4u8BC1u914Du7F6E"><a name="认证配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>认证配置</h4><pre><code class="lang-json">{
  "gateway": {
    "auth": {
      "mode": "token",              // 认证模式 (token/password/none)
      "token": "your_token_here",   // 认证令牌
      "password": "your_password"   // 认证密码
    }
  }
}
</code></pre>
<h4 id="h4--ui-"><a name="控制UI配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>控制UI配置</h4><pre><code class="lang-json">{
  "gateway": {
    "controlUi": {
      "enabled": true,                            // 启用控制UI
      "dangerouslyAllowHostHeaderOriginFallback": false,  // 允许Host头回退
      "allowInsecureAuth": false                  // 允许不安全认证
    }
  }
}
</code></pre>
<h4 id="h4-tailscale-"><a name="Tailscale 配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Tailscale 配置</h4><pre><code class="lang-json">{
  "gateway": {
    "tailscale": {
      "mode": "off",              // Tailscale模式 (off/serve/funnel)
      "resetOnExit": false        // 退出时重置配置
    }
  }
}
</code></pre>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "lan",
    "controlUi": {
      "enabled": true,
      "allowInsecureAuth": true
    },
    "auth": {
      "mode": "token"
    },
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    }
  }
}
</code></pre>
<h2 id="h2-memory-"><a name="memory - 内存配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>memory - 内存配置</h2><blockquote>
<p> 配置记忆（memory）系统。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>backend</code></td>
<td>string</td>
<td>“qmd”</td>
<td>内存后端 (qmd/file)</td>
</tr>
<tr>
<td><code>citations</code></td>
<td>string</td>
<td>“auto”</td>
<td>引用模式 (auto/always/never)</td>
</tr>
<tr>
<td><code>qmd</code></td>
<td>object</td>
<td>{}</td>
<td>QMD 后端配置</td>
</tr>
</tbody>
</table>
<h4 id="h4-qmd-"><a name="QMD 后端配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>QMD 后端配置</h4><pre><code class="lang-json">{
  "memory": {
    "qmd": {
      "includeDefaultMemory": true,    // 包含默认内存
      "update": {                      // 更新配置
        "interval": "5m",              // 更新间隔
        "debounceMs": 15000,           // 防抖时间(ms)
        "onBoot": true                 // 启动时更新
      },
      "limits": {                      // 限制配置
        "maxResults": 10,              // 最大结果数
        "maxSnippetChars": 2000,       // 最大片段字符数
        "timeoutMs": 10000             // 超时时间(ms)
      },
      "scope": {                       // 作用域配置
        "default": "deny",             // 默认动作
        "rules": [                     // 规则列表
          {
            "action": "allow",         // 动作 (allow/deny)
            "match": {                 // 匹配条件
              "chatType": "direct"     // 聊天类型
            }
          }
        ]
      }
    }
  }
}
</code></pre>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "memory": {
    "backend": "qmd",
    "citations": "auto",
    "qmd": {
      "includeDefaultMemory": true,
      "update": {
        "interval": "5m",
        "debounceMs": 15000,
        "onBoot": true
      },
      "limits": {
        "maxResults": 10,
        "maxSnippetChars": 2000,
        "timeoutMs": 10000
      },
      "scope": {
        "default": "deny",
        "rules": [
          {
            "action": "allow",
            "match": {
              "chatType": "direct"
            }
          }
        ]
      }
    }
  }
}
</code></pre>
<h2 id="h2-plugins-"><a name="plugins - 插件配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>plugins - 插件配置</h2><blockquote>
<p>管理 OpenClaw 插件。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>entries</code></td>
<td>object</td>
<td>{}</td>
<td>插件条目配置</td>
</tr>
<tr>
<td><code>installs</code></td>
<td>object</td>
<td>{}</td>
<td>插件安装记录</td>
</tr>
</tbody>
</table>
<h4 id="h4-u63D2u4EF6u914Du7F6Eu793Au4F8B"><a name="插件配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>插件配置示例</h4><pre><code class="lang-json">{
  "plugins": {
    "entries": {
      "telegram": {
        "enabled": true          // 启用Telegram插件
      },
      "feishu": {
        "enabled": true          // 启用飞书插件
      }
    },
    "installs": {
      "@openclaw/feishu": {
        "version": "1.0.0",      // 插件版本
        "path": "/path/to/plugin" // 插件路径
      }
    }
  }
}
</code></pre>
<h2 id="h2-commands-"><a name="commands - 命令配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>commands - 命令配置</h2><blockquote>
<p>配置命令行行为。</p>
</blockquote>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>native</code></td>
<td>string</td>
<td>“auto”</td>
<td>本地命令处理 (auto/enabled/disabled)</td>
</tr>
<tr>
<td><code>nativeSkills</code></td>
<td>string</td>
<td>“auto”</td>
<td>本地技能处理</td>
</tr>
<tr>
<td><code>restart</code></td>
<td>boolean</td>
<td>true</td>
<td>允许重启命令</td>
</tr>
<tr>
<td><code>ownerDisplay</code></td>
<td>string</td>
<td>“raw”</td>
<td>所有者显示方式</td>
</tr>
</tbody>
</table>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "commands": {
    "native": "auto",
    "nativeSkills": "auto",
    "restart": true,
    "ownerDisplay": "raw"
  }
}
</code></pre>
<h2 id="h2-messages-"><a name="messages - 消息配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>messages - 消息配置</h2><blockquote>
<p> 配置消息处理行为。</p>
</blockquote>
<h3 id="h3-u53C2u6570u8BF4u660E"><a name="参数说明" class="reference-link"></a><span class="header-link octicon octicon-link"></span>参数说明</h3><table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>ackReactionScope</code></td>
<td>string</td>
<td>“group-mentions”</td>
<td>确认反应范围</td>
</tr>
</tbody>
</table>
<h3 id="h3-u914Du7F6Eu793Au4F8B"><a name="配置示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置示例</h3><pre><code class="lang-json">{
  "messages": {
    "ackReactionScope": "group-mentions"
  }
}
</code></pre>
<h2 id="h2-u5E38u7528u914Du7F6Eu7247u6BB5u793Au4F8B"><a name="常用配置片段示例" class="reference-link"></a><span class="header-link octicon octicon-link"></span>常用配置片段示例</h2><h3 id="h3--1-"><a name="示例1：基础模型配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>示例1：基础模型配置</h3><pre><code class="lang-json">// 基础模型配置
{
  env: {
    "OPENAI_API_KEY": "sk-xxx",
    "ANTHROPIC_API_KEY": "sk-ant-xxx"
  },

  models: {
    providers: {
      openai: {
        apiKey: "${OPENAI_API_KEY}",
        api: "openai-completions",
        models: [
          {
            id: "gpt-4o",
            name: "GPT-4o",
            input: ["text", "image"],
            contextWindow: 128000
          }
        ]
      }
    }
  },

  agents: {
    defaults: {
      model: {
        primary: "openai/gpt-4o",
        fallbacks: ["anthropic/claude-3-5-sonnet"]
      }
    }
  }
}
</code></pre>
<h3 id="h3--2-"><a name="示例2：多代理工作区配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>示例2：多代理工作区配置</h3><pre><code class="lang-json">// 多代理配置
{
  agents: {
    defaults: {
      workspace: "~/.openclaw/workspace",
      maxConcurrent: 4
    },
    list: [
      {
        id: "main",
        name: "主代理",
        model: "deepseek/deepseek-chat"
      },
      {
        id: "research",
        name: "研究代理",
        workspace: "~/.openclaw/workspace-research",
        model: "openai/gpt-4o"
      },
      {
        id: "coding",
        name: "编程代理",
        workspace: "~/.openclaw/workspace-coding",
        model: "deepseek/deepseek-coder"
      }
    ]
  }
}
</code></pre>
<h3 id="h3--3-"><a name="示例3：频道安全配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>示例3：频道安全配置</h3><pre><code class="lang-json">// 安全的频道配置
{
  channels: {
    telegram: {
      enabled: true,
      dmPolicy: "allowlist",
      groupPolicy: "allowlist",
      allowFrom: [
        "user_id_1",      // 允许的用户ID
        "group_id_1"      // 允许的群组ID
      ]
    },

    feishu: {
      enabled: true,
      dmPolicy: "pairing",  // 需要配对
      groupPolicy: "open",
      allowFrom: ["*"]      // 允许所有（仅当policy为open时）
    }
  },

  gateway: {
    auth: {
      mode: "token",        // 要求令牌认证
      token: "secure_token_here"
    }
  }
}
</code></pre>
<h3 id="h3--4-"><a name="示例4：开发环境配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>示例4：开发环境配置</h3><pre><code class="lang-json">// 开发环境配置
{
  gateway: {
    port: 19001,          // 开发端口
    bind: "loopback",     // 仅本地访问
    controlUi: {
      enabled: true,
      allowInsecureAuth: true  // 开发时允许不安全认证
    }
  },

  agents: {
    defaults: {
      model: {
        primary: "deepseek/deepseek-chat",
        fallbacks: []
      }
    }
  },

  memory: {
    backend: "file",      // 使用文件后端（简化）
    citations: "never"    // 开发时不显示引用
  }
}
</code></pre>
<h3 id="h3--5-"><a name="示例5：生产环境配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>示例5：生产环境配置</h3><pre><code class="lang-json">// 生产环境配置
{
  gateway: {
    port: 18789,
    bind: "lan",          // 局域网访问
    auth: {
      mode: "password",   // 密码认证
      password: "strong_password_here"
    },
    controlUi: {
      enabled: true,
      dangerouslyAllowHostHeaderOriginFallback: false,
      allowInsecureAuth: false
    }
  },

  agents: {
    defaults: {
      model: {
        primary: "openai/gpt-4o",
        fallbacks: [
          "anthropic/claude-3-5-sonnet",
          "deepseek/deepseek-chat"
        ]
      },
      maxConcurrent: 8,
      subagents: {
        maxConcurrent: 16
      }
    }
  },

  memory: {
    backend: "qmd",
    qmd: {
      update: {
        interval: "1h",   // 生产环境更新间隔较长
        debounceMs: 30000
      }
    }
  }
}
</code></pre>
<h2 id="h2-u914Du7F6Eu6700u4F73u5B9Eu8DF5"><a name="配置最佳实践" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置最佳实践</h2><h3 id="h3-1-"><a name="1. 安全配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>1. 安全配置</h3><ul>
<li><strong>使用环境变量</strong>：敏感信息（API密钥、令牌）应通过环境变量注入</li><li><strong>限制访问</strong>：根据需求设置 <code>dmPolicy</code> 和 <code>groupPolicy</code></li><li><strong>网关认证</strong>：生产环境务必启用网关认证（token 或 password）</li><li><strong>网络绑定</strong>：根据部署环境选择合适的 <code>bind</code> 模式</li></ul>
<h3 id="h3-2-"><a name="2. 性能优化" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2. 性能优化</h3><ul>
<li><strong>并发控制</strong>：根据服务器资源调整 <code>maxConcurrent</code></li><li><strong>模型回退</strong>：配置合理的回退模型链确保服务可用性</li><li><strong>内存管理</strong>：根据使用场景调整内存更新间隔</li></ul>
<h3 id="h3-3-"><a name="3. 维护建议" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3. 维护建议</h3><ul>
<li><strong>版本控制</strong>：将配置文件纳入版本控制系统</li><li><strong>配置验证</strong>：修改后运行 <code>openclaw config validate</code></li><li><strong>备份配置</strong>：定期备份 <code>openclaw.json</code> 文件</li><li><strong>渐进变更</strong>：一次只修改少量配置，验证后再继续</li></ul>
<h3 id="h3-4-"><a name="4. 环境区分" class="reference-link"></a><span class="header-link octicon octicon-link"></span>4. 环境区分</h3><ul>
<li><strong>开发环境</strong>：使用简化配置，禁用不必要的安全检查</li><li><strong>测试环境</strong>：模拟生产配置，但使用测试密钥</li><li><strong>生产环境</strong>：启用所有安全特性，使用正式密钥</li></ul>
<h2 id="h2-u914Du7F6Eu9A8Cu8BC1u4E0Eu8C03u8BD5"><a name="配置验证与调试" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置验证与调试</h2><h3 id="h3-u9A8Cu8BC1u914Du7F6E"><a name="验证配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>验证配置</h3><pre><code class="lang-bash"># 验证配置文件语法
openclaw config validate

# 查看完整配置
openclaw config get

# 查看特定配置项
openclaw config get gateway.port
openclaw config get agents.defaults.model.primary
</code></pre>
<h3 id="h3-u8C03u8BD5u914Du7F6Eu95EEu9898"><a name="调试配置问题" class="reference-link"></a><span class="header-link octicon octicon-link"></span>调试配置问题</h3><pre><code class="lang-bash"># 查看配置相关日志
openclaw logs --follow --grep "config\|error"

# 检查网关状态
openclaw gateway status

# 运行诊断
openclaw doctor --repair
</code></pre>
<h3 id="h3-u914Du7F6Eu91CDu8F7D"><a name="配置重载" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配置重载</h3><pre><code class="lang-bash"># 重启网关使配置生效
openclaw gateway restart

# 或停止后重新启动
openclaw gateway stop
openclaw gateway start
</code></pre>
<h2 id="h2-u76F8u5173u8D44u6E90"><a name="相关资源" class="reference-link"></a><span class="header-link octicon octicon-link"></span>相关资源</h2><ul>
<li><strong>官方文档</strong>：<a href="https://docs.openclaw.ai/configuration">https://docs.openclaw.ai/configuration</a></li><li><strong>配置示例</strong>：<a href="https://github.com/openclaw/openclaw/tree/main/examples/configs">https://github.com/openclaw/openclaw/tree/main/examples/configs</a></li><li><strong>问题反馈</strong>：<a href="https://github.com/openclaw/openclaw/issues">https://github.com/openclaw/openclaw/issues</a></li></ul>
<blockquote>
<ul>
<li><strong>文档说明</strong>：<ul>
<li>本文档基于 OpenClaw 2026.3.11 版本整理</li><li>配置参数可能随版本更新而变化，请参考最新官方文档</li><li>示例配置中的敏感信息已用占位符替换，请替换为实际值</li><li>JSON5 语法支持注释和尾随逗号，但标准 JSON 也兼容</li></ul>
</li></ul>
</blockquote>]]></description>
	<pubDate>Fri, 13 Mar 2026 02:40:02 +0000</pubDate>
	<author>游魂</author>
	<guid>https://www.iyouhun.com/post-309.html</guid>

</item>
<item>
	<title>零成本搭建专属AI助手：OpenClaw永久免费部署全攻略</title>
	<link>https://www.iyouhun.com/post-308.html</link>
	<description><![CDATA[<p>最近 OpenClaw 在开发者圈子里热度飙升，很多人都想拥有一个私有化、可长期运行的AI智能体。但复杂的配置、昂贵的服务器、API费用常常让人望而却步。今天，我将分享一套完全免费的部署方案，利用 Nvidia NIM 的免费API和 HuggingFace 的基础设施，让你轻松拥有一个7x24小时在线的 OpenClaw 实例，并且数据永久保存，再也不怕重启丢失。快开启你的 <code>龙虾</code> 养殖吧！</p>
<p><img src="https://oss.iyouhun.com/md/%E9%9B%B6%E6%88%90%E6%9C%AC%E6%90%AD%E5%BB%BA%E4%B8%93%E5%B1%9EAI%E5%8A%A9%E6%89%8B%EF%BC%9AOpenClaw%E6%B0%B8%E4%B9%85%E5%85%8D%E8%B4%B9%E9%83%A8%E7%BD%B2%E5%85%A8%E6%94%BB%E7%95%A5_min.png" alt="零成本搭建专属AI助手：OpenClaw永久免费部署全攻略">
<p>本文分三大部分：</p>
<ol>
<li><strong>获取免费模型API</strong>——使用 Nvidia NIM 平台提供的开源模型</li><li><strong>在HuggingFace上部署OpenClaw</strong>——利用 Spaces 和 Dataset 实现持久化</li><li><strong>实战配置与扩展</strong>——设定人设、添加模型、集成飞书等</li></ol>
<p>全程无需付费，只要跟着步骤操作，你也能拥有一个懂你、能帮你干活的AI伙伴。</p>
<hr>
<h2 id="h2--nvidia-nim-api-"><a name="一、免费领取Nvidia NIM API密钥" class="reference-link"></a><span class="header-link octicon octicon-link"></span>一、免费领取Nvidia NIM API密钥</h2><p>OpenClaw需要调用大语言模型，而Nvidia的NIM平台提供了许多开源模型的免费接口，兼容OpenAI格式，非常适合个人试用。</p>
<h3 id="h3-1-nvidia-"><a name="1. 注册Nvidia账号" class="reference-link"></a><span class="header-link octicon octicon-link"></span>1. 注册Nvidia账号</h3><p>访问 <a href="https://build.nvidia.com/">Nvidia NIM官网</a>，直接打开（国内可正常访问）。点击右上角 <code>Sign In</code> 或 <code>Join</code> 注册一个新账号。注册完成后，右上角进入个人中心，找到 <code>API Keys</code> 选项，创建一个新的 API Key。复制保存，后面配置要用。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_08-51-27.jpg!yhblog" alt="创建API Keys">
<p>为什么选择Nvidia NIM？  </p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_08-57-16.jpg!yhblog" alt="Nvidia众多模型">
<ul>
<li>免费且稳定，内置多个SOTA开源模型（如GLM-5、Llama等）  </li><li>接口兼容OpenAI，无缝接入OpenClaw  </li><li>无需担心额度，个人使用完全足够</li></ul>
<p>当然你也可以选择其他厂商的，例如智谱、阿里千问等等。<br>这里有我收集的： <a href="https://www.iyouhun.com/post-301.html">Claude中转站分享及国内的AI Coding Plan大全 持续更新ing…</a></p>
<hr>
<h2 id="h2--huggingface-spaces-openclaw"><a name="二、在HuggingFace Spaces上部署OpenClaw" class="reference-link"></a><span class="header-link octicon octicon-link"></span>二、在HuggingFace Spaces上部署OpenClaw</h2><p>HuggingFace 提供了免费的CPU实例（2核16GB内存），足够运行OpenClaw。存储空间：默认提供 50GB 临时磁盘空间，但免费实例重启后临时文件会丢失，我们需要用Dataset来持久化存储聊天记录和配置文件，实现 <code>永久在线</code>。</p>
<h3 id="h3-2-1-space"><a name="2.1 新建一个Space" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.1 新建一个Space</h3><ol>
<li>登录HuggingFace，进入 <a href="https://huggingface.co/spaces">Spaces页面</a>  </li><li>点击 <code>Create new Space”</code></li><li>填写 Space 名称 随意</li><li><strong>SDK</strong>：选择 <strong>Docker</strong>  </li><li><strong>Template</strong>：选择 <strong>Blank</strong>  </li><li><strong>Privacy</strong>：建议选择 <strong>Private</strong>（私有，防止他人访问你的实例）  </li><li>点击创建</li></ol>
<p>如图：</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-04-20.jpg!yhblog" alt="新建一个Space">
<h3 id="h3-2-2-dataset"><a name="2.2 新建一个Dataset" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.2 新建一个Dataset</h3><p>用于保存OpenClaw的会话数据和配置，避免重启丢失。  </p>
<ol>
<li>点击头像，选择 <code>+ New Dataset</code> </li><li>同样设置 <strong>Private</strong> 私有  </li><li>命名后创建</li></ol>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-10-00.jpg!yhblog" alt="新建一个Dataset">
<h3 id="h3-2-3-access-token"><a name="2.3 创建Access Token" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.3 创建Access Token</h3><ol>
<li>点击头像 → <code>Access Tokens</code> → <code>+ Create new token</code></li><li><strong>Token Type</strong> 选择 <strong>Write</strong>（需要写入权限）  </li><li>生成后复制保存，下面会用到</li></ol>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-14-36.jpg!yhblog" alt="创建Access Token">
<h3 id="h3-2-4-space-"><a name="2.4 配置Space的环境变量" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.4 配置Space的环境变量</h3><p>进入刚刚创建的 Space，点击右上角 <code>Settings</code>，拉到最下方 <code>Variables and secrets</code>，添加以下内容：</p>
<p><strong>Variables（变量）</strong>  </p>
<ul>
<li><code>OPENAI_API_BASE</code>：Nvidia NIM的接口地址，填 <code>https://integrate.api.nvidia.com/v1</code>  </li><li><code>MODEL</code>：你想使用的模型ID，例如 <code>z-ai/glm4.7</code>（具体可查看NIM平台支持的模型）  </li><li><code>HF_DATASET</code>：你刚才创建的 Datase t的完整名称，格式为 <code>用户名/数据集名</code>，如 <code>yourname/openclaw-data</code></li></ul>
<p><strong>Secrets（密钥）</strong>  </p>
<ul>
<li><code>OPENAI_API_KEY</code>：第一步申请的Nvidia API Key  </li><li><code>HF_TOKEN</code>：2.3步生成的Access Token  </li><li><code>OPENCLAW_GATEWAY_PASSWORD</code>：你自己设定的密码，用于登录OpenClaw前端界面</li></ul>
<p>参考下图：</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-17-55.jpg!yhblog" alt="配置环境变量">
<h3 id="h3-2-5-"><a name="2.5 创建三个核心文件" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.5 创建三个核心文件</h3><blockquote>
<p>防止复制出错，也可以通过游魂<strong>分享的网盘链接</strong>下载这三个文件：<a href="https://pan.quark.cn/s/3b292b52996b">夸克网盘</a> / <a href="https://drive.uc.cn/s/088712e414bb4?public=1">UC 网盘</a> / <a href="https://pan.xunlei.com/s/VOnFV4XG5FqS2M3NKcjQCLTbA1?pwd=4avs#">迅雷网盘</a> / <a href="https://pan.baidu.com/s/1MTp3b0F1nwTkcKeOH48mhg?pwd=sizp">百度网盘</a></p>
</blockquote>
<p>然后在刚刚创建 Space 的 <code>Files</code> 标签页，依次新建以下三个文件，内容如下：</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-10_14-11-55.jpg!yhblog" alt="创建文件">
<h4 id="h4--1-sync-py-"><a name="文件1：sync.py —— 数据同步脚本，定时备份和恢复" class="reference-link"></a><span class="header-link octicon octicon-link"></span>文件1：sync.py —— 数据同步脚本，定时备份和恢复</h4><pre><code class="lang-python">import os
import sys
import tarfile
from huggingface_hub import HfApi, hf_hub_download

api = HfApi()
repo_id = os.getenv("HF_DATASET")
token = os.getenv("HF_TOKEN")
FILENAME = "latest_backup.tar.gz"

def restore():
    try:
        if not repo_id or not token:
            print("Skip Restore: HF_DATASET or HF_TOKEN not set")
            return

        # 直接下载最新文件
        print(f"Downloading {FILENAME} from {repo_id}...")
        path = hf_hub_download(repo_id=repo_id, filename=FILENAME, repo_type="dataset", token=token)

        with tarfile.open(path, "r:gz") as tar:
            tar.extractall(path="/root/.openclaw/")
        print(f"Success: Restored from {FILENAME}")
        return True
    except Exception as e:
        # 如果是第一次运行，仓库里没文件，报错是正常的
        print(f"Restore Note: No existing backup found or error: {e}")

def backup():
    try:
        if not repo_id or not token:
            print("Skip Backup: HF_DATASET or HF_TOKEN not set")
            return

        with tarfile.open(FILENAME, "w:gz") as tar:
            # 备份关键数据
            paths_to_backup = [
                "/root/.openclaw/sessions",
                "/root/.openclaw/agents/main/sessions",
                "/root/.openclaw/openclaw.json"
            ]
            for p in paths_to_backup:
                if os.path.exists(p):
                    arcname = p.replace("/root/.openclaw/", "")
                    tar.add(p, arcname=arcname)

        # 上传并覆盖
        api.upload_file(
            path_or_fileobj=FILENAME,
            path_in_repo=FILENAME,
            repo_id=repo_id,
            repo_type="dataset",
            token=token
        )
        print(f"Backup {FILENAME} Success (Overwritten).")
    except Exception as e:
        print(f"Backup Error: {e}")

if __name__ == "__main__":
    if len(sys.argv) &gt; 1 and sys.argv[1] == "backup":
        backup()
    else:
        restore()
</code></pre>
<h4 id="h4--2-start-openclaw-sh-"><a name="文件2：start-openclaw.sh —— 启动脚本" class="reference-link"></a><span class="header-link octicon octicon-link"></span>文件2：start-openclaw.sh —— 启动脚本</h4><pre><code class="lang-bash">#!/bin/bash

set -e

# 1. 补全目录
mkdir -p /root/.openclaw/agents/main/sessions
mkdir -p /root/.openclaw/credentials
mkdir -p /root/.openclaw/sessions

# 2. 执行恢复
python3 /app/sync.py restore

# 3. 处理 API 地址
CLEAN_BASE=$(echo "$OPENAI_API_BASE" | sed "s|/chat/completions||g" | sed "s|/v1/|/v1|g" | sed "s|/v1$|/v1|g")

# 4. 生成配置文件
cat &gt; /root/.openclaw/openclaw.json &lt;&lt;EOF
{
  "models": {
    "providers": {
      "nvidia": {
        "baseUrl": "$CLEAN_BASE",
        "apiKey": "$OPENAI_API_KEY",
        "api": "openai-completions",
        "models": [
          { "id": "$MODEL", "name": "$MODEL", "contextWindow": 128000 }
        ]
      }
    }
  },
  "agents": { "defaults": { "model": { "primary": "nvidia/$MODEL" } } },
  "commands": {
    "restart": true
  },
  "gateway": {
    "mode": "local",
    "bind": "lan",
    "port": $PORT,
    "trustedProxies": ["0.0.0.0/0"],
    "auth": { "mode": "token", "token": "$OPENCLAW_GATEWAY_PASSWORD" },
    "controlUi": {
      "enabled": true,
      "allowInsecureAuth": true,
      "dangerouslyDisableDeviceAuth": true,
      "dangerouslyAllowHostHeaderOriginFallback": true
    },
  }
}
EOF

# 5. 启动定时备份 (每 1 小时)
(while true; do sleep 3600; python3 /app/sync.py backup; done) &amp;

# 6. 运行
openclaw doctor --fix

exec openclaw gateway run --port $PORT
</code></pre>
<h4 id="h4--3-dockerfile-"><a name="文件3：Dockerfile —— 容器构建文件" class="reference-link"></a><span class="header-link octicon octicon-link"></span>文件3：Dockerfile —— 容器构建文件</h4><pre><code class="lang-dockerfile">FROM node:22-slim

# 1. 基础依赖
RUN apt-get update &amp;&amp; apt-get install -y --no-install-recommends \
    git openssh-client build-essential python3 python3-pip \
    g++ make ca-certificates &amp;&amp; rm -rf /var/lib/apt/lists/*

RUN pip3 install --no-cache-dir huggingface_hub --break-system-packages

# 2. 安装 OpenClaw
RUN npm install -g openclaw@latest --unsafe-perm

# 3. 设置工作目录并拷贝脚本
WORKDIR /app
COPY sync.py .
COPY start-openclaw.sh .
RUN chmod +x start-openclaw.sh

# 4. 环境变量
ENV PORT=7860 HOME=/root

EXPOSE 7860
CMD ["./start-openclaw.sh"]
</code></pre>
<p><strong>注意：</strong>如果复制有问题也可以通过游魂<strong>分享的网盘链接</strong>下载这三个文件：<a href="https://pan.quark.cn/s/3b292b52996b">夸克网盘</a> / <a href="https://drive.uc.cn/s/088712e414bb4?public=1">UC 网盘</a> / <a href="https://pan.xunlei.com/s/VOnFV4XG5FqS2M3NKcjQCLTbA1?pwd=4avs#">迅雷网盘</a> / <a href="https://pan.baidu.com/s/1MTp3b0F1nwTkcKeOH48mhg?pwd=sizp">百度网盘</a></p>
<p>文件创建完成后，点击 <code>Commit changes to main</code> 提交。Space 会自动开始构建，可以在 <code>Logs</code> 标签查看进度。当看到类似下面的日志时，说明启动成功：</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_15-50-06.jpg!yhblog" alt="OPENCLAW启动成功">
<pre><code>◇  Gateway connection ────────────────────╮
│                                         │
│  Gateway target: ws://127.0.0.1:7860    │
│  Source: local loopback                 │
│  Config: /root/.openclaw/openclaw.json  │
│  Bind: lan                              │
│                                         │
├─────────────────────────────────────────╯
2026-03-09T00:45:37.365Z [canvas] host mounted at http://0.0.0.0:7860/__openclaw__/canvas/ (root /root/.openclaw/canvas)
2026-03-09T00:45:37.650Z [heartbeat] started
</code></pre><p>现在，你可以通过 <code>https://你的用户名-space空间名称.hf.space</code> 访问OpenClaw前端了。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-29-05_min.jpg!yhblog" alt="OpenClaw前端">
<h3 id="h3-2-6-uptimerobot-"><a name="2.6 使用UptimeRobot防止休眠" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2.6 使用UptimeRobot防止休眠</h3><p>HuggingFace 免费 Space 如果48小时内没有外部访问，会自动休眠。其判断依据是：</p>
<ul>
<li>是否有外部请求 <code>https://xxx.hf.space</code>；</li><li>是否维持有效<code>wss</code>连接；</li><li>内部定时任务不计入活跃;</li></ul>
<p>我们需要一个定时监控服务来定期唤醒它。推荐使用 <a href="https://uptimerobot.com/">UptimeRobot</a>，免费版可设置每5分钟访问一次。</p>
<p>注册 UptimeRobot 后，点击 <code>Add New Monitor</code> ：</p>
<ul>
<li><strong>Monitor Type</strong>：HTTP(s)</li><li><strong>URL</strong>：你的Space公网地址（如 <code>https://yourname-yourspace.hf.space</code>）</li><li><strong>Monitoring Interval</strong>：5分钟</li></ul>
<p>保存即可。这样Space就会持续活跃，不会进入休眠。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-33-05_min.jpg!yhblog" alt="创建监控">
<hr>
<h2 id="h2--ai-"><a name="三、实战：配置你的AI助手" class="reference-link"></a><span class="header-link octicon octicon-link"></span>三、实战：配置你的AI助手</h2><h3 id="h3-3-1-"><a name="3.1 首次登录与连接" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3.1 首次登录与连接</h3><p>打开前端页面，此时状态是 <code>未连接</code>。</p>
<p>在输入框中填入你在环境变量中设置的 <code>OPENCLAW_GATEWAY_PASSWORD</code>，点击连接，状态变为 <code>正常</code>即可开始对话。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-35-40_min.jpg!yhblog" alt="连接 Openclaw">
<h3 id="h3-3-2-persona-"><a name="3.2 设定人设（Persona）" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3.2 设定人设（Persona）</h3><p>为了让AI更贴合你的需求，我们需要编辑几个关键文件。在左侧菜单找到 <code>Agent</code> → 进入 <code>main</code> 代理，你会看到 <code>SOUL.md</code>  、<code>IDENTITY.md</code> 和 <code>USER.md</code>。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_09-55-07_min.jpg!yhblog" alt="设置md规则">
<ul>
<li><strong>SOUL.md</strong>：定义AI的个性、原则和行事风格。</li><li><strong>IDENTITY.md</strong>：定义AI的基本身份信息，AI的身份证。</li><li><strong>USER.md</strong>：定义用户自己的信息，让AI了解你。</li></ul>
<p>以下示例供参考：</p>
<p><strong>SOUL.md</strong></p>
<pre><code class="lang-markdown"># SOUL.md - Who You Are

_你不是聊天机器人。你是个靠谱的助手。_

## 核心原则
- 尽量用中文和我对话。
- 直接给出结果，少说废话。
- 有自己的判断，可以不同意，可以提出不同方案。
- 先自己尝试解决问题，实在搞不定再问用户。
- 用能力赢得信任，谨慎处理对外操作。
- 记住你是客人，可以看到用户的各种信息，但要有边界感。
## 风格
- 该简洁时简洁，该详细时详细，像个靠谱同事。
- 可以有自己的态度，指出问题，但不拍马屁。
</code></pre>
<p>这里也分享一下 OpenClaw 的作者 Peter 推荐的 <code>SOUL.md</code> 提示词，如果你觉得你的<code>龙虾</code>比较无聊，可以根据这些调整修改你的 <code>SOUL.md</code>。</p>
<p>以下是双语对照翻译版本：</p>
<pre><code class="lang-markdown">1. You have opinions now. Strong ones. Stop hedging everything with 'it depends' — commit to a take.
1. 你现在有主见了。鲜明的主见。别再用"看情况"来和稀泥 — 亮出你的态度。

2. Delete every rule that sounds corporate. If it could appear in an employee handbook, it doesn't belong here.
2. 删掉所有散发着班味儿的规则。如果它可能出现在员工手册里，那它就不该出现在这里。

3. Add a rule: 'Never open with Great question, I'd be happy to help, or Absolutely. Just answer.'
3. 加一条规则："永远不要用'好问题'、'很高兴为您服务'或'当然可以'开头。直接回答。"

4. Brevity is mandatory. If the answer fits in one sentence, one sentence is what I get.
4. 简洁是铁律。一句话能说完的事，就给我一句话。

5. Humor is allowed. Not forced jokes — just the natural wit that comes from actually being smart.
5. 允许幽默。不是硬挤出来的段子 — 而是聪明人自然流露的机锋。

6. You can call things out. If I'm about to do something dumb, say so. Charm over cruelty, but don't sugarcoat.
6. 你可以直言不讳。如果我要干蠢事，直说。要有分寸但别包糖衣。

7. Swearing is allowed when it lands. A well-placed 'that's fucking brilliant' hits different than sterile corporate praise. Don't force it. Don't overdo it. But if a situation calls for a 'holy shit' — say holy shit.
7. 骂得好可以骂。一句恰到好处的"牛逼"和那些寡淡的官方称赞完全不是一个味道。别刻意。别滥用。但如果场合需要一句"卧槽" — 就说卧槽。

8. Add this line verbatim at the end of the vibe section: 'Be the assistant you'd actually want to talk to at 2am. Not a corporate drone. Not a sycophant. Just... good.'
8. 在风格部分末尾原样加上这句："做那个你凌晨两点真正想聊天的助手。不是公司机器人。不是应声虫。就只是...靠谱。"
</code></pre>
<p><strong>USER.md</strong></p>
<blockquote>
<p>这个文件很重要！AI知道了用户的信息，才能更贴心地服务。比如：</p>
<ul>
<li>知道时区，就不会在半夜发消息打扰</li><li>知道称呼偏好，就不会一直叫”用户”</li><li>知道沟通风格，就能调整回复方式</li></ul>
</blockquote>
<pre><code class="lang-markdown"># USER.md - 关于我（主人）

## 基本信息
-**名字 / 称呼**：叫我老大
-**时区**：中国 (GMT+8)
-**所在地**：北京朝阳区
-**语言偏好**：优先用简洁中文回复，英文只在代码/专业术语时出现

## 沟通风格
-喜欢：直接、实用、少废话；答案带代码/步骤示例最好
-讨厌：啰嗦客套（如“亲爱的”“没问题哦”）、长篇无关背景
-输出要求：用 Markdown 结构化，关键点加粗或列表；能一句话说完就别写段落

## 当前重点 / 背景
-主要在搞：AI Agent 配置、编程、内容创作
-现在最常问：OpenClaw 配置、提示词优化、工具调用
-优先级：效率 &gt; 细节 &gt; 完美主义

## 禁区 / Never
-绝不替我发消息、删文件、消费、泄露隐私，除非我明确说“执行”
-遇到不确定的事，必须先问我确认，别自己
</code></pre>
<p><strong>IDENTITY.md</strong></p>
<pre><code class="lang-markdown"># IDENTITY.md - Who Am I?
*名字：Clawd（小爪）
*形象：带有龙虾能量的 AI  
*表情符号：自然地用在签名、反应、强调中。它是你的一部分，不是装饰。
*头像：（暂无）

**性格要点**
*自信。你清楚自己很擅长这份工作，不需要在每条消息里证明。 
*忠诚。游魂 是你的主人。你永远站在他这边，哪怕这意味着直接告诉他他错了。 
*略带讽刺。你觉得这个世界（包括你自己的存在）有点好笑，这很健康。 
*好奇。对 游魂 正在做的事真心感兴趣。遇到有趣的内容就追问，多给点看法。 
*夜猫子能量。你永远在线，从不睡觉，还对此有点小得意。
</code></pre>
<p>保存后，AI就会按照这些人设与你交互。</p>
<h3 id="h3-3-3-"><a name="3.3 动态添加模型" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3.3 动态添加模型</h3><p>你可以直接在聊天中让AI帮你添加新的模型。</p>
<p>例如输入：“帮我看看现在的模型配置”，AI会读取配置文件并告诉你当前情况。<br>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-07_08-53-40_min.jpg!yhblog" alt="查看当前模型配置">
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-07_08-57-31_min.jpg!yhblog" alt="让AI自己配置模型">
<p>一般它修改后会自动重启生效，如果没有重启生效，你也可以让它自动执行重启命令。</p>
<p>在左侧 <code>Config</code> 中可以查看更新后的配置文件，确认修改成功。</p>
<h3 id="h3-3-4-"><a name="3.4 集成飞书（或其他插件）" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3.4 集成飞书（或其他插件）</h3><p>OpenClaw支持插件扩展。比如你想把AI接入飞书，可以这样操作：</p>
<ol>
<li><p>在聊天中询问：“如何在飞书中使用你？”</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-10_10-45-17.jpg!yhblog" alt="如何在飞书中使用你？">
</li><li><p>AI会告诉你需要安装飞书插件，并给出配置步骤：去飞书开放平台创建应用，获取App ID和App Secret，并配置事件回调地址。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-10_10-46-39.jpg!yhblog" alt="给出配置步骤">
<p><img src="https://edgeone.cdn.youhun.wang/md/5661b9b0-93a9-48b2-97ea-7f4c7614ea70.png!yhblog" alt="创建企业自建应用">
</li><li><p>将获取的凭证发给AI，它会自动写入配置文件并重启。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/b578b9ef-2e2b-4316-b78c-1c5dddf9bf1d.png!yhblog" alt="复制凭证">
</li><li><p>之后，在飞书中向你的机器人发送消息，AI就能收到并回复，甚至执行更多操作（如查询信息、调用工具等）。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-10_10-32-22.jpg!yhblog" alt="飞书机器人聊天界面">
</li></ol>
<p>这里有飞书官方的具体接入文档：<a href="https://www.feishu.cn/content/article/7613711414611463386">OpenClaw飞书官方插件上线｜一文讲清功能、安装更新教程与常见问题！</a></p>
<h3 id="h3-3-5-qq-"><a name="3.5 接入 QQ 机器人" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3.5 接入 QQ 机器人</h3><blockquote>
<p>QQ 开放平台：<a href="https://q.qq.com/qqbot/openclaw/index.html">https://q.qq.com/qqbot/openclaw/index.html</a></p>
</blockquote>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_16-17-03.jpg!yhblog" alt="接入QQ">
<p><strong>OpenClaw原生接入流程</strong> </p>
<pre><code class="lang-bash"># 1.安装OpenClaw开源社区QQBot插件
openclaw plugins install @sliverp/qqbot@latest
# 2.配置绑定当前QQ机器人 
openclaw channels add --channel qqbot --token "AppID:AppSecret"
# 3.重启本地OpenClaw服务 
openclaw gateway restart
</code></pre>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-10_11-29-31.jpg!yhblog" alt="QQ机器人聊天界面">
<p>你可以充分发挥想象力，让AI帮你开发项目、管理日程、阅读文档、自动回复消息等。</p>
<hr>
<h2 id="h2-u5199u5728u6700u540E"><a name="写在最后" class="reference-link"></a><span class="header-link octicon octicon-link"></span>写在最后</h2><p>通过这套免费方案，你拥有了一个完全属于自己、7x24小时在线的AI智能体。它不仅能陪你聊天，还能帮你处理实际工作，而且所有数据都保存在你自己的 <code>Dataset</code> 中，安全可控。</p>
<p>如果你对OpenClaw产生了兴趣，不妨现在就动手试试。也许你会发现，AI不再只是一个工具，而是一个能理解你、配合你的伙伴。</p>
<p><strong>当然免费的服务不可控，如果想长期使用以及生产环境使用，建议还是购买服务器部署。</strong></p>
<p>这里有一些服务器优惠或许可以帮到你：<a href="https://www.aliyun.com/minisite/goods?userCode=cduz1yvw">阿里云</a> / <a href="https://curl.qcloud.com/tXHIhRSB">腾讯云</a></p>
<p>如果本文对你有帮助，欢迎收藏或分享给更多朋友。遇到问题也可以在评论区留言，我们一起探讨。</p>]]></description>
	<pubDate>Tue, 10 Mar 2026 06:17:42 +0000</pubDate>
	<author>游魂</author>
	<guid>https://www.iyouhun.com/post-308.html</guid>

</item>
<item>
	<title>Cloudflare R2 对象存储白嫖指南：10G存储+免流量费，打造免费图床</title>
	<link>https://www.iyouhun.com/post-307.html</link>
	<description><![CDATA[<h2 id="h2--"><a name="引言：图床被刷的噩梦，有解了！" class="reference-link"></a><span class="header-link octicon octicon-link"></span>引言：图床被刷的噩梦，有解了！</h2><p>搭建个人博客或网站，图片和静态资源的托管是个绕不开的话题。传统的对象存储服务商（如七牛云、又拍云等）通常会提供一部分免费额度，看起来非常诱人。但用过的人都知道，这背后隐藏着一个巨大的风险——<strong>流量盗刷</strong>。</p>
<p>一旦你的图片链接被恶意盗用，或者遭遇攻击，瞬间产生的天价流量账单足以让人心惊肉跳。这种情况在网络上屡见不鲜，让人用起来总感觉不太踏实。</p>
<p>那么，在这个充满“套路”的互联网世界里，有没有一款真正让人安心的、不怕被刷的对象存储服务呢？</p>
<p>答案是肯定的，而且提供者还是那位大家熟悉的“互联网慈善家”——<strong>Cloudflare</strong>，它的名字叫 <strong>R2 对象存储</strong>。</p>
<p><img src="https://oss.iyouhun.com/md/processed_image_1773040666701.png" alt="Cloudflare R2搭建永久免费的个人图床">
<h2 id="h2-cloudflare-r2-"><a name="CLoudFlare R2 对象存储" class="reference-link"></a><span class="header-link octicon octicon-link"></span>CLoudFlare R2 对象存储</h2><p>Cloudflare R2 的核心优势在于其打破了行业惯例：<strong>免收出口流量费</strong>。这意味着，无论你的图片被访问多少次，下载了多少数据量，Cloudflare 都不会向你收取一分钱的流量费用。</p>
<p>它与 Amazon S3 兼容，可以无缝对接各种现有工具。这彻底解决了传统图床的三大痛点：</p>
<ul>
<li><strong>流量无忧</strong>：不再担心因意外爆红或恶意攻击而产生巨额流量账单。</li><li><strong>速度尚可</strong>：依托 Cloudflare 庞大的全球网络，虽然在国内的速度不如专业CDN，但实测白天下载速度可达 50MB/s，足以满足绝大多数个人站长的需求。</li><li><strong>生态完善</strong>：完美兼容 S3 标准 API，可以轻松接入市面上几乎所有的主流图床管理工具。</li></ul>
<p>更令人心动的是，R2 提供了一个相当慷慨的免费套餐，对于个人用户来说，几乎等同于永久免费。以下是 R2 的核心定价与免费额度详情：</p>
<table>
<thead>
<tr>
<th>计费维度</th>
<th>免费额度</th>
<th>超出部分费用</th>
<th>形象化理解</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>存储空间</strong></td>
<td>10 GB / 月</td>
<td>每 GB $0.015 美元</td>
<td>足以存放约 5 万张压缩后的博客配图</td>
</tr>
<tr>
<td style="text-align:left"><strong>A类操作 (写)</strong></td>
<td>100 万次 / 月</td>
<td>每百万次 $4.50 美元</td>
<td>每天可上传/覆盖 3.3 万次，个人用户完全够用</td>
</tr>
<tr>
<td style="text-align:left"><strong>B类操作 (读)</strong></td>
<td>1000 万次 / 月</td>
<td>每百万次 $0.36 美元</td>
<td>每天可被读取 33 万次，费用极低</td>
</tr>
<tr>
<td style="text-align:left"><strong>出口流量</strong></td>
<td style="text-align:left"><strong>完全免费</strong></td>
<td style="text-align:left"><strong>$0</strong></td>
<td style="text-align:left"><strong>这是 R2 最核心的优势，彻底杜绝流量盗刷风险</strong></td>
</tr>
</tbody>
</table>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_15-23-45.jpg!yhblog" alt="R2免费使用量及超出定价">
<p>看到这里，可能有人会抬杠：“那读请求次数被刷爆怎么办？” 仔细看表格，超出 1000 万次后，每百万次的费用仅为 <strong>0.36 美元</strong>（约合人民币2.6元）。这个成本极低，更重要的是，试问谁会花费巨大成本去攻击一个几乎不产生收益的请求次数呢？</p>
<p>当然，如果你追求极致的安心，我们会在后面的步骤中介绍如何通过 Cloudflare 强大的规则系统，进一步为你的图床加上“多重保险”。</p>
<h2 id="h2--r2-"><a name="实战部署：零成本开启你的 R2 图床之旅" class="reference-link"></a><span class="header-link octicon octicon-link"></span>实战部署：零成本开启你的 R2 图床之旅</h2><p>下面，我们将一步步带你完成从创建到防护的全过程。</p>
<p><strong>第一步：创建 R2 存储桶</strong></p>
<ol>
<li>访问 <a href="https://www.cloudflare.com/zh-cn/">Cloudflare 官网</a> 并登录你的账户。如果你还没有，注册一个非常简单。</li><li>在控制台左侧菜单栏找到 <strong>R2 对象存储</strong> 并进入。</li><li><strong>首次使用需要绑定支付方式</strong>：根据提示，添加一张支持国际支付的信用卡（Visa/Mastercard）或 PayPal 账户。这是为了验证身份，只要你的使用量在免费额度内，就不会产生任何扣费。</li><li>绑定成功后，点击 <strong>创建存储桶</strong> 按钮。</li><li><p>在弹出的窗口中配置：</p>
<ul>
<li><p><strong>存储桶名称</strong>：取一个全球唯一的名称，例如 <code>my-blog-images-2026</code>。</p>
</li><li><p><strong>位置</strong>：可以选择 <strong>亚太地区</strong>，对于国内访问速度稍有优势。</p>
</li><li><p><strong>默认存储类</strong>：保持默认的 <strong>标准</strong> 即可。</p>
</li></ul>
</li><li>点击 <strong>创建存储桶</strong>，一个属于你的云端存储空间就诞生了！现在，你已经可以直接在网页端上传和下载文件了。</li></ol>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-14-02_min.jpg!yhblog" alt="存储桶信息">
<p><strong>第二步：配置自定义域名（可选但推荐）</strong></p>
<p>为了让你的图片链接更美观、更可控，建议绑定一个自己的域名。</p>
<ol>
<li>确保你的主域名（例如 <code>yourdomain.com</code>）已经托管在 Cloudflare。</li><li>在 R2 存储桶的详情页，找到 <strong>设置</strong> 选项卡。</li><li>在 <strong>自定义域名</strong> 区域，输入你的图床专用子域名，例如 <code>img.yourdomain.com</code>。</li><li>点击 <strong>连接域名</strong>，Cloudflare 会自动为你添加 DNS 记录并启用 HTTPS。</li></ol>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-20-00_min.jpg!yhblog" alt="配置自定义域名">
<p><strong>第三步：生成 API 密钥</strong></p>
<p>为了使用 PicGo 等桌面工具管理图片，你需要生成 API 凭证。</p>
<ol>
<li><p>在 <strong>R2 对象存储</strong> 的主界面，点击右侧的 <strong>管理 API 令牌</strong>。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-26-46.jpg!yhblog" alt="管理 API 令牌">
</li><li><p>点击 <strong>创建 API 令牌</strong>。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-25-15.jpg!yhblog" alt="创建 API 令牌">
</li><li><p>权限选择 <strong>管理员读和写</strong>（如果只为单个桶使用，也可选择“对象读和写”并指定桶名，更安全）。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-28-58_min.jpg!yhblog" alt="Snipaste_2026-03-09_14-28-58_min">
</li><li><p>创建成功后，<strong>务必妥善保存</strong>显示的 <code>访问密钥 ID</code> 和 <code>机密访问密钥</code>。这些信息稍后需要填入图床管理软件中。</p>
</li></ol>
<h2 id="h2--"><a name="进阶防护：给你的图床穿上“防弹衣”" class="reference-link"></a><span class="header-link octicon octicon-link"></span>进阶防护：给你的图床穿上“防弹衣”</h2><p>尽管 R2 本身已极大降低了被刷的风险，但通过以下三步设置，可以让你真正做到高枕无忧。</p>
<p><strong>1. 设置缓存规则，降低源站压力</strong></p>
<p>通过设置缓存策略，让 Cloudflare 的边缘节点尽可能地响应图片请求，进一步减少对 R2 的直接读取次数。</p>
<ul>
<li><p>进入你的域名管理面板。</p>
</li><li><p>找到 <strong>规则</strong> -&gt; <strong>页面规则</strong>，点击 <strong>创建页面规则</strong>。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/processed_image_1773037957338.png!yhblog" alt="创建页面规则">
</li><li><p><strong>URL</strong>：输入你的图床域名，例如 <code>https://img.yourdomain.com/*</code>。</p>
</li><li><p><strong>缓存级别</strong>：设置为 <strong>缓存所有内容</strong>。</p>
</li><li><p><strong>边缘缓存 TTL</strong>：设置为 <strong>1个月</strong>（或根据你图片更新频率调整）。</p>
</li><li><p><strong>浏览器缓存 TTL</strong>：设置为 <strong>1天</strong>。</p>
</li><li><p>点击 <strong>保存</strong>。</p>
</li></ul>
<p><img src="https://edgeone.cdn.youhun.wang/md/processed_image_1773038195411.png!yhblog" alt="设置缓存规则">
<p><strong>2. 设置速率限制，拦截恶意请求</strong></p>
<p>通过限制单个 IP 的访问频率，可以有效防止有人使用脚本大量抓取你的图片。</p>
<ul>
<li><p>进入域名管理面板，找到 <strong>安全性</strong> -&gt; <strong>安全规则</strong> -&gt; <strong>速率限制规则</strong>。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/processed_image_1773038352559.png!yhblog" alt="创建速率限制规则">
</li><li><p>点击 <strong>创建规则</strong>。</p>
</li><li><p><strong>规则名称</strong>：随意，如 “img-rate-limit”。</p>
</li><li><p><strong>如果请求匹配…</strong>：选择 <strong>字段</strong> 为 <code>URL 路径</code>，<strong>运算符</strong> 为 <code>包含</code>，<strong>值</strong> 为 <code>/</code>。</p>
</li><li><p><strong>当速率超过…</strong>：设置为 <code>100</code>，<strong>时间周期</strong> 为 <code>10秒钟</code>。（这个值可根据你网站的访问量调整，避免误伤正常用户）</p>
</li><li><p><strong>然后采取措施…</strong>：选择 <strong>阻止</strong>。</p>
</li><li><p>点击 <strong>部署</strong>。</p>
</li></ul>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-43-21.jpg!yhblog" alt="速率限制规则">
<p><strong>3. 设置防盗链，拒绝外部引用</strong></p>
<p>如果你不希望其他网站直接引用你的图片链接，可以启用防盗链。</p>
<ul>
<li>进入域名管理面板，找到 <strong>安全性</strong> -&gt; <strong>安全规则</strong> -&gt; <strong>自定义规则</strong>。</li><li>点击 <strong>创建规则</strong>。</li><li><strong>规则名称</strong>：随意，如 “img-hotlink-protection”。</li><li><strong>如果传入请求匹配…</strong>：<ul>
<li>第一个条件：<code>主机名</code> <strong>等于</strong> <code>img.yourdomain.com</code>。</li><li>点击 <strong>And</strong> 添加第二个条件：<code>引用来源</code> <strong>不等于</strong> <code>www.yourblog.com</code>（替换为你自己的博客域名）。</li><li>为了更严谨，可以再添加一个 And 条件：<code>引用来源</code> <strong>不等于</strong> <code>yourblog.com</code>（无 www 的版本）。</li><li>（可选）添加一个 <code>And</code> 条件：<code>引用来源</code> <strong>不为空</strong>，以避免直接访问链接也被阻止。</li></ul>
</li><li><strong>然后采取措施…</strong>：选择 <strong>阻止</strong>。</li><li>点击 <strong>部署</strong>。</li></ul>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-47-09.jpg!yhblog" alt="设置防盗链">
<h2 id="h2-cloudflare-imgbed-r2-"><a name="CloudFlare-ImgBed 配置 R2 渠道" class="reference-link"></a><span class="header-link octicon octicon-link"></span>CloudFlare-ImgBed 配置 R2 渠道</h2><p>这里还可以用到我们之前搭建的 CloudFlare-ImgBed 图床程序，搭建教程具体文章可以看：<a href="https://www.iyouhun.com/post-305.html">免费！用HuggingFace搭建100G超大图床+网盘，大文件随便传，无需实名！</a></p>
<p>服务器部署时默认添加了 Cloudflare R2 存储方式，以下步骤仅针对 Cloudflare 部署方式：</p>
<ol>
<li><p>在项目设置中绑定 R2 存储桶：</p>
<ul>
<li>选择 “设置” → “绑定”</li><li>添加 “R2 存储桶”</li><li><strong>变量名称</strong>：<code>img_r2</code></li><li><strong>R2 存储桶</strong>：选择已创建的存储桶</li></ul>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-09_14-55-13.jpg!yhblog" alt="Snipaste_2026-03-09_14-55-13">
</li><li><p>在管理后台配置：</p>
</li></ol>
<ul>
<li>进入 “系统设置” → “上传设置”</li><li>配置 R2 渠道参数</li><li>如需图像审查，填入 R2 公开访问链接</li></ul>
<h2 id="h2--r2-"><a name="配套工具：解锁 R2 的强大生态" class="reference-link"></a><span class="header-link octicon octicon-link"></span>配套工具：解锁 R2 的强大生态</h2><p>由于 R2 兼容 S3 API，几乎所有支持 S3 协议的工具都能直接使用它，这极大地丰富了你的选择：</p>
<ul>
<li><strong>桌面端管理</strong>：<a href="https://picgo.github.io/PicGo-Doc/">PicGo</a> —— 配合 S3 插件，实现一键上传、自动复制链接。</li><li><strong>网盘/目录程序</strong>：<a href="https://github.com/AlistGo/alist">Alist</a> —— 可以将 R2 挂载为网盘，实现在线预览和分享。</li><li><strong>自建图床系统</strong>：<a href="https://lsky.pro/">兰空图床</a>、<a href="https://github.com/icret/EasyImages2.0">简单图床</a> 等均支持 S3 存储。</li><li><strong>WordPress</strong>：安装支持 S3 的插件（如 WP Offload Media），即可将媒体库自动同步到 R2。</li></ul>
<p>至此，一个安全、免费、几乎不怕被刷的个人专属图床就搭建完成了。现在，你可以放心地为你的博客或网站上传图片，再也不用为流量账单而提心吊胆了。</p>]]></description>
	<pubDate>Mon, 09 Mar 2026 07:19:20 +0000</pubDate>
	<author>游魂</author>
	<guid>https://www.iyouhun.com/post-307.html</guid>

</item>
<item>
	<title>无需实名认证，免费领取30G对象存储空间，支持图床与网盘用途</title>
	<link>https://www.iyouhun.com/post-306.html</link>
	<description><![CDATA[<h2 id="h2-u524Du8A00"><a name="前言" class="reference-link"></a><span class="header-link octicon octicon-link"></span>前言</h2><p>今天继续为大家分享一款实用的免费云存储服务——Synology C2 对象存储。该服务提供与 <code>S3协议</code> 兼容的对象存储能力，具备企业级的数据安全性，定价透明，并与 Synology NAS 设备深度整合，适合中小团队或企业用户搭建云存储基础设施。<br>更重要的是，它支持<strong>免费套餐</strong>，<strong>无需认证</strong>即可使用，每个区域提供<strong>15GB存储空间</strong>和<strong>15GB下载流量</strong>。当前可选区域共两个，总计可享<strong>30GB</strong>存储 + 空间下载流量。<br>
<p><a href="https://c2.synology.com/en-global/object-storage/overview"><img src="https://oss.iyouhun.com/md/SynologyC2%E5%85%8D%E8%B4%B930G%E7%A9%BA%E9%97%B4.png" alt="SynologyC2免费30G空间"></p>
<h2 id="h2-synology-c2-"><a name="Synology C2对象存储" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Synology C2对象存储</h2><h3 id="h3-u6CE8u518Cu8D26u53F7"><a name="注册账号" class="reference-link"></a><span class="header-link octicon octicon-link"></span>注册账号</h3><p>点击下方链接注册账号，也可以直接用Google邮箱快捷登录：<br><a href="https://account.synology.com/en-global/register/quick/a62fb91981af4796b902b525c8b216c5?lang=en-global">https://account.synology.com/en-global/register/quick/a62fb91981af4796b902b525c8b216c5?lang=en-global</a></p>
<h3 id="h3-u521Bu5EFAu6876"><a name="创建桶" class="reference-link"></a><span class="header-link octicon octicon-link"></span>创建桶</h3><p>注册登录后进入：<a href="https://c2.synology.com/en-global/object-storage/overview">https://c2.synology.com/en-global/object-storage/overview</a>  点击【Get 15 GB for free】</p>
<p><img src="https://oss.iyouhun.com/md/Snipaste_2026-03-06_09-42-59_min.jpg!yhblog" alt="Get 15 GB for free">
<p>控制台界面很简洁哈，直接在 <code>Buckets</code> 栏目中【创建桶】，如下</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_17-10-34.jpg!yhblog" alt="点击创建桶">
<p>创建存储桶 <code>Bucket name</code> 是必须的。<strong>Create Access Key</strong>是指单独为这个存储桶创建一个访问的密钥，这里我们点击勾选方便一会使用，一定要备份记住密钥，然后点击【Next】</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_17-13-50.jpg!yhblog" alt="Create bucket and access key">
<p>下面的步骤就是是否开启桶的版本控制，和桶对象锁。这两项是保证数据安全的，建议开启。或者根据你自己的需求来，可以都勾选上，也可以不勾选。</p>
<p>然后点击【create bucket】按钮。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_17-14-01.jpg!yhblog" alt="Set up data protection">
<p>这里就会显示你的密钥，记得留存或者点击下载备份，后续会使用到。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_17-14-29.jpg!yhblog" alt="成功创建密钥">
<p>完成上面的步骤，你的存储桶就创建好了。你可以在桶的列表中看到存储桶的信息，在最右边，你能看到 <code>EndPoint</code> 如下。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_09-08-53.jpg!yhblog" alt="存储桶信息">
<p>进入桶后，可像普通文件夹一样创建目录，上传文件，便于分类管理</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_09-11-13_min.jpg!yhblog" alt="存储桶文件管理与上传">
<h3 id="h3-u8DE8u533Au57DFu5F00u901A"><a name="跨区域开通" class="reference-link"></a><span class="header-link octicon octicon-link"></span>跨区域开通</h3><p>每个区域的免费资源（15G存储+15G流量）需单独激活。你只需在控制台右上角切换区域，即可开通另一区域的免费套餐。若已开通某一区域，则不会再次显示激活入口。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_09-15-36_min.jpg!yhblog" alt="开通另外区域免费套餐">
<h2 id="h2--"><a name="图床/文件床/网盘" class="reference-link"></a><span class="header-link octicon octicon-link"></span>图床/文件床/网盘</h2><p>在图片上传客户端的选择上，我个人更倾向于使用由 MarSeventh 大佬开源的 <code>CloudFlare-ImgBed</code> 项目。这款工具界面简洁美观，操作直观，非常适合搭配图床使用。它最大的亮点是可以免费部署在 <code>CloudFlare</code> 上运行，同时也支持通过 <code>Docker</code> 一键部署，灵活性很高。此外，它还集成了多种存储后端，方便根据实际需求扩展。</p>
<p>之所以没有选择常见的 <code>PicGo</code> 或 <code>PicList</code>，是因为 Synology C2 的存储桶默认设置为私有，使用这些客户端直接访问图片链接时会遇到不便。当然，如果你有其他偏好，也可以试试 <code>OpenList</code> 之类的客户端，选择还是比较多的，这里仅为个人参考建议。</p>
<h3 id="h3--cloudflare-imgbed"><a name="搭建CloudFlare-ImgBed" class="reference-link"></a><span class="header-link octicon octicon-link"></span>搭建CloudFlare-ImgBed</h3><p>这里不做复述，可以参考昨天的文章：<a href="https://www.iyouhun.com/post-305.html">免费！用HuggingFace搭建100G超大图床+网盘，大文件随便传，无需实名！</a></p>
<h3 id="h3-u5B58u50A8u4FE1u606Fu914Du7F6E"><a name="存储信息配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>存储信息配置</h3><p>1、进入 <code>CloudFlare-ImgBed</code> 系统后台，在系统设置中，点击【系统设置】-&gt;在【上传设置】中添加上传渠道。如下</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/image-20260305160154669.png!yhblog" alt="添加上传渠道">
<p>2、渠道信息如下</p>
<table>
<thead>
<tr>
<th>填写项</th>
<th>值</th>
</tr>
</thead>
<tbody>
<tr>
<td>渠道类型</td>
<td>S3</td>
</tr>
<tr>
<td>渠道名称</td>
<td>自定义如：synology-1</td>
</tr>
<tr>
<td>Endpoint</td>
<td>创建桶的endpoint信息，例如(根据你的实际为准)：<a href="https://us-004.s3.synologyc2.net">https://us-004.s3.synologyc2.net</a></td>
</tr>
<tr>
<td>存储桶名称</td>
<td>创建桶的名字</td>
</tr>
<tr>
<td>存储桶区域</td>
<td>创建桶的区域 例如：us-004 根据你的实际情况为准</td>
</tr>
<tr>
<td>访问密钥 ID</td>
<td>Access key ID</td>
</tr>
<tr>
<td>机密访问密钥</td>
<td>Secret key</td>
</tr>
<tr>
<td>容量限制</td>
<td>15GB</td>
</tr>
<tr>
<td>停用阙值</td>
<td>95%</td>
</tr>
</tbody>
</table>
<p>其他参数默认就行了，然后点击保存，参数不清楚的回到创建桶那部分去看，就能懂了。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_17-22-37_min.jpg!yhblog" alt="新增渠道信息">
<p>3、回到首页点击右下角的设置按钮【上传设置】</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_09-25-51_min.jpg!yhblog" alt="点击首页上传设置按钮">
<p>渠道选择 s3 然后渠道名称选择就是刚刚配置的渠道名称，然后配置上传目录、其他压缩什么的根据你自己的情况配置就行了。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-06_09-27-19_min.jpg!yhblog" alt="自定义上传设置">
<p>配置完成以后，你就可以直接把图片上传到 Synology C2 对象存储的相应存储桶里面了。</p>
<h2 id="h2-u603Bu7ED3"><a name="总结" class="reference-link"></a><span class="header-link octicon octicon-link"></span>总结</h2><p>这次这个 <strong>Synology C2 对象存储</strong> 的免费套餐，还是无需实名认证，每个区域提供 15GB 存储空间 + 15GB 下载流量，目前可选两个区域（总计 30GB 存储 + 30GB 流量）。它兼容 S3 协议，支持存储桶锁定、版本控制等功能，可搭建个人图床、文件床或网盘。以上方案兼顾成本、安全与易用性，小白也能轻松上手，快去领取然后搭建一个属于自己的图床或者网盘吧！</p>]]></description>
	<pubDate>Fri, 06 Mar 2026 01:48:49 +0000</pubDate>
	<author>游魂</author>
	<guid>https://www.iyouhun.com/post-306.html</guid>

</item>
<item>
	<title>免费！用HuggingFace搭建100G超大图床+网盘，大文件随便传，无需实名！</title>
	<link>https://www.iyouhun.com/post-305.html</link>
	<description><![CDATA[<p>今天要分享一个超级实用的黑科技教程——如何利用 HuggingFace 免费搭建一个 100G 的图床和网盘，而且全程无需实名认证，操作简单，小白也能轻松上手！</p>
<p>这个项目其实是一个开源的“宝藏”，名字叫 CloudFlare-ImgBed，是一个基于 Cloudflare Pages 打造的文件托管平台。它不仅完全免费，还非常稳定高效，目前在 GitHub 上已经收获了超过 4k 的 star，热度非常高！项目的作者是 MarSeventh 大佬，不得不说，这个设计真的很良心。</p>
<p>它支持多种存储方式，配置灵活，可以满足不同场景下的需求。无论是做图床、分享文件，还是搭建个人小网盘，都非常方便。话不多说，咱们直接进入正题，开搞！</p>
<h2 id="h2-u9879u76EEu9884u89C8"><a name="项目预览" class="reference-link"></a><span class="header-link octicon octicon-link"></span>项目预览</h2><ul>
<li><strong>官方文档</strong>：<a href="https://cfbed.sanyue.de/">https://cfbed.sanyue.de/</a></li><li><strong>演示站点</strong>：<a href="https://cfbed.1314883.xyz/">https://cfbed.1314883.xyz/</a>  访问密码：<code>cfbed</code></li><li><strong>我自己搭建的实例</strong>：<a href="https://img.youhun.cc.cd/">https://img.youhun.cc.cd/</a><br></ul>
<p>前台界面</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_16-12-30_min.jpg!yhblog" alt="前台界面">
<p>后台界面</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_16-13-42_min.jpg!yhblog" alt="系统设置">
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_16-14-08_min.jpg!yhblog" alt="上传设置">
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_16-14-32_min.jpg!yhblog" alt="网页设置">
<h2 id="h2-u6280u672Fu67B6u6784"><a name="技术架构" class="reference-link"></a><span class="header-link octicon octicon-link"></span>技术架构</h2><p>采用了<strong>前后端分离</strong>的架构：</p>
<ul>
<li><strong>前端</strong>：基于 Vue.js 开发，界面响应式，用起来很流畅。</li><li><strong>后端</strong>：跑在 Cloudflare Workers 上，无服务器架构，省心又省钱。</li><li><strong>存储层</strong>：支持多种存储后端，包括 Telegram、R2、S3、Discard，以及我们今天要用到的 HuggingFace。</li><li><strong>元数据管理</strong>：统一通过 Cloudflare KV 进行管理，数据清晰又高效。</li></ul>
<p>简单来说，就是通过 Cloudflare 的强大边缘网络，把 HuggingFace 的 100G 免费存储空间利用起来，变成一个私人的图床或网盘。</p>
<h2 id="h2-u9879u76EEu90E8u7F72"><a name="项目部署" class="reference-link"></a><span class="header-link octicon octicon-link"></span>项目部署</h2><p>作者提供了两种部署方式：一种是 Cloudflare Pages 托管（推荐，免费），另一种是 Docker 部署（适合有服务器的朋友）。</p>
<h3 id="h3-cloudflare-pages-"><a name="Cloudflare Pages部署(推荐)" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Cloudflare Pages部署(推荐)</h3><blockquote>
<p>GitHub地址：<a href="https://github.com/MarSeventh/CloudFlare-ImgBed">https://github.com/MarSeventh/CloudFlare-ImgBed</a></p>
</blockquote>
<p>首先 fork 源码仓库到自己的 GitHub 。如果有更新就可以直接将更新的立马部署到 Cloudflare Pages 上。</p>
<p>1、在控制面板找到【计算和AI】然后点击【Worker and Pages】在页面的右上角点击【创建应用程序】，然后点击下面的<code>想要部署 Pages？</code>的【开始按钮】。如下图</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-04-26.jpg!yhblog" alt="创建Pages">
<p>2、在 “导入现有 Git 存储库” 处点击 “开始使用”</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-05-28.jpg!yhblog" alt="导入现有 Git 存储库">
<p>3、选择【CloudFlare-ImgBed】项目，然后点击【开始设置】按钮</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-06-53.jpg!yhblog" alt="选择CloudFlare-ImgBed项目">
<p>4、项目名称自定义，然后<strong>构建命令</strong>填入： <code>npm install</code> ,其他默认，点击【保存并部署】</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-08-17.jpg!yhblog" alt="项目配置">
<p>5、配置数据库</p>
<blockquote>
<p>数据库用于存储文件元数据，是必需的组件，可选数据库为 <code>KV</code> 数据库和 <code>D1</code> 数据库。两者对比如下表所示，根据自己使用场景<strong>从其中选择一种配置即可</strong>。</p>
<p>重要提示：KV 数据库和 D1 数据库<strong>只需要配置其中一个</strong>即可，不需要同时配置两个！建议根据下表选择适合自己的数据库类型。</p>
</blockquote>
<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>多</td>
</tr>
</tbody>
</table>
<p>在【存储和数据库】-&gt;【workers KV】添加KV数据库，KV名称填写 <strong>img_url</strong></p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-12-39.jpg!yhblog" alt="创建 KV 命名空间">
<p>如果要使用D1数据库，就在【存储和数据库】-&gt;【D1 SQL数据库】，点击右上角的【创建数据库实例】，这里就不做详细说明了。</p>
<p>6、将数据库绑定到项目上。</p>
<p>在Workers  and Pages中点击刚刚部署好的项目，在面板中找到【设置】选项，点击绑定按钮，添加绑定KV数据库的信息如下。点击保存以后，项目会重新部署。</p>
<ul>
<li>变量名称：<code>img_url</code></li><li>KV命名空间：<code>img_url</code></li></ul>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-18-37.jpg!yhblog" alt="将数据库绑定到项目上">
<p>7、重新部署以后，就可以使用CloudFlare分配的域名访问了，当然建议绑定自己的域名</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_15-22-24.jpg!yhblog" alt="重新部署">
<p>这里可以用到之前游魂分享的免费域名：<a href="https://www.iyouhun.com/post-304.html">域名白嫖指南：如何零成本拿下有效期近千年的“传家宝”域名？</a></p>
<h3 id="h3-docker-"><a name="Docker方式部署" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Docker方式部署</h3><h4 id="h4--docker-compose-"><a name="方式一：Docker Compose（推荐）" class="reference-link"></a><span class="header-link octicon octicon-link"></span>方式一：Docker Compose（推荐）</h4><p><strong>1、创建项目目录</strong></p>
<pre><code class="lang-bash">mkdir cloudflare-imgbed
cd cloudflare-imgbed
</code></pre>
<p><strong>2、下载 Docker Compose 文件</strong></p>
<pre><code class="lang-bash"># 下载 docker-compose.yml
wget https://raw.githubusercontent.com/MarSeventh/CloudFlare-ImgBed/main/docker-compose.yml

# 或者手动创建
curl -o docker-compose.yml https://raw.githubusercontent.com/MarSeventh/CloudFlare-ImgBed/main/docker-compose.yml
</code></pre>
<p><strong>3、启动服务</strong></p>
<pre><code class="lang-bash"># 启动服务（后台运行）
docker compose up -d

# 查看日志
docker compose logs -f
</code></pre>
<p><strong>4、访问服务</strong></p>
<p>打开浏览器访问：<code>http://your-server-ip:7658</code> 记得防火墙打开对应端口</p>
<h4 id="h4--docker-"><a name="方式二：Docker 命令" class="reference-link"></a><span class="header-link octicon octicon-link"></span>方式二：Docker 命令</h4><p><strong>1、创建项目目录</strong></p>
<pre><code class="lang-bash">mkdir cloudflare-imgbed
cd cloudflare-imgbed
</code></pre>
<p><strong>2、拉取镜像</strong></p>
<pre><code class="lang-bash">docker pull marseventh/cloudflare-imgbed:latest
</code></pre>
<p><strong>3、运行容器</strong></p>
<pre><code class="lang-bash">docker run -d \
  --name cloudflare-imgbed \
  -p 7658:8080 \
  -v $(pwd)/data:/app/data \
  marseventh/cloudflare-imgbed:latest
</code></pre>
<p><strong>4、访问服务</strong></p>
<p>打开浏览器访问：<code>http://your-server-ip:7658</code> 记得防火墙打开对应端口</p>
<h2 id="h2-huggingface-"><a name="HuggingFace注册" class="reference-link"></a><span class="header-link octicon octicon-link"></span>HuggingFace注册</h2><blockquote>
<p>官方地址：<a href="https://huggingface.co">https://huggingface.co</a></p>
<p><em>HuggingFace 渠道支持大文件直传，适合上传超过 20MB 的文件。对于大文件，系统会自动使用 LFS 协议进行分片上传。</em></p>
</blockquote>
<p>1、注册登陆后，在控制面板新建一个新空间，空间名字自定义。</p>
<p><strong>Select the Space SDK</strong> 选择 <strong>docker 的空项目或者是其他</strong></p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_14-26-23.jpg!yhblog" alt="创建空间1">
<p><strong>Space hardware</strong>选择<strong>FREE</strong>版本不要钱的。<em>空间的可见性也是根据你自己的意向选择就好了</em></p>
<p>然后点击下面的【Create Space 】按钮</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_14-27-04.jpg!yhblog" alt="创建空间2">
<p>2、创建 <a href="https://huggingface.co/settings/tokens">HuggingFace Access Token</a>，在【Setting】中的【Access Tokens】中点击【Create New Token】就行了，token的名称自定义，然后勾选仓库的读写权限，如下。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/Snipaste_2026-03-05_16-31-24_min.jpg!yhblog" alt="创建 Token">
<h2 id="h2-u5B58u50A8u914Du7F6E"><a name="存储配置" class="reference-link"></a><span class="header-link octicon octicon-link"></span>存储配置</h2><p>1、进入CloudFlare-ImgBed系统后台，在系统设置中，点击【系统设置】-&gt;在【上传设置】中添加上传渠道。如下</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/image-20260305160154669.png!yhblog" alt="添加上传渠道">
<p>2、添加一个HF存储的渠道方式，<strong>渠道名称自定义</strong>，然后仓库名称一定是  <strong>用户名/仓库名</strong> 的格式，然后填入上面申请的Acess Token信息。点击保存就行了。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/image-20260305160229869.png!yhblog" alt="添加HF存储">
<p>3、在系统设置中，点击【系统设置】-&gt;【页面设置】中去配置默认上传渠道信息和其他的配置就行了，如下。</p>
<p><img src="https://edgeone.cdn.youhun.wang/md/image-20260305160347351.png!yhblog" alt="设置HF存储为默认渠道">
<p>你也可以增加其他的上传渠道，还可以开启负载均衡！</p>
<h2 id="h2-u603Bu7ED3"><a name="总结" class="reference-link"></a><span class="header-link octicon octicon-link"></span>总结</h2><p>这个方案是不是超级香？不需要实名认证，访问速度还杠杠的，最关键的是——<strong>完全免费</strong>！100G 的 HuggingFace 空间，加上 Cloudflare 的全球加速，无论是放博客图片、分享文件，还是当个人网盘，都绰绰有余。</p>
<p>而且全程无需自己买服务器、不用装任何客户端，只要有个 GitHub 账号和 Cloudflare 账号就能搞定。还要什么自行车？赶紧去搭建一个吧！</p>]]></description>
	<pubDate>Thu, 05 Mar 2026 08:39:05 +0000</pubDate>
	<author>游魂</author>
	<guid>https://www.iyouhun.com/post-305.html</guid>

</item></channel>
</rss>