Files
xiaoxia-saas/docs/基础设施安装指南.md
API文档维护Agent e2c68888e9
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
refactor: 统一 OSS 配置命名(MINIO_* → OSS_*)
- .env.production: MINIO_* 环境变量全部改为 OSS_* 命名
  - MINIO_ENDPOINT → OSS_ENDPOINT
  - MINIO_ACCESS_KEY → OSS_ACCESS_KEY_ID
  - MINIO_SECRET_KEY → OSS_ACCESS_KEY_SECRET
  - MINIO_BUCKET → OSS_BUCKET_NAME
  - MINIO_SECURE → OSS_SECURE
  - MINIO_PUBLIC_URL → OSS_PUBLIC_URL
- .env.staging: 修正 section header 为 OSS 对象存储配置
- storage.py: 移除 MinIOService 和 get_minio_service() 向后兼容别名
- test_architecture_boundaries.py: 移除 storage.py 的 allowed 例外
- 更新文档中的 MINIO_* 示例为 OSS_*:
  - docs/CI-CD.md
  - docs/基础设施安装指南.md
  - docs/本地验证检查清单.md
  - docs/静态验证报告-2026-06-19.md
2026-06-28 08:33:48 +08:00

333 lines
7.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 小虾 SaaS 基础设施安装指南
**目标**:统一安装路径,便于管理
**安装位置**`F:\xiaoxia-infrastructure\`
---
## 一、安装 PostgreSQL
### 1.1 下载
**官方下载地址**https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
**推荐版本**PostgreSQL 16.x for Windows x86-64
**下载链接**https://sbp.enterprisedb.com/getfile.jsp?fileid=1258893
---
### 1.2 安装
1. 运行下载的安装程序
2. **安装路径**`F:\xiaoxia-infrastructure\PostgreSQL\16`
3. **端口**5432(默认)
4. **超级用户密码**:设置一个你记得住的密码(如:`xiaoxia2026`
5. 勾选 "Launch Stack Builder at exit"(可以取消)
---
### 1.3 配置
**创建数据库和用户**
```sql
-- 使用 psql 或 pgAdmin 执行
-- 创建用户
CREATE USER xiaoxia WITH PASSWORD 'xiaoxia2026';
-- 创建数据库
CREATE DATABASE xiaoxia_saas OWNER xiaoxia;
-- 授权
GRANT ALL PRIVILEGES ON DATABASE xiaoxia_saas TO xiaoxia;
```
---
### 1.4 验证
```bash
# 设置环境变量(临时)
$env:PGPASSWORD="xiaoxia2026"
# 测试连接
psql -h localhost -U xiaoxia -d xiaoxia_saas -c "SELECT 1;"
```
**预期输出**
```
?column?
----------
1
(1 row)
```
---
## 二、安装 Redis
### 2.1 下载
**Windows 版本**https://github.com/tporadowski/redis/releases
**推荐版本**Redis-x64-5.0.14.1.zip
**直接下载**https://github.com/tporadowski/redis/releases/download/v5.0.14.1/Redis-x64-5.0.14.1.zip
---
### 2.2 安装
1. 解压到:`F:\xiaoxia-infrastructure\Redis\`
2. 目录结构:
```
F:\xiaoxia-infrastructure\Redis\
├── redis-server.exe
├── redis-cli.exe
└── redis.windows.conf
```
---
### 2.3 启动
**方式 1:临时启动(推荐用于测试)**
```bash
cd F:\xiaoxia-infrastructure\Redis
.\redis-server.exe
```
**方式 2:安装为 Windows 服务**
```bash
cd F:\xiaoxia-infrastructure\Redis
.\redis-server.exe --service-install redis.windows.conf --service-name RedisService
.\redis-server.exe --service-start
```
---
### 2.4 验证
```bash
cd F:\xiaoxia-infrastructure\Redis
.\redis-cli.exe ping
```
**预期输出**`PONG`
---
## 三、安装 MinIO
### 3.1 下载
**官方下载**https://dl.min.io/server/minio/release/windows-amd64/minio.exe
**直接下载**
```bash
# 使用 PowerShell 下载
Invoke-WebRequest -Uri "https://dl.min.io/server/minio/release/windows-amd64/minio.exe" -OutFile "F:\xiaoxia-infrastructure\MinIO\minio.exe"
```
---
### 3.2 配置
创建数据目录:
```bash
mkdir F:\xiaoxia-infrastructure\MinIO\data
```
---
### 3.3 启动
```bash
cd F:\xiaoxia-infrastructure\MinIO
# 设置访问密钥
$env:MINIO_ROOT_USER="minioadmin"
$env:MINIO_ROOT_PASSWORD="minioadmin"
# 启动 MinIO
.\minio.exe server .\data --console-address ":9001"
```
**重要**
- MinIO API 端口:`9000`
- MinIO 控制台端口:`9001`
- 访问控制台:http://localhost:9001
---
### 3.4 验证
**浏览器访问**http://localhost:9001
**登录**
- 用户名:`minioadmin`
- 密码:`minioadmin`
---
## 四、快速安装脚本
**创建一个一键安装脚本**(可选)
```powershell
# install-infrastructure.ps1
# 创建目录
New-Item -ItemType Directory -Force -Path "F:\xiaoxia-infrastructure\PostgreSQL"
New-Item -ItemType Directory -Force -Path "F:\xiaoxia-infrastructure\Redis"
New-Item -ItemType Directory -Force -Path "F:\xiaoxia-infrastructure\MinIO\data"
Write-Host "目录创建完成!"
Write-Host ""
Write-Host "接下来请手动完成:"
Write-Host "1. 下载并安装 PostgreSQL 到 F:\xiaoxia-infrastructure\PostgreSQL\16"
Write-Host "2. 下载并解压 Redis 到 F:\xiaoxia-infrastructure\Redis\"
Write-Host "3. 下载 MinIO 到 F:\xiaoxia-infrastructure\MinIO\"
Write-Host ""
Write-Host "下载链接已保存在文档中。"
```
---
## 五、启动脚本
**创建统一启动脚本**
### start-infrastructure.ps1
```powershell
# 小虾 SaaS 基础设施启动脚本
Write-Host "=== 启动小虾 SaaS 基础设施 ===" -ForegroundColor Green
# 1. 检查并启动 PostgreSQL
Write-Host "`n[1/3] 检查 PostgreSQL..." -ForegroundColor Yellow
$pgService = Get-Service -Name "postgresql-x64-16" -ErrorAction SilentlyContinue
if ($pgService) {
if ($pgService.Status -ne "Running") {
Start-Service "postgresql-x64-16"
Write-Host "PostgreSQL 已启动" -ForegroundColor Green
} else {
Write-Host "PostgreSQL 已在运行" -ForegroundColor Green
}
} else {
Write-Host "警告:PostgreSQL 服务未找到,请手动启动" -ForegroundColor Red
}
# 2. 启动 Redis
Write-Host "`n[2/3] 启动 Redis..." -ForegroundColor Yellow
$redisPath = "F:\xiaoxia-infrastructure\Redis\redis-server.exe"
if (Test-Path $redisPath) {
Start-Process -FilePath $redisPath -WindowStyle Minimized
Write-Host "Redis 已启动" -ForegroundColor Green
} else {
Write-Host "警告:Redis 未找到,请检查路径" -ForegroundColor Red
}
# 3. 启动 MinIO
Write-Host "`n[3/3] 启动 MinIO..." -ForegroundColor Yellow
$minioPath = "F:\xiaoxia-infrastructure\MinIO\minio.exe"
if (Test-Path $minioPath) {
$env:MINIO_ROOT_USER = "minioadmin"
$env:MINIO_ROOT_PASSWORD = "minioadmin"
Start-Process -FilePath $minioPath -ArgumentList "server","F:\xiaoxia-infrastructure\MinIO\data","--console-address",":9001" -WindowStyle Minimized
Write-Host "MinIO 已启动" -ForegroundColor Green
Write-Host "MinIO 控制台: http://localhost:9001" -ForegroundColor Cyan
} else {
Write-Host "警告:MinIO 未找到,请检查路径" -ForegroundColor Red
}
Write-Host "`n=== 基础设施启动完成 ===" -ForegroundColor Green
Write-Host "`n服务地址:"
Write-Host " PostgreSQL: localhost:5432"
Write-Host " Redis: localhost:6379"
Write-Host " MinIO API: localhost:9000"
Write-Host " MinIO UI: http://localhost:9001"
```
---
## 六、停止脚本
### stop-infrastructure.ps1
```powershell
# 小虾 SaaS 基础设施停止脚本
Write-Host "=== 停止小虾 SaaS 基础设施 ===" -ForegroundColor Yellow
# 停止 Redis
Get-Process -Name "redis-server" -ErrorAction SilentlyContinue | Stop-Process -Force
Write-Host "Redis 已停止" -ForegroundColor Green
# 停止 MinIO
Get-Process -Name "minio" -ErrorAction SilentlyContinue | Stop-Process -Force
Write-Host "MinIO 已停止" -ForegroundColor Green
# PostgreSQL(通常作为服务运行,不停止)
Write-Host "PostgreSQL 保持运行(系统服务)" -ForegroundColor Cyan
Write-Host "`n=== 基础设施已停止 ===" -ForegroundColor Green
```
---
## 七、环境变量更新
安装完成后,更新 `.env.development`
```env
# 数据库
DATABASE_URL=postgresql://xiaoxia:xiaoxia2026@localhost:5432/xiaoxia_saas
USE_IN_MEMORY_DB=false
# Redis
REDIS_URL=redis://localhost:6379/0
CELERY_BROKER_URL=redis://localhost:6379/1
CELERY_RESULT_BACKEND=redis://localhost:6379/2
# MinIO
OSS_ENDPOINT=localhost:9000
OSS_ACCESS_KEY_ID=minioadmin
OSS_ACCESS_KEY_SECRET=minioadmin
OSS_BUCKET_NAME=xiaoxia-saas
OSS_SECURE=false
OSS_PUBLIC_URL=http://localhost:9000
# JWT
JWT_SECRET_KEY=xiaoxia-dev-secret-key-please-change-in-production-min-32-chars
JWT_ALGORITHM=HS256
JWT_ACCESS_TOKEN_EXPIRE_MINUTES=30
```
---
## 八、验证清单
安装完成后,执行验证:
```powershell
# PostgreSQL
psql -h localhost -U xiaoxia -d xiaoxia_saas -c "SELECT version();"
# Redis
cd F:\xiaoxia-infrastructure\Redis
.\redis-cli.exe ping
# MinIO
# 浏览器访问 http://localhost:9001
```
---
**准备好后,运行 `start-infrastructure.ps1` 启动所有服务!**