feat: v1.1.0 全平台客户端打包 + 详细服务端部署教程
Client: - 支持 Windows (NSIS安装包+免安装版), macOS (DMG x64/arm64), Linux (AppImage+deb) - 添加 dist:win / dist:mac / dist:linux / dist:all 打包脚本 - 生成应用图标 (icon.png + icon.ico) - Windows x64 安装包已编译: release/FunConnect-1.1.0-Win-x64.exe - 更新 README 包含完整的跨平台构建指南和国内镜像加速说明 Server: - 新增 DEPLOY.md 详细部署教程 (400+行) - Ubuntu主节点完整部署流程 - 工作节点部署和注册 - Web管理面板生产部署 - 防火墙配置 - Nginx反向代理配置 - SSL证书(Let's Encrypt)配置 - 多节点集群架构说明 - 运维管理命令和监控 - 常见问题排查 - 快速部署清单
This commit is contained in:
113
client/README.md
113
client/README.md
@@ -1,6 +1,19 @@
|
|||||||
# FunConnect Client
|
# FunConnect Client
|
||||||
|
|
||||||
Minecraft 联机桌面客户端,基于 Electron 构建,支持 Windows / macOS / Linux。
|
Minecraft 联机桌面客户端,基于 Electron 构建,支持 **Windows / macOS / Linux** 全平台。
|
||||||
|
|
||||||
|
## 下载
|
||||||
|
|
||||||
|
从 [Releases](https://gt.funmc.cn/xiaobai/FunConnect/releases) 页面下载对应平台的安装包:
|
||||||
|
|
||||||
|
| 平台 | 文件 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| **Windows** | `FunConnect-x.x.x-Win-x64.exe` | 安装包(NSIS) |
|
||||||
|
| **Windows** | `FunConnect-x.x.x-Win-x64.exe` (portable) | 免安装版 |
|
||||||
|
| **macOS (Intel)** | `FunConnect-x.x.x-Mac-x64.dmg` | Intel Mac |
|
||||||
|
| **macOS (Apple Silicon)** | `FunConnect-x.x.x-Mac-arm64.dmg` | M1/M2/M3 Mac |
|
||||||
|
| **Linux** | `FunConnect-x.x.x-Linux-x64.AppImage` | 通用 Linux |
|
||||||
|
| **Linux** | `FunConnect-x.x.x-Linux-x64.deb` | Debian/Ubuntu |
|
||||||
|
|
||||||
## 功能
|
## 功能
|
||||||
|
|
||||||
@@ -12,30 +25,103 @@ Minecraft 联机桌面客户端,基于 Electron 构建,支持 Windows / macO
|
|||||||
- **系统托盘** - 最小化到托盘,后台运行
|
- **系统托盘** - 最小化到托盘,后台运行
|
||||||
- **自动重连** - 连接断开后自动尝试重新连接
|
- **自动重连** - 连接断开后自动尝试重新连接
|
||||||
|
|
||||||
## 快速开始
|
## 从源码构建
|
||||||
|
|
||||||
### 安装依赖
|
### 前置要求
|
||||||
|
|
||||||
|
- Node.js 18+
|
||||||
|
- npm 9+
|
||||||
|
- Git
|
||||||
|
|
||||||
|
### 1. 安装依赖
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
cd client
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
> 如果 Electron 下载慢,使用国内镜像:
|
> **国内镜像加速**(解决 Electron 下载慢):
|
||||||
> ```bash
|
> ```bash
|
||||||
> ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ npm install
|
> # 设置镜像
|
||||||
|
> npm config set registry https://registry.npmmirror.com
|
||||||
|
>
|
||||||
|
> # Windows PowerShell
|
||||||
|
> $env:ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
|
||||||
|
> $env:ELECTRON_BUILDER_BINARIES_MIRROR="https://npmmirror.com/mirrors/electron-builder-binaries/"
|
||||||
|
> npm install
|
||||||
|
>
|
||||||
|
> # macOS / Linux
|
||||||
|
> ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ \
|
||||||
|
> ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/ \
|
||||||
|
> npm install
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
### 开发模式
|
### 2. 开发模式
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### 打包发布
|
### 3. 编译打包
|
||||||
|
|
||||||
|
#### Windows(在 Windows 上执行)
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 安装程序(NSIS)
|
||||||
|
npm run dist:win
|
||||||
|
|
||||||
|
# 输出:
|
||||||
|
# release/FunConnect-x.x.x-Win-x64.exe (安装包)
|
||||||
|
# release/FunConnect-x.x.x-Win-x64.exe (portable免安装)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### macOS(在 macOS 上执行)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dist
|
# DMG 安装包
|
||||||
# 输出到 release/ 目录
|
npm run dist:mac
|
||||||
|
|
||||||
|
# 输出:
|
||||||
|
# release/FunConnect-x.x.x-Mac-x64.dmg (Intel)
|
||||||
|
# release/FunConnect-x.x.x-Mac-arm64.dmg (Apple Silicon)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Linux(在 Linux 上执行)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# AppImage + deb
|
||||||
|
npm run dist:linux
|
||||||
|
|
||||||
|
# 输出:
|
||||||
|
# release/FunConnect-x.x.x-Linux-x64.AppImage
|
||||||
|
# release/FunConnect-x.x.x-Linux-x64.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 全平台(需要对应平台环境)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dist:all
|
||||||
|
```
|
||||||
|
|
||||||
|
> **注意**:跨平台编译限制——Windows 安装包需要在 Windows 上构建,macOS DMG 需要在 macOS 上构建。Linux AppImage 可在 Linux 或使用 Docker 构建。
|
||||||
|
|
||||||
|
### 4. CI/CD 自动构建(参考)
|
||||||
|
|
||||||
|
如果使用 GitHub Actions 或 GitLab CI,可以用 matrix 策略在多个平台上并行构建:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# .gitlab-ci.yml 示例
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
parallel:
|
||||||
|
matrix:
|
||||||
|
- OS: [windows, macos, linux]
|
||||||
|
script:
|
||||||
|
- npm ci
|
||||||
|
- npm run dist
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- client/release/
|
||||||
```
|
```
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
@@ -60,6 +146,9 @@ npm run dist
|
|||||||
|
|
||||||
```
|
```
|
||||||
client/
|
client/
|
||||||
|
├── build/ # 构建资源(图标等)
|
||||||
|
│ ├── icon.png # 应用图标 (256x256)
|
||||||
|
│ └── icon.ico # Windows 图标
|
||||||
├── src/main/
|
├── src/main/
|
||||||
│ ├── index.ts # Electron 主进程
|
│ ├── index.ts # Electron 主进程
|
||||||
│ ├── preload.ts # 预加载脚本(IPC桥接)
|
│ ├── preload.ts # 预加载脚本(IPC桥接)
|
||||||
@@ -74,9 +163,7 @@ client/
|
|||||||
└── tsconfig.json
|
└── tsconfig.json
|
||||||
```
|
```
|
||||||
|
|
||||||
## 配置说明
|
## 设置说明
|
||||||
|
|
||||||
设置页面中可配置:
|
|
||||||
|
|
||||||
| 设置项 | 默认值 | 说明 |
|
| 设置项 | 默认值 | 说明 |
|
||||||
|--------|--------|------|
|
|--------|--------|------|
|
||||||
@@ -91,4 +178,4 @@ client/
|
|||||||
- **TypeScript** - 主进程开发
|
- **TypeScript** - 主进程开发
|
||||||
- **electron-store** - 设置持久化
|
- **electron-store** - 设置持久化
|
||||||
- **Axios** - HTTP 请求
|
- **Axios** - HTTP 请求
|
||||||
- **electron-builder** - 打包发布
|
- **electron-builder** - 全平台打包发布
|
||||||
|
|||||||
BIN
client/build/icon.ico
Normal file
BIN
client/build/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
BIN
client/build/icon.png
Normal file
BIN
client/build/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -1,20 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "funconnect",
|
"name": "funconnect",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"description": "FunMC Minecraft 联机客户端",
|
"description": "FunConnect - Minecraft 跨平台联机客户端",
|
||||||
"main": "dist/main/index.js",
|
"main": "dist/main/index.js",
|
||||||
"author": "FunMC",
|
"author": "FunMC <funmc@funmc.cn>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:ts": "tsc",
|
"build:ts": "tsc",
|
||||||
"start": "npm run build:ts && electron .",
|
"start": "npm run build:ts && electron .",
|
||||||
"dev": "tsc && electron .",
|
"dev": "tsc && electron .",
|
||||||
"pack": "npm run build:ts && electron-builder --dir",
|
"pack": "npm run build:ts && electron-builder --dir",
|
||||||
"dist": "npm run build:ts && electron-builder"
|
"dist": "npm run build:ts && electron-builder",
|
||||||
|
"dist:win": "npm run build:ts && electron-builder --win",
|
||||||
|
"dist:mac": "npm run build:ts && electron-builder --mac",
|
||||||
|
"dist:linux": "npm run build:ts && electron-builder --linux",
|
||||||
|
"dist:all": "npm run build:ts && electron-builder --win --mac --linux"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"appId": "cn.funmc.connect",
|
"appId": "cn.funmc.connect",
|
||||||
"productName": "FunConnect",
|
"productName": "FunConnect",
|
||||||
|
"copyright": "Copyright © 2024 FunMC",
|
||||||
"directories": {
|
"directories": {
|
||||||
"output": "release"
|
"output": "release"
|
||||||
},
|
},
|
||||||
@@ -24,12 +29,66 @@
|
|||||||
"package.json"
|
"package.json"
|
||||||
],
|
],
|
||||||
"win": {
|
"win": {
|
||||||
"target": "nsis",
|
"target": [
|
||||||
"icon": "renderer/icon.ico"
|
{
|
||||||
|
"target": "nsis",
|
||||||
|
"arch": ["x64", "ia32"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target": "portable",
|
||||||
|
"arch": ["x64"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"icon": "build/icon.ico",
|
||||||
|
"artifactName": "FunConnect-${version}-Win-${arch}.${ext}"
|
||||||
},
|
},
|
||||||
"nsis": {
|
"nsis": {
|
||||||
"oneClick": false,
|
"oneClick": false,
|
||||||
"allowToChangeInstallationDirectory": true
|
"allowToChangeInstallationDirectory": true,
|
||||||
|
"installerIcon": "build/icon.ico",
|
||||||
|
"uninstallerIcon": "build/icon.ico",
|
||||||
|
"installerHeaderIcon": "build/icon.ico",
|
||||||
|
"createDesktopShortcut": true,
|
||||||
|
"createStartMenuShortcut": true,
|
||||||
|
"shortcutName": "FunConnect"
|
||||||
|
},
|
||||||
|
"mac": {
|
||||||
|
"target": [
|
||||||
|
{
|
||||||
|
"target": "dmg",
|
||||||
|
"arch": ["x64", "arm64"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"icon": "build/icon.png",
|
||||||
|
"category": "public.app-category.games",
|
||||||
|
"artifactName": "FunConnect-${version}-Mac-${arch}.${ext}"
|
||||||
|
},
|
||||||
|
"dmg": {
|
||||||
|
"title": "FunConnect ${version}",
|
||||||
|
"contents": [
|
||||||
|
{ "x": 130, "y": 220 },
|
||||||
|
{ "x": 410, "y": 220, "type": "link", "path": "/Applications" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linux": {
|
||||||
|
"target": [
|
||||||
|
{
|
||||||
|
"target": "AppImage",
|
||||||
|
"arch": ["x64"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"target": "deb",
|
||||||
|
"arch": ["x64"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"icon": "build/icon.png",
|
||||||
|
"category": "Game",
|
||||||
|
"artifactName": "FunConnect-${version}-Linux-${arch}.${ext}",
|
||||||
|
"desktop": {
|
||||||
|
"Name": "FunConnect",
|
||||||
|
"Comment": "Minecraft 联机客户端",
|
||||||
|
"Categories": "Game;Network"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
591
server/DEPLOY.md
Normal file
591
server/DEPLOY.md
Normal file
@@ -0,0 +1,591 @@
|
|||||||
|
# FunConnect 服务端部署教程
|
||||||
|
|
||||||
|
本教程详细介绍如何在 Ubuntu 服务器上部署 FunConnect 中继服务器,包括主节点和工作节点的完整部署流程。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
|
||||||
|
1. [环境要求](#1-环境要求)
|
||||||
|
2. [方式一:一键部署](#2-方式一一键部署)
|
||||||
|
3. [方式二:手动部署](#3-方式二手动部署)
|
||||||
|
4. [部署主节点](#4-部署主节点)
|
||||||
|
5. [部署工作节点](#5-部署工作节点)
|
||||||
|
6. [部署 Web 管理面板](#6-部署-web-管理面板)
|
||||||
|
7. [防火墙配置](#7-防火墙配置)
|
||||||
|
8. [Nginx 反向代理(可选)](#8-nginx-反向代理可选)
|
||||||
|
9. [SSL 证书配置(可选)](#9-ssl-证书配置可选)
|
||||||
|
10. [多节点集群配置](#10-多节点集群配置)
|
||||||
|
11. [运维管理](#11-运维管理)
|
||||||
|
12. [常见问题](#12-常见问题)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 环境要求
|
||||||
|
|
||||||
|
| 项目 | 要求 |
|
||||||
|
|------|------|
|
||||||
|
| 操作系统 | Ubuntu 20.04 / 22.04 / 24.04 LTS |
|
||||||
|
| CPU | 1核+ (推荐2核+) |
|
||||||
|
| 内存 | 512MB+ (推荐1GB+) |
|
||||||
|
| 网络 | 公网IP,开放 TCP 3000 和 25565 端口 |
|
||||||
|
| 软件 | Node.js 18+, npm |
|
||||||
|
|
||||||
|
> **带宽建议**:每个联机房间大约需要 0.5-2 Mbps 带宽,请根据预计房间数量选择合适的服务器。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 方式一:一键部署
|
||||||
|
|
||||||
|
适合快速部署单个主节点。
|
||||||
|
|
||||||
|
### 2.1 上传项目文件
|
||||||
|
|
||||||
|
将 `server/` 目录上传到服务器:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在本地执行(将server目录上传到服务器)
|
||||||
|
scp -r server/ root@your-server-ip:/root/funconnect-server/
|
||||||
|
|
||||||
|
# 或者使用 Git 克隆
|
||||||
|
ssh root@your-server-ip
|
||||||
|
git clone https://gt.funmc.cn/xiaobai/FunConnect.git
|
||||||
|
cd FunConnect/server
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 执行安装脚本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 部署主节点
|
||||||
|
sudo bash deploy/install.sh master my-relay-server
|
||||||
|
|
||||||
|
# 部署工作节点
|
||||||
|
sudo bash deploy/install.sh worker relay-node-2
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会自动完成:
|
||||||
|
- 安装 Node.js 20.x(如未安装)
|
||||||
|
- 创建安装目录 `/opt/funmc`
|
||||||
|
- 安装依赖、编译 TypeScript
|
||||||
|
- 生成 `.env` 配置文件
|
||||||
|
- 创建 systemd 服务并自动启动
|
||||||
|
|
||||||
|
### 2.3 验证安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看服务状态
|
||||||
|
systemctl status funmc
|
||||||
|
|
||||||
|
# 测试 API
|
||||||
|
curl http://localhost:3000/api/health
|
||||||
|
# 应返回: {"status":"ok","nodeId":"...","isMaster":true,...}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 方式二:手动部署
|
||||||
|
|
||||||
|
适合需要自定义配置的场景。
|
||||||
|
|
||||||
|
### 3.1 安装 Node.js
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 方法一:使用 NodeSource 仓库(推荐)
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||||
|
sudo apt-get install -y nodejs
|
||||||
|
|
||||||
|
# 方法二:使用 nvm
|
||||||
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
|
||||||
|
source ~/.bashrc
|
||||||
|
nvm install 20
|
||||||
|
nvm use 20
|
||||||
|
|
||||||
|
# 验证
|
||||||
|
node -v # 应显示 v20.x.x
|
||||||
|
npm -v # 应显示 10.x.x
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 创建项目目录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mkdir -p /opt/funmc
|
||||||
|
sudo mkdir -p /opt/funmc/logs
|
||||||
|
cd /opt/funmc
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.3 上传并安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 将 server/ 内容复制到 /opt/funmc/
|
||||||
|
# 假设已上传到 /root/FunConnect/server/
|
||||||
|
sudo cp -r /root/FunConnect/server/* /opt/funmc/
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
cd /opt/funmc
|
||||||
|
sudo npm install --production
|
||||||
|
|
||||||
|
# 编译 TypeScript
|
||||||
|
sudo npx tsc
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.4 创建配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo cp .env.example .env
|
||||||
|
sudo nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 部署主节点
|
||||||
|
|
||||||
|
主节点是集群的核心,负责管理所有房间和工作节点。
|
||||||
|
|
||||||
|
### 4.1 配置文件
|
||||||
|
|
||||||
|
编辑 `/opt/funmc/.env`:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# ===== 网络配置 =====
|
||||||
|
# TCP 中继端口(Minecraft 流量转发)
|
||||||
|
RELAY_PORT=25565
|
||||||
|
|
||||||
|
# HTTP API 端口(管理面板和API)
|
||||||
|
API_PORT=3000
|
||||||
|
|
||||||
|
# ===== 节点配置 =====
|
||||||
|
# 节点名称(自定义,用于标识)
|
||||||
|
NODE_NAME=master-node
|
||||||
|
|
||||||
|
# 设为主节点
|
||||||
|
IS_MASTER=true
|
||||||
|
|
||||||
|
# 主节点URL(主节点自身留空)
|
||||||
|
MASTER_URL=
|
||||||
|
|
||||||
|
# ===== 安全配置 =====
|
||||||
|
# API 认证密钥(用于保护写操作,请修改为随机字符串)
|
||||||
|
SECRET=your-random-secret-key-here
|
||||||
|
|
||||||
|
# ===== 限制配置 =====
|
||||||
|
# 最大房间数
|
||||||
|
MAX_ROOMS=100
|
||||||
|
|
||||||
|
# 每房间最大玩家数
|
||||||
|
MAX_PLAYERS_PER_ROOM=20
|
||||||
|
|
||||||
|
# ===== 心跳配置 =====
|
||||||
|
# 心跳间隔(毫秒)
|
||||||
|
HEARTBEAT_INTERVAL=10000
|
||||||
|
|
||||||
|
# ===== 日志配置 =====
|
||||||
|
LOG_LEVEL=info
|
||||||
|
```
|
||||||
|
|
||||||
|
> **重要**:请将 `SECRET` 修改为一个强随机字符串,可以用 `openssl rand -hex 32` 生成。
|
||||||
|
|
||||||
|
### 4.2 创建 systemd 服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo tee /etc/systemd/system/funmc.service > /dev/null << 'EOF'
|
||||||
|
[Unit]
|
||||||
|
Description=FunConnect Minecraft Relay Server
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
WorkingDirectory=/opt/funmc
|
||||||
|
ExecStart=/usr/bin/node dist/index.js
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
Environment=NODE_ENV=production
|
||||||
|
|
||||||
|
# 日志输出到 journald
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
|
||||||
|
# 资源限制
|
||||||
|
LimitNOFILE=65535
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.3 启动服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable funmc
|
||||||
|
sudo systemctl start funmc
|
||||||
|
|
||||||
|
# 查看状态
|
||||||
|
sudo systemctl status funmc
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.4 验证主节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 健康检查
|
||||||
|
curl http://localhost:3000/api/health
|
||||||
|
|
||||||
|
# 查看统计
|
||||||
|
curl http://localhost:3000/api/stats
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
sudo journalctl -u funmc -f
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 部署工作节点
|
||||||
|
|
||||||
|
工作节点用于分担主节点的负载,可部署在不同地区的服务器上。
|
||||||
|
|
||||||
|
### 5.1 安装步骤
|
||||||
|
|
||||||
|
在新服务器上重复 [3.1] ~ [3.3] 的步骤。
|
||||||
|
|
||||||
|
### 5.2 配置文件
|
||||||
|
|
||||||
|
编辑 `/opt/funmc/.env`:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
RELAY_PORT=25565
|
||||||
|
API_PORT=3000
|
||||||
|
|
||||||
|
# 工作节点名称(每个节点不同)
|
||||||
|
NODE_NAME=worker-node-guangzhou
|
||||||
|
|
||||||
|
# 不是主节点
|
||||||
|
IS_MASTER=false
|
||||||
|
|
||||||
|
# 主节点地址(替换为主节点的实际IP)
|
||||||
|
MASTER_URL=http://主节点IP:3000
|
||||||
|
|
||||||
|
# 与主节点相同的密钥
|
||||||
|
SECRET=same-secret-as-master
|
||||||
|
|
||||||
|
MAX_ROOMS=100
|
||||||
|
MAX_PLAYERS_PER_ROOM=20
|
||||||
|
HEARTBEAT_INTERVAL=10000
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
|
# 本机公网IP(用于向主节点注册)
|
||||||
|
PUBLIC_HOST=本机公网IP
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.3 启动并注册
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动工作节点
|
||||||
|
sudo systemctl start funmc
|
||||||
|
|
||||||
|
# 验证工作节点已连接到主节点
|
||||||
|
curl http://localhost:3000/api/health
|
||||||
|
|
||||||
|
# 在主节点上查看是否注册成功
|
||||||
|
curl http://主节点IP:3000/api/nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.4 手动注册工作节点
|
||||||
|
|
||||||
|
如果工作节点没有自动注册,可以通过 API 手动注册:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://主节点IP:3000/api/nodes/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "x-auth-token: your-secret-key" \
|
||||||
|
-d '{
|
||||||
|
"name": "worker-node-guangzhou",
|
||||||
|
"host": "工作节点公网IP",
|
||||||
|
"apiPort": 3000,
|
||||||
|
"relayPort": 25565,
|
||||||
|
"maxRooms": 100,
|
||||||
|
"region": "guangzhou"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 部署 Web 管理面板
|
||||||
|
|
||||||
|
Web 管理面板用于可视化管理服务器。
|
||||||
|
|
||||||
|
### 6.1 开发模式
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/funmc/web
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
# 访问 http://服务器IP:5173
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.2 生产模式(推荐)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/funmc/web
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# 构建产物在 web/dist/ 目录
|
||||||
|
# 使用 Nginx 托管静态文件(见下方 Nginx 配置)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 防火墙配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用 ufw
|
||||||
|
sudo ufw allow 25565/tcp comment 'FunConnect Relay'
|
||||||
|
sudo ufw allow 3000/tcp comment 'FunConnect API'
|
||||||
|
sudo ufw allow 80/tcp comment 'HTTP'
|
||||||
|
sudo ufw allow 443/tcp comment 'HTTPS'
|
||||||
|
sudo ufw enable
|
||||||
|
|
||||||
|
# 查看规则
|
||||||
|
sudo ufw status
|
||||||
|
```
|
||||||
|
|
||||||
|
如果使用云服务器(阿里云、腾讯云等),还需要在**安全组**中开放对应端口:
|
||||||
|
|
||||||
|
| 端口 | 协议 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| 25565 | TCP | Minecraft 中继流量 |
|
||||||
|
| 3000 | TCP | HTTP API + WebSocket |
|
||||||
|
| 80 | TCP | Web 面板(HTTP) |
|
||||||
|
| 443 | TCP | Web 面板(HTTPS) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Nginx 反向代理(可选)
|
||||||
|
|
||||||
|
推荐使用 Nginx 反向代理 API 和托管 Web 管理面板。
|
||||||
|
|
||||||
|
### 8.1 安装 Nginx
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8.2 配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo tee /etc/nginx/sites-available/funconnect > /dev/null << 'EOF'
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name your-domain.com; # 替换为你的域名或IP
|
||||||
|
|
||||||
|
# Web 管理面板(静态文件)
|
||||||
|
location / {
|
||||||
|
root /opt/funmc/web/dist;
|
||||||
|
index index.html;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# API 反向代理
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
}
|
||||||
|
|
||||||
|
# WebSocket 反向代理
|
||||||
|
location /ws {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sudo ln -sf /etc/nginx/sites-available/funconnect /etc/nginx/sites-enabled/
|
||||||
|
sudo rm -f /etc/nginx/sites-enabled/default
|
||||||
|
sudo nginx -t
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. SSL 证书配置(可选)
|
||||||
|
|
||||||
|
使用 Let's Encrypt 免费证书:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装 certbot
|
||||||
|
sudo apt install -y certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# 申请证书(替换为你的域名)
|
||||||
|
sudo certbot --nginx -d your-domain.com
|
||||||
|
|
||||||
|
# 自动续期(certbot 会自动添加定时任务)
|
||||||
|
sudo certbot renew --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. 多节点集群配置
|
||||||
|
|
||||||
|
### 架构图
|
||||||
|
|
||||||
|
```
|
||||||
|
┌──────────────────┐
|
||||||
|
│ 主节点 (Master) │
|
||||||
|
│ IP: 1.2.3.4 │
|
||||||
|
│ Port: 25565 │
|
||||||
|
│ API: 3000 │
|
||||||
|
└───────┬──────────┘
|
||||||
|
│
|
||||||
|
┌─────────────┼──────────────┐
|
||||||
|
▼ ▼ ▼
|
||||||
|
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
||||||
|
│ 工作节点-华北 │ │ 工作节点-华南 │ │ 工作节点-华东 │
|
||||||
|
│ IP: 2.3.4.5 │ │ IP: 3.4.5.6 │ │ IP: 4.5.6.7 │
|
||||||
|
│ Port: 25565 │ │ Port: 25565 │ │ Port: 25565 │
|
||||||
|
└──────────────┘ └──────────────┘ └──────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### 工作流程
|
||||||
|
|
||||||
|
1. 所有工作节点向主节点发送心跳
|
||||||
|
2. 主节点汇总所有节点的房间和玩家信息
|
||||||
|
3. 客户端连接主节点获取房间列表
|
||||||
|
4. 客户端根据节点信息直接连接对应的工作节点
|
||||||
|
|
||||||
|
### 添加新节点步骤
|
||||||
|
|
||||||
|
1. 在新服务器上部署工作节点(见第5节)
|
||||||
|
2. 确保工作节点和主节点网络互通
|
||||||
|
3. 确保两端使用相同的 `SECRET`
|
||||||
|
4. 在 Web 管理面板 → 节点管理 → 添加节点
|
||||||
|
5. 或通过 API 注册(见 5.4)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 11. 运维管理
|
||||||
|
|
||||||
|
### 常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 服务管理
|
||||||
|
sudo systemctl start funmc # 启动
|
||||||
|
sudo systemctl stop funmc # 停止
|
||||||
|
sudo systemctl restart funmc # 重启
|
||||||
|
sudo systemctl status funmc # 状态
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
sudo journalctl -u funmc -f # 实时日志
|
||||||
|
sudo journalctl -u funmc --since today # 今日日志
|
||||||
|
sudo journalctl -u funmc -n 100 # 最近100行
|
||||||
|
|
||||||
|
# 更新服务
|
||||||
|
cd /opt/funmc
|
||||||
|
sudo systemctl stop funmc
|
||||||
|
sudo git pull # 或重新上传文件
|
||||||
|
sudo npm install --production
|
||||||
|
sudo npx tsc
|
||||||
|
sudo systemctl start funmc
|
||||||
|
```
|
||||||
|
|
||||||
|
### 监控
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# API 健康检查
|
||||||
|
curl -s http://localhost:3000/api/health | python3 -m json.tool
|
||||||
|
|
||||||
|
# 服务器统计
|
||||||
|
curl -s http://localhost:3000/api/stats | python3 -m json.tool
|
||||||
|
|
||||||
|
# 流量统计
|
||||||
|
curl -s http://localhost:3000/api/traffic | python3 -m json.tool
|
||||||
|
|
||||||
|
# 房间列表
|
||||||
|
curl -s http://localhost:3000/api/rooms | python3 -m json.tool
|
||||||
|
|
||||||
|
# 节点列表(主节点)
|
||||||
|
curl -s http://localhost:3000/api/nodes | python3 -m json.tool
|
||||||
|
```
|
||||||
|
|
||||||
|
### 备份
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 备份配置
|
||||||
|
sudo cp /opt/funmc/.env /opt/funmc/.env.backup
|
||||||
|
|
||||||
|
# 备份日志
|
||||||
|
sudo cp -r /opt/funmc/logs /opt/funmc/logs.backup
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 12. 常见问题
|
||||||
|
|
||||||
|
### Q: 服务启动失败?
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看详细错误
|
||||||
|
sudo journalctl -u funmc -n 50 --no-pager
|
||||||
|
|
||||||
|
# 常见原因:
|
||||||
|
# 1. 端口被占用
|
||||||
|
sudo lsof -i :25565
|
||||||
|
sudo lsof -i :3000
|
||||||
|
|
||||||
|
# 2. Node.js 版本过低
|
||||||
|
node -v # 需要 18+
|
||||||
|
|
||||||
|
# 3. 依赖未安装
|
||||||
|
cd /opt/funmc && sudo npm install --production
|
||||||
|
```
|
||||||
|
|
||||||
|
### Q: 玩家无法连接?
|
||||||
|
|
||||||
|
1. 检查防火墙是否开放 25565 端口
|
||||||
|
2. 检查云服务器安全组是否放行
|
||||||
|
3. 检查服务是否正在运行:`systemctl status funmc`
|
||||||
|
4. 测试端口连通性:`telnet 服务器IP 25565`
|
||||||
|
|
||||||
|
### Q: 工作节点无法注册?
|
||||||
|
|
||||||
|
1. 确保主节点和工作节点网络互通
|
||||||
|
2. 确保 `.env` 中 `MASTER_URL` 正确
|
||||||
|
3. 确保两端 `SECRET` 一致
|
||||||
|
4. 检查主节点 API 是否可访问:`curl http://主节点IP:3000/api/health`
|
||||||
|
|
||||||
|
### Q: Web 面板打不开?
|
||||||
|
|
||||||
|
1. 如果是开发模式,确认访问 `http://IP:5173`
|
||||||
|
2. 如果是生产模式 + Nginx,确认 Nginx 配置正确
|
||||||
|
3. 检查 Nginx 状态:`sudo systemctl status nginx`
|
||||||
|
|
||||||
|
### Q: 如何修改端口?
|
||||||
|
|
||||||
|
编辑 `/opt/funmc/.env`,修改 `RELAY_PORT` 和 `API_PORT`,然后重启:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl restart funmc
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 快速部署清单
|
||||||
|
|
||||||
|
- [ ] 服务器 Ubuntu 20.04+,已开放 25565 和 3000 端口
|
||||||
|
- [ ] 安装 Node.js 18+
|
||||||
|
- [ ] 上传 server/ 目录到服务器
|
||||||
|
- [ ] 安装依赖:`npm install --production`
|
||||||
|
- [ ] 编译:`npx tsc`
|
||||||
|
- [ ] 创建 `.env` 配置文件
|
||||||
|
- [ ] 创建 systemd 服务
|
||||||
|
- [ ] 启动服务:`systemctl start funmc`
|
||||||
|
- [ ] 验证:`curl http://localhost:3000/api/health`
|
||||||
|
- [ ] (可选)配置 Nginx 反向代理
|
||||||
|
- [ ] (可选)配置 SSL 证书
|
||||||
|
- [ ] (可选)部署工作节点扩展集群
|
||||||
@@ -64,6 +64,8 @@ chmod +x deploy/install.sh
|
|||||||
sudo ./deploy/install.sh
|
sudo ./deploy/install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> **详细部署教程**(主节点、工作节点、Nginx、SSL、多节点集群)请查看 [DEPLOY.md](DEPLOY.md)
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user