V2 独立版愿景

Server 部署

HeteroFlow 是本站的异构算力与大模型调度产品。Server 部署。Server 部署 本文档介绍 HeteroFlow V2 Server 的部署方法,包括源码部署、二进制部署和 systemd 服务管理。 部署前准备 端口需要80 8080 3333 5173,安全组放行 系统要求 组件 最低版本 推荐 ------ --------- --…

Server 部署

本文档介绍 HeteroFlow V2 Server 的部署方法,包括源码部署、二进制部署和 systemd 服务管理。

部署前准备

端口需要80 8080 3333 5173,安全组放行

系统要求

组件最低版本推荐
操作系统Linux (Ubuntu 20.04+) / macOSUbuntu 22.04
Go1.22+1.22
Node.js18+18 LTS
PostgreSQL14+16
内存2GB+4GB+
磁盘10GB+50GB+(含模型存储)

安装 Go 环境

wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
go version

安装 Node.js

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v && npm -v

安装 PostgreSQL

sudo apt-get install -y postgresql postgresql-contrib
sudo systemctl enable --now postgresql

# 创建数据库和用户
sudo -u postgres psql <<EOF
CREATE USER heteroflow WITH PASSWORD 'heteroflow2024';
CREATE DATABASE heteroflow OWNER heteroflow;
GRANT ALL PRIVILEGES ON DATABASE heteroflow TO heteroflow;
EOF

方法一:源码部署

# 1. 克隆源码
git clone https://gitee.com/heteroflow/HeteroFlow.git
cd HeteroFlow

# 2. 编译后端
cd v2/cmd && go build -o server . && cd ../..

# 3. 配置
cp config.yaml.example config.yaml
# 编辑 config.yaml 设置数据库、JWT 密钥等

# 4. 编译前端(可选)
cd web && npm install && npm run build && cd ..

# 5. 启动
./v2/cmd/server

方法二:systemd 服务部署(推荐)

# 1. 编译后复制到部署目录
sudo mkdir -p /opt/heteroflow
sudo cp v2/cmd/server /opt/heteroflow/
sudo cp config.yaml /opt/heteroflow/

# 2. 创建 systemd 服务
sudo cat > /etc/systemd/system/heteroflow.service <<EOF
[Unit]
Description=HeteroFlow Server
After=network.target postgresql.service

[Service]
Type=simple
User=heteroflow
WorkingDirectory=/opt/heteroflow
ExecStart=/opt/heteroflow/server
Restart=always
RestartSec=5
Environment=HETEROFLOW_ENV=production
Environment=HETEROFLOW_JWT_SECRET=your-secret-key-min-32chars

[Install]
WantedBy=multi-user.target
EOF

# 3. 启动服务
sudo systemctl daemon-reload
sudo systemctl enable heteroflow
sudo systemctl start heteroflow

# 4. 查看状态
sudo systemctl status heteroflow

配置说明

config.yaml 核心配置

server:
  port: 3333
  mode: release

storage:
  type: postgresql
  postgresql:
    host: localhost
    port: 5432
    database: heteroflow
    user: heteroflow
    password: heteroflow2024
    ssl_mode: disable
    max_open_conns: 25
    max_idle_conns: 5
    conn_max_lifetime: 1800

auth:
  jwt_secret: "your-secret-key"
  expire_hours: 72

scheduler:
  schedule_interval: 5
  default_task_timeout: 1800
  gpu_reserve_fixed_mb: 500
  gpu_reserve_percent: 10
  plugins:
    pre_score: [Preempt]
    filter: [ResourceFilter, GPUFilter]
    score: [Binpack, Spread, NVLink]
    bind: [DefaultBind]

环境变量

变量说明默认值
HETEROFLOW_JWT_SECRETJWT 签名密钥(≥32字符)自动生成
HETEROFLOW_TOKEN_EXPIRYToken 有效期24h
HETEROFLOW_AGENT_API_KEYAgent API 密钥自动生成
CORS_ALLOWED_ORIGINSCORS 允许的额外来源-
HETEROFLOW_ENV运行环境development

前端部署

开发模式

cd web
npm install
npm run dev -- --host 0.0.0.0

生产模式

cd web && npm install && npm run build
# 构建产物在 web/dist/ 目录

验证部署

# 检查 Server 健康状态
curl http://localhost:3333/api/v1/nodes

# 检查前端访问
curl http://localhost:5173/

# 检查服务状态
systemctl status heteroflow

常见问题

端口被占用

lsof -i :3333
# 修改 config.yaml 中的 port 或 kill 占用进程

数据库连接失败

# 检查 PostgreSQL 状态
systemctl status postgresql
# 测试连接
psql -h localhost -U heteroflow -d heteroflow

服务启动后立即退出

查看日志:journalctl -u heteroflow --since "1 minute ago"