Files
XCDesktop/remote/docs/开发/部署指南.md
2026-03-08 01:34:54 +08:00

4.7 KiB
Raw Blame History

部署指南

本文档介绍远程屏幕监控系统的开发环境运行、生产环境部署、pkg 打包和 Windows 服务安装。


一、开发环境运行

1.1 环境要求

软件 版本要求 说明
Node.js >= 16.0.0 推荐使用 LTS 版本
操作系统 Windows 输入控制功能需要 Windows 系统
FFmpeg 内置 通过 npm 自动安装

1.2 安装依赖

# 进入项目目录
cd C:\Users\xuanchi\Desktop\remote

# 安装依赖
npm install

1.3 启动开发服务器

# 方式一:使用 dev 脚本
npm run dev

# 方式二:使用 start 脚本
npm start

# 方式三:直接运行
node src/index.js

启动成功后,访问 http://localhost:3000 查看屏幕流。


二、生产环境部署

2.1 环境变量配置

所有配置项都可以通过环境变量覆盖,格式为 REMOTE_<SECTION>_<KEY>

# 服务器配置
REMOTE_SERVER_PORT=3000
REMOTE_SERVER_HOST=0.0.0.0

# 安全配置
REMOTE_SECURITY_PASSWORD=your_password
REMOTE_SECURITY_TOKENEXPIRY=3600

# JWT 密钥
JWT_SECRET=your_jwt_secret

# 流媒体配置
REMOTE_STREAM_FPS=30
REMOTE_STREAM_BITRATE=4000k

# 输入控制配置
REMOTE_INPUT_MOUSEENABLED=true
REMOTE_INPUT_KEYBOARDENABLED=true

# FRP 配置
REMOTE_FRP_ENABLED=true

2.2 配置文件修改

配置文件位于 config/default.json

{
  "server": {
    "port": 3000,
    "host": "0.0.0.0"
  },
  "stream": {
    "fps": 30,
    "bitrate": "4000k",
    "gop": 10,
    "preset": "ultrafast",
    "resolution": {
      "width": 1920,
      "height": 1080
    }
  },
  "input": {
    "mouseEnabled": true,
    "keyboardEnabled": true,
    "sensitivity": 1.0
  },
  "security": {
    "password": "",
    "tokenExpiry": 3600
  },
  "frp": {
    "enabled": true,
    "frpcPath": "./frp/frpc.exe",
    "configPath": "./frp/frpc.toml"
  },
  "gitea": {
    "enabled": true
  }
}

2.3 启动生产服务

# 设置环境变量
$env:NODE_ENV="production"
$env:REMOTE_SECURITY_PASSWORD="your_password"

# 启动服务
node src/index.js

或创建启动脚本 start.ps1

$env:NODE_ENV="production"
$env:REMOTE_SECURITY_PASSWORD="your_password"
$env:JWT_SECRET="your_jwt_secret"

node src/index.js

三、pkg 打包说明

3.1 package.json 中的 pkg 配置

{
  "pkg": {
    "assets": [
      "node_modules/@ffmpeg-installer/**/*"
    ],
    "scripts": [
      "src/**/*.js"
    ]
  }
}
配置项 说明
assets 需要打包的资源文件,包含 FFmpeg 二进制文件
scripts 需要打包的脚本文件

3.2 打包命令

# 执行打包
npm run build

打包命令实际执行:

# 1. 使用 pkg 打包为可执行文件
pkg . --targets node18-win-x64 --output dist/remote-screen-monitor.exe

# 2. 复制资源文件
npm run build:copy-assets

3.3 打包输出目录

打包后的文件位于 dist/ 目录:

dist/
├── remote-screen-monitor.exe    # 主程序
├── public/                       # 前端静态文件
│   ├── css/
│   ├── js/
│   └── index.html
├── config/                       # 配置文件
│   └── default.json
├── frp/                          # FRP 客户端
│   ├── frpc.exe
│   └── frpc.toml
└── ffmpeg.exe                    # FFmpeg 编码器

3.4 资源文件处理

打包时需要手动复制的资源:

资源 来源 目标
前端文件 public/ dist/public/
配置文件 config/ dist/config/
FRP 客户端 frp/ dist/frp/
FFmpeg node_modules/@ffmpeg-installer/win32-x64/ffmpeg.exe dist/ffmpeg.exe

四、NSSM Windows 服务安装

4.1 服务安装命令

# 以管理员身份运行 PowerShell
cd C:\Users\xuanchi\Desktop\remote\nssm

# 安装服务(使用打包后的 exe
.\nssm.exe install RemoteApp "C:\path\to\dist\remote-screen-monitor.exe"

# 或使用 Node.js 运行
.\nssm.exe install RemoteApp "C:\Program Files\nodejs\node.exe" "C:\Users\xuanchi\Desktop\remote\src\index.js"

4.2 服务配置

# 设置工作目录
.\nssm.exe set RemoteApp AppDirectory "C:\path\to\app"

# 设置显示名称
.\nssm.exe set RemoteApp DisplayName "Remote Desktop Application"

# 设置描述
.\nssm.exe set RemoteApp Description "Remote screen streaming service"

# 设置启动类型(自动启动)
.\nssm.exe set RemoteApp Start SERVICE_AUTO_START

# 设置日志输出
.\nssm.exe set RemoteApp AppStdout "C:\path\to\app\logs\service.log"
.\nssm.exe set RemoteApp AppStderr "C:\path\to\