用于AI代理、工作流自动化和数据工程项目的个人VPS设置,使用Python、FastAPI和n8n。
此VPS设置提供以下服务的开发和生产环境:
graph TB
%% 客户端层
Client[Claude Code] -->|MCP/HTTP<br/>Bearer Auth| Caddy[Caddy<br/>反向代理]
%% 网络层
Caddy -->|MCP/HTTP| AIDev[MCP Server<br/>工具提供者]
%% 应用层
AIDev -->|创建/读取/更新/删除<br/>N8N API| N8N[N8N<br/>工作流自动化]
AIDev -->|HTTP| HostAgent[HostAgent<br/>特权操作]
AIDev -->|搜索| Workflows[模板服务器<br/>2000+ 社区工作流]
%% 主机服务
HostAgent -->|Bash/Git| BackupN8N[备份 N8N<br/>工作流]
HostAgent -->|搜索| SearchN8N[N8N 文档<br/>通用节点描述]
HostAgent -->|搜索| TypeScriptN8N[N8N 源代码<br/>TypeScript 节点模式]
%% 自动化层
GitHub[GitHub Actions] -->|Webhook| Runner[自托管运行器<br/>Docker 部署]
Runner --> AIDev
Runner --> N8N
Runner --> Supabase[Supabase<br/>PostgreSQL]
Runner --> DBT[DBT<br/>数据转换]
Runner --> Browserless[Browserless<br/>无头Chrome]
%% 安全层(独立盒子)
UFW[UFW 防火墙<br/>网络安全]
%% 样式
classDef client fill:#e1f5fe,stroke:#01579b,stroke-width:2px
classDef web fill:#f3e5f5,stroke:#4a148c,stroke-width:2_2px
classDef app fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px
classDef host fill:#f5f5f5,stroke:#424242,stroke-width:2px
classDef infra fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef container fill:#fce4ec,stroke:#880e4f,stroke-width:2px
classDef security fill:#ffebee,stroke:#b71c1c,stroke-width:2px
class Client client
class Caddy web
class AIDev,HostAgent,Workflows app
class N8N,Supabase,DBT,Browserless container
class BackupN8N,SearchN8N,TypeScriptN8N host
class GitHub,Runner infra
class UFW security
注:MCP Server指代本仓库中的AI Dev Server服务。
所有服务通过Docker网络连接,并具有特定的网络需求:
supabase_default),大多数服务加入extra_hosts: "host.docker.internal:host-gateway"127.0.0.1以确保安全性(仅限本地)AI 开发服务器(容器化)需要与HostAgent(主机服务)进行通信:
host.docker.internal:9000来访问HostAgent0.0.0.0:9000(而不是127.0.0.1)以接受容器连接配置:
# docker-compose/ai-dev-server/docker-compose.yml
services:
ai-dev-server:
extra_hosts:
- "host.docker.internal:host-gateway" # 启用主机访问
# host-agent/.env
HOST=0.0.0.0 # 允许容器访问
PORT=9000
服务通过以下方式互相发现:
127.0.0.1防止外部访问# 克隆包含子模块的仓库
git clone --recurse-submodules <repository-url> /home/david/vps
cd /home/david/vps
# 或者如果已经克隆,初始化子模块
git submodule update --init --recursive
# 配置环境变量
cp host-agent/.env.example host-agent/.env
# 编辑.env文件以您的配置
# 部署HostAgent服务(主要部署方法)
./deploy.sh
# 部署单个Docker服务
cd docker-compose/[service-name]
docker-compose up -d
# 设置GitHub Actions运行器以实现自动化部署
cd github-runner
./setup-runner.sh
# 使用来自仓库设置的GitHub令牌进行配置
./start-runner-service.sh
# 验证部署
docker ps
sudo systemctl status host-agent
sudo systemctl status actions.runner.*
n8n-docs/目录包含通过git子模块获取的n8n全面节点文档。这为MCP工具提供了对所有n8n节点、凭证和集成的详细文档访问,同时保持与官方文档同步。
# 初始化n8n-docs子模块(首次)
git submodule update --init --recursive n8n-docs
# 或一次性初始化所有子模块
git submodule update --init --recursive
# 将n8n文档更新到最新版本
git submodule update --remote n8n-docs
# 提交子模块更新
git add n8n-docs
git commit -m "更新n8n-docs子模块到最新版本"
git push
n8n-docs 子模块使用稀疏检出仅包含:
docs/integrations/builtin/app-nodes/* - 应用节点文档docs/integrations/builtin/core-nodes/* - 核心节点文档docs/integrations/builtin/cluster-nodes/* - LangChain集群节点文档docs/integrations/builtin/credentials/* - 凭证文档docs/integrations/builtin/trigger-nodes/* - 触发节点文档docs/integrations/builtin/node-types.md & rate-limits.md这提供了所有n8n节点和集成的全面文档。
# 如果子模块看起来为空或过时
git submodule update --init --remote --force n8n-docs
# 将子模块重置为跟踪的提交
git submodule update --init n8n-docs
# 检查子模块状态
git submodule status
# 单个Docker服务
cd docker-compose/[service-name]
docker-compose up -d
docker-compose down
# HostAgent(systemd服务)
sudo systemctl start/stop/restart host-agent
sudo journalctl -u host-agent -f
# GitHub Actions 运行器
sudo systemctl start/stop/restart actions.runner.*
sudo journalctl -u actions.runner.* -f
# 部署脚本(用于HostAgent更新)
./deploy.sh
当推送更改时,GitHub Actions会自动部署服务:
ai-dev-server/ → 自动构建和部署.github/workflows/deploy-ai-dev-server.yml定义了部署registry.correlion.ai所有服务使用干净、可预测的容器名称:
ai-dev-servern8nsupabase-*(多个容器)browserless-chromiumregistrydbtdtc-frontend-app# 服务健康端点
curl http://127.0.0.1:8080/health # AI 开发服务器
curl http://127.0.0.1:9000/health # HostAgent
curl http://127.0.0.1:3000/api/platform/profile # Supabase Studio
# 容器状态
docker ps
docker logs -f [container-name]
每个服务需要特定的环境变量。关键共享变量:
# 共享认证
MCP_BEARER_TOKEN=your-secure-token
HOST_AGENT_BEARER_TOKEN=your-secure-token
# n8n 配置
N8N_BASE_URL=http://n8n:5678
N8N_API_KEY=your-n8n-api-key
# 数据库(Supabase)
POSTGRES_PASSWORD=your-db-password
JWT_SECRET=your-jwt-secret
ANON_KEY=your-anon-key
SERVICE_ROLE_KEY=your-service-role-key
.env文件提交到版本控制backup-n8n-workflows.sh脚本或HostAgent API进行自动备份# n8n 工作流备份(通过脚本)
./backup-n8n-workflows.sh
# n8n 工作流备份(通过HostAgent API)
curl -X POST http://127.0.0.1:9000/backup/n8n \
-H "Authorization: Bearer $HOST_AGENT_BEARER_TOKEN"
# 数据库备份
docker exec supabase-db pg_dump -U postgres database_name > backup.sql
# 完整系统状态
docker images > docker-images.txt
docker ps -a > docker-containers.txt
每个服务都有自己的开发设置。参见各个服务的README:
docker-compose/中创建服务目录docker-compose.yml.github/workflows/中创建GitHub工作流以实现自动化部署# 测试服务间通信
docker exec ai-dev-server curl http://host.docker.internal:9000/health
docker exec ai-dev-server curl http://n8n:5678/healthz
# 测试外部访问
curl https://[domain].correlion.ai/health
HostAgent连接被拒绝
HOST=0.0.0.0在host-agent .env中sudo systemctl status host-agentdocker exec ai-dev-server curl http://host.docker.internal:9000/health容器网络问题
docker network lsextra_hosts以访问主机服务发现失败
docker ps# 服务日志
sudo journalctl -u host-agent -f
docker logs -f ai-dev-server
docker logs -f n8n
# 系统资源
docker stats
df -h
free -m
# 网络连通性
docker exec [container-name] ping [其他容器]
docker exec [container-name] nslookup [服务名称]
该项目包含用于VPS基础设施管理的配置和部署脚本。