Skip to content
广告 · 本站推荐广告

Fly.io 部署

Fly.io 是一个全球边缘计算平台,可以将 Docker 容器部署到离用户最近的数据中心。适合需要低延迟访问的场景。


前置条件

bash
# 安装 Fly CLI
curl -L https://fly.io/install.sh | sh

# 登录
fly auth login

快速部署

1. 创建项目目录

bash
mkdir openclaw-fly && cd openclaw-fly

2. 创建 fly.toml

toml
app = "my-openclaw"
primary_region = "nrt"  # 东京,亚洲延迟最低

[build]
  image = "ghcr.io/openclaw/gateway:latest"

[env]
  NODE_ENV = "production"
  OPENCLAW_LOG_LEVEL = "info"

[http_service]
  internal_port = 18789
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1

[[vm]]
  cpu_kind = "shared"
  cpus = 1
  memory_mb = 1024

3. 设置 Secrets(密钥)

bash
# 设置 API Key(控制台认证)
fly secrets set OPENCLAW_API_KEY="your-secret-key"

# 设置模型 Provider Key(如需要)
fly secrets set OPENAI_API_KEY="sk-xxx"

4. 创建持久化卷

bash
fly volumes create openclaw_data --size 1 --region nrt

fly.toml 中添加挂载:

toml
[mounts]
  source = "openclaw_data"
  destination = "/home/openclaw/.openclaw"

5. 部署

bash
fly launch    # 首次部署
fly deploy    # 后续更新

常用命令

bash
# 查看日志
fly logs

# SSH 进入容器
fly ssh console

# 查看状态
fly status

# 扩缩容
fly scale count 2    # 扩到 2 个实例
fly scale memory 2048  # 增加内存到 2GB

排障

部署失败:健康检查超时

bash
# 增加启动超时时间
fly deploy --wait-timeout 300

磁盘空间不足

bash
# 扩展卷大小
fly volumes extend <vol_id> --size 5

查看崩溃原因

bash
fly logs --instance <instance_id>

🇨🇳 中国用户须知

Fly.io 在亚洲的最近节点为东京(nrt)和新加坡(sin)。国内访问延迟约 50–100ms。如需更低延迟,建议使用 阿里云腾讯云 部署。

基于MIT协议开源 | 内容翻译自 官方文档,同步更新