From e73c8e536e59f62e7974280c7febbda4edab9237 Mon Sep 17 00:00:00 2001 From: FunMC Date: Mon, 23 Feb 2026 08:02:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v1.1.0=20=E5=85=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=89=93=E5=8C=85=20+=20=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E6=9C=8D=E5=8A=A1=E7=AB=AF=E9=83=A8=E7=BD=B2=E6=95=99?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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)配置 - 多节点集群架构说明 - 运维管理命令和监控 - 常见问题排查 - 快速部署清单 --- client/README.md | 113 +++++++- client/build/icon.ico | Bin 0 -> 1980 bytes client/build/icon.png | Bin 0 -> 1958 bytes client/package.json | 73 +++++- server/DEPLOY.md | 591 ++++++++++++++++++++++++++++++++++++++++++ server/README.md | 2 + 6 files changed, 759 insertions(+), 20 deletions(-) create mode 100644 client/build/icon.ico create mode 100644 client/build/icon.png create mode 100644 server/DEPLOY.md diff --git a/client/README.md b/client/README.md index 994301f..bc2605f 100644 --- a/client/README.md +++ b/client/README.md @@ -1,6 +1,19 @@ # 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 +cd client npm install ``` -> 如果 Electron 下载慢,使用国内镜像: +> **国内镜像加速**(解决 Electron 下载慢): > ```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 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 -npm run dist -# 输出到 release/ 目录 +# DMG 安装包 +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/ +├── build/ # 构建资源(图标等) +│ ├── icon.png # 应用图标 (256x256) +│ └── icon.ico # Windows 图标 ├── src/main/ │ ├── index.ts # Electron 主进程 │ ├── preload.ts # 预加载脚本(IPC桥接) @@ -74,9 +163,7 @@ client/ └── tsconfig.json ``` -## 配置说明 - -设置页面中可配置: +## 设置说明 | 设置项 | 默认值 | 说明 | |--------|--------|------| @@ -91,4 +178,4 @@ client/ - **TypeScript** - 主进程开发 - **electron-store** - 设置持久化 - **Axios** - HTTP 请求 -- **electron-builder** - 打包发布 +- **electron-builder** - 全平台打包发布 diff --git a/client/build/icon.ico b/client/build/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..c28e85331bc71dc6357e8fd8136c542d4d94397f GIT binary patch literal 1980 zcmb_d|5sB-7M~ZA@Z{@@&@_B$lb{Q>h=Kt`1QH}b!7nVeA|6;xYazDsoh|}G@&c4E zT>`YIr!681)I$pe6a`mQpwK9ygsc{c5fTk&jfg@J=>w9yeX&2Zf56V1nR{nG_jBjY zojKl)Cc?z&8T_6R6-&JvjET4(C}Etf38PWliw+qul{5)_AxFi3bZ5We>Psw zp&N$f^b-m^=dA75VQ*6fY=s4#Ld;r6vUwgkvdDqXuMO^uj^KIS{!=Y79L;B~)(k&2LMT383YRL3c@^;yb~ zEf3*LfZ`5jiH=iJ#4w6{%0u>UC{oP16zjUa9AXr1`V#E)UNKlf=LOhhN62Pi{-`JU z%H66#d_}Gvk(##3;m}3p5I@IBG&Io_84Ay{_mwe&b)Ux~(6y$A^G%k$VK#h_RLTs# zU0=*1?;Z{@=pHBe9)}y{zI(pOGbq-zo`p5^0|cq%wiUGJ>r8_}tBj)chuQR1D|aA; zORCz>h%H?+%({y;-5fhWJMz_IP6FJxRZ*(bM>2CpZ6)w}8TKA&w@*Rbn$X3#?m_dS z!dbldIOz;h&O>A|1V_J@{QX)VlWuU>nT<$>8Qk!*@0o#0efH(nb;$J#m)cy#i{}o9 zgtHK>kQ&YcTA_Qmz(*!eY5$71xb%yUD0v^*y=!KMSy&UlzkyWiEsBdJy9*3$%`p-Q zgX{S|$s#`Ub#=&wM+6%4$awv< zebnSwKK1fm?rQe2Nz%Il!)zmLplXF4g;s`=9&Yb5`n-coUUikSOSBrv6)bR6YSJ~M zQaRoO(#03`Uj5kcTz4-eceS>I5Df0}cw7&FSn7xFKo(<~qSFwt@Ov5)Xg#<&&tVuW zUr(Ii23#y8k4RzC8JfbTPzwu;Gt0Qd&VdSe`jK*=&aIq4r;#_8kAna1qY=lsCl|kztr#+pb3N{i8uvyo$H3?op_?OALsB^ z^P?T!dEF?a@W>O2tOs~2lwr+cCM>LM2GfiYswSFTK&_ecI&SQ920dWm`VVST7l}oh z)l~N23m~zA@ZWK&&veKZm4k)fyr$lukCdtH`2Kaot3{YSB2dn;-kv@plF2Q=jVF59 zt>uzY!~LHvGKf2ky|^hRe#;mg3gDv!!a6;Z#JjPVNXG7ZKhq^B;1TH-vpavaPebSV z7q0esdjhw9tAoM!5~O&BwIDm8&v=NCkt#xdn`ezc$zS{z8=+{3JM*G&8U#vf)N>_p=S3O5 ze!tj8Y%g#ZR*P4GYZ|oiryiWgM^E~i2HG%31ggsT6?;RWk6|8NZbWF?r-F~l#59_~ zUn*v|hEVvZFwsv0VQXjts+5b+1kJJr^dt=-i3&f#WL(L1ZVTLb8>48*Zai&z6+DL3 zInW^Xgi0tc)o+dDp~!UB zeU6`LN6@Rz5`jI(MvYkvuZ7qx+X}R5bQcXN3LM;OlIAXjT7{-{*{U&zZ+u8QYK~$u zHQL5TimxbKM4T;=Jb2trjn!>=a!zg+`a9!}DK)ZQqU);kXjxli7aITC#W`fkdxqC$ zGqA}ge)+hxU{oQb7dzzz#Fd?mc5D<8CBc8C?Gv}&5>}v<0#6>inHs@7y^*bZQu*}l zLU$U9-2czK&uOQ!Xn4V1jp<7dlbj3GkH{9b7pYcnpL!ZPdjm31Z9 z#F^R^LfEBqq5mbLq+Gpu<&GfC%`WTm20k945Rz@nL#Ca6L5%7C1V!Z literal 0 HcmV?d00001 diff --git a/client/build/icon.png b/client/build/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..571b810b303a649a94f8f3f86e88dffeb87eba32 GIT binary patch literal 1958 zcmb_d`&Uy}7Ctv5;mY$yXc``E5_G^8QDOiQfdmOq@WC)v#08^iEyPydbPyDh%cDFx z1ZYuLTSOFS7gH#pQE)^B3XLL4$Y_xmArRXcLT$c27b8`2dM$@3P%%J7E+dJ&xDaol&in>n?pTu{?or&PFN zVMa!fn|W4wQeT3%NeWh;_x&1)*Z%@WDnqAf;hpp{J-67Nvv@qNB9uD;N;;XPdTwbk z!z|`hgznu?tekTz(aXLVVia!r0_^l%HrYTw2(in~kln!iQE&28V}{&rC}ELz4~LrckCXjQ zz)cFjJzwXWl`^cWMnHgqbZNmOWQk}0jK91}uG_|+H78Nmg-tUvF60%;`gl>35 zps`P0C~jY+1Q!`{tRu8kxuU_j=%3ijr|CBR(N>?~}YTUq9^_wK!Kyy}XyVl5=d5 z^sdk}+XS1aI+0hQjj6PU*ZYh@}zM1XGsj6FVhTqM9Oc zk`wU0)j_7poJ)AwJZamWlYNc<1ix)`zfPge$ zas=BnmvAScY1(z~6p4%`HUELf|1OjOvE01DCxHNtJ|t=jlGn zA$wE-7Jl`adV@YvrFG!@*AcH4xvGdjxyO2Y`iPxOZUG*A@yl)04)&J8<-^ijlINW>~8S4T!I20k!~@&kFWG;>HL7gl|El@;L&e$FyvmM z6wkC3<|Ou+4-q~}P55u}Z4oHt^Z#Na6fLpFy>6Ba_@I9`E=o{1^OzKON}=+}jAsq6 z9)4yjPXt@X)%bdk{z*TJ?Hvaq<9k`BMNQEnPdarTHx&99<|XqWwzhpL0$FO=Q8pNJZixg#s&5`6I zrn@xARg%->!6ILN$6%83)~qIuPFj1A3#;637&h})b1JJ*WIFpk*Wa=u_*GY_(2;AW z!K{YYLhROU1v(A7i-r^j4Q{na^A^Kw!qR2-8qDcy4rxd2QB1Bu+u2CT6{VY)yCsSb zk2`3v`Ylh+D;&apW8AT%MKu)ZWmR6SYl|Ji5?;HxhEDm;@Z0SMHgOV`PDl$zl_GkH zOMYN{`MDV9CNa?x0+!o9_UJ8T1=%R^l);;6k<2q2+4?6{Pv0)|q@l?D|IBmFxRl4h z3yvDhP=L5oOn3jtgC+VoyFpspICcXiA-59?L~(6_Cqfm;Jd_qBv9& X6BB%M%?Ec^yJvL79zn+rVe$U}lW=qA literal 0 HcmV?d00001 diff --git a/client/package.json b/client/package.json index 405a765..9ef800a 100644 --- a/client/package.json +++ b/client/package.json @@ -1,20 +1,25 @@ { "name": "funconnect", - "version": "1.0.0", - "description": "FunMC Minecraft 联机客户端", + "version": "1.1.0", + "description": "FunConnect - Minecraft 跨平台联机客户端", "main": "dist/main/index.js", - "author": "FunMC", + "author": "FunMC ", "license": "MIT", "scripts": { "build:ts": "tsc", "start": "npm run build:ts && electron .", "dev": "tsc && electron .", "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": { "appId": "cn.funmc.connect", "productName": "FunConnect", + "copyright": "Copyright © 2024 FunMC", "directories": { "output": "release" }, @@ -24,12 +29,66 @@ "package.json" ], "win": { - "target": "nsis", - "icon": "renderer/icon.ico" + "target": [ + { + "target": "nsis", + "arch": ["x64", "ia32"] + }, + { + "target": "portable", + "arch": ["x64"] + } + ], + "icon": "build/icon.ico", + "artifactName": "FunConnect-${version}-Win-${arch}.${ext}" }, "nsis": { "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": { diff --git a/server/DEPLOY.md b/server/DEPLOY.md new file mode 100644 index 0000000..87af98b --- /dev/null +++ b/server/DEPLOY.md @@ -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 证书 +- [ ] (可选)部署工作节点扩展集群 diff --git a/server/README.md b/server/README.md index fe83394..421b229 100644 --- a/server/README.md +++ b/server/README.md @@ -64,6 +64,8 @@ chmod +x deploy/install.sh sudo ./deploy/install.sh ``` +> **详细部署教程**(主节点、工作节点、Nginx、SSL、多节点集群)请查看 [DEPLOY.md](DEPLOY.md) + ## 项目结构 ```