单机部署
【Single Machine Deployment】
使用独立版本在单个虚拟机或物理服务器上部署 Onlook。这将创建一个自包含的生产部署,无需 Docker 容器,非常适合小团队和简单的生产环境。
【Deploy Onlook on a single virtual machine or physical server using the standalone build. This creates a self-contained production deployment without Docker containers, ideal for small teams and simple production setups.】
先决条件
【Prerequisites】
系统要求:
- 4个以上 CPU 核心
- 8GB+ 内存(建议16GB)
- 可用磁盘空间 50GB 以上
软件要求:
安装
【Setup】
1. 克隆仓库
【1. Clone the Repository】
git clone https://github.com/onlook-dev/onlook.git
cd onlook
# Install dependencies
bun install2. 设置环境变量
【2. Setup Environment Variables】
创建你的环境配置:
【Create your environment configuration:】
# Run interactive environment setup
bun run setup:env必填变量:
- Supabase:生产数据库 URL 和 API 密钥
- OpenRouter API 密钥:用于 AI 聊天功能
- CodeSandbox 令牌:用于开发容器
有关获取这些 API 密钥的详细说明,请参阅开发设置指南。
【For detailed instructions on obtaining these API keys, see the development setup guide.】
3. 启动后端服务
【3. Start Backend Services】
bun backend:start这将在本地启动 Supabase,包括 PostgreSQL 数据库、身份验证和存储。服务将可用于:
【This starts Supabase locally with PostgreSQL database, authentication, and storage. The services will be available at:】
- Supabase API: http://127.0.0.1:54321
- PostgreSQL: http://127.0.0.1:54322
- Supabase 仪表板: http://127.0.0.1:54323
4. 初始化数据库
【4. Initialize Database】
# Push database schema
bun db:push5. 构建并部署独立应用
【5. Build and Deploy Standalone Application】
# Build standalone production deployment
bun run preview:standalone这将创建一个自包含的生产构建,其中包括:
【This creates a self-contained production build with:】
- 独立服务器:具有所有依赖的独立 Node.js 服务器
- 静态资源:所有为生产环境打包的静态文件
- 优化构建:已压缩并针对性能进行了优化
- 生产就绪:已配置为生产环境
验证
【Verification】
运行后,验证你的部署:
【Once running, verify your deployment:】
- 主要应用: http://localhost:3000
- Supabase 控制面板: http://localhost:54323
检查所有服务是否正在运行:
【Check all services are running:】
# Check application
curl http://localhost:3000
# Check Supabase API
curl http://localhost:54321/rest/v1/可选:生产加固
【Optional: Production Hardening】
在生产环境中运行
【Running in Production】
独立版本构建会创建一个完整的生产服务器。你可以通过不同的方式启动它:
【The standalone build creates a complete production server. You can start it in different ways:】
# Option 1: Direct command
bun .next/standalone/apps/web/client/server.js
# Option 2: Use bun script
bun run start:standalone
# Option 3: With PM2 for process management
pm2 start .next/standalone/apps/web/client/server.js --name onlook流程管理(推荐)
【Process Management (Recommended)】
对于生产环境部署,请使用像 PM2 这样的进程管理器:
【For production deployments, use a process manager like PM2:】
# Install PM2 globally
bun add -g pm2
# Start with PM2
pm2 start .next/standalone/apps/web/client/server.js --name onlook
# Save PM2 configuration
pm2 save
# Setup auto-start on boot
pm2 startup故障排除
【Troubleshooting】
常见问题:
- 端口冲突:如果端口 3000、54321 或 54322 被占用,请在配置中更改端口
- 构建失败:运行
rm -rf node_modules && bun install然后重试构建 - 数据库连接:确保
bun backend:start成功完成 - 独立服务器无法启动:请确认已使用
ls -la .next/standalone/apps/web/client/完成构建 - 内存问题:使用
NODE_OPTIONS="--max-old-space-size=4096"增加 Node.js 内存限制
性能优化:
- 使用 PM2 进行进程管理和自动重启
- 配置反向代理(Nginx/Apache)以支持 SSL 和缓存
- 使用SSD存储以获得更好的I/O性能
- 监控内存使用情况并在需要时重启
用例
【Use Cases】
适合于:
- 小团队生产部署(5-20 用户)
- 单服务器设置
- 注重成本的部署
- 简单的生产环境
- 组织避免容器复杂性
相对于 Docker 的优势:
- 无需容器编排复杂性
- 直接服务器访问和调试
- 较低的资源开销
- 更简化的部署流程
- 标准系统服务管理
相比开发模式的优势:
- 生产优化构建
- 更好的性能和安全性
- 降低内存占用
- 自包含部署
- 不需要开发依赖
注意事项:
- 单点故障
- 需要手动缩放
- 需要系统管理知识
- 不如容器便携
- 手动备份和恢复流程
对于高可用性的生产部署,请考虑使用 Docker Compose 或 云部署 选项。
【For high-availability production deployments, consider Docker Compose or Cloud Deployment options.】