Initial commit: FunConnect project with server, relay, client and admin panel

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-24 20:56:36 +08:00
parent eb6e901440
commit b6891483ae
167 changed files with 16147 additions and 106 deletions

574
docs/DEPLOYMENT.md Normal file
View File

@@ -0,0 +1,574 @@
# FunMC 部署指南
本文档详细介绍如何部署 FunMC 服务端和客户端。
## 目录
- [系统要求](#系统要求)
- [快速部署 (Docker)](#快速部署-docker)
- [手动部署](#手动部署)
- [生产环境配置](#生产环境配置)
- [监控与维护](#监控与维护)
- [局域网部署](#局域网部署)
---
## 系统要求
### 服务器
| 组件 | 最低要求 | 推荐配置 |
|------|---------|---------|
| CPU | 1 核 | 2 核+ |
| 内存 | 512 MB | 1 GB+ |
| 存储 | 1 GB | 10 GB+ |
| 系统 | Ubuntu 20.04 / Debian 11 / CentOS 8 | Ubuntu 22.04 LTS |
| 网络 | 1 Mbps | 10 Mbps+ |
### 开放端口
| 端口 | 协议 | 用途 |
|------|------|------|
| 80 | TCP | HTTP (重定向到 HTTPS) |
| 443 | TCP | HTTPS (API + WebSocket) |
| 7900 | UDP | QUIC 中继服务 (主线路) |
| 7901 | UDP | QUIC 中继服务 (备用) |
---
## 快速部署 (Docker)
### 1. 安装 Docker
```bash
# Ubuntu/Debian
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# 安装 Docker Compose
sudo apt install docker-compose-plugin
```
### 2. 获取配置文件
```bash
# 克隆仓库
git clone https://github.com/mofangfang/funmc.git
cd funmc
# 或者只下载 Docker 配置
mkdir funmc && cd funmc
curl -O https://raw.githubusercontent.com/mofangfang/funmc/main/docker/docker-compose.yml
curl -O https://raw.githubusercontent.com/mofangfang/funmc/main/.env.example
```
### 3. 配置环境变量
```bash
cp .env.example .env
```
编辑 `.env` 文件:
```env
# 数据库配置
POSTGRES_USER=funmc
POSTGRES_PASSWORD=your_secure_password_here
POSTGRES_DB=funmc
# JWT 密钥 (至少 32 字符)
JWT_SECRET=change-this-to-a-very-long-random-string-at-least-32-chars
# 服务器地址
SERVER_DOMAIN=funmc.example.com
# 中继服务器配置
RELAY_PORT=7900
RELAY_BACKUP_PORT=7901
```
### 4. 启动服务
```bash
# 启动所有服务
docker compose up -d
# 查看运行状态
docker compose ps
# 查看日志
docker compose logs -f
# 停止服务
docker compose down
```
### 5. 配置 SSL 证书
推荐使用 Certbot 获取免费 SSL 证书:
```bash
# 安装 Certbot
sudo apt install certbot
# 获取证书
sudo certbot certonly --standalone -d funmc.example.com
# 证书位置
# /etc/letsencrypt/live/funmc.example.com/fullchain.pem
# /etc/letsencrypt/live/funmc.example.com/privkey.pem
```
---
## 手动部署
### 1. 安装依赖
#### Ubuntu/Debian
```bash
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装基础工具
sudo apt install -y build-essential pkg-config libssl-dev curl git
# 安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# 安装 PostgreSQL
sudo apt install -y postgresql postgresql-contrib
# 启动 PostgreSQL
sudo systemctl enable postgresql
sudo systemctl start postgresql
```
#### CentOS/RHEL
```bash
# 更新系统
sudo dnf update -y
# 安装基础工具
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y openssl-devel curl git
# 安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# 安装 PostgreSQL
sudo dnf install -y postgresql-server postgresql-contrib
sudo postgresql-setup --initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql
```
### 2. 配置数据库
```bash
# 切换到 postgres 用户
sudo -u postgres psql
# 在 psql 中执行:
CREATE DATABASE funmc;
CREATE USER funmc WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE funmc TO funmc;
\q
```
编辑 `/etc/postgresql/14/main/pg_hba.conf` (版本号可能不同):
```
# 添加以下行允许本地密码认证
local funmc funmc md5
host funmc funmc 127.0.0.1/32 md5
```
重启 PostgreSQL:
```bash
sudo systemctl restart postgresql
```
### 3. 编译服务
```bash
# 克隆仓库
git clone https://github.com/mofangfang/funmc.git
cd funmc
# 编译主服务器
cargo build --release -p funmc-server
# 编译中继服务器
cargo build --release -p funmc-relay-server
# 复制二进制文件
sudo mkdir -p /opt/funmc/bin
sudo cp target/release/funmc-server /opt/funmc/bin/
sudo cp target/release/funmc-relay-server /opt/funmc/bin/
```
### 4. 配置服务
创建配置目录:
```bash
sudo mkdir -p /etc/funmc
```
创建主服务器配置 `/etc/funmc/server.env`:
```env
# 数据库连接
DATABASE_URL=postgres://funmc:your_password@localhost/funmc
# JWT 密钥
JWT_SECRET=your-super-secret-jwt-key-at-least-32-characters
# 服务绑定地址
BIND_ADDR=127.0.0.1:3000
# 内置 QUIC 中继端口
QUIC_PORT=3001
# 日志级别
RUST_LOG=funmc_server=info,tower_http=info
```
创建中继服务器配置 `/etc/funmc/relay.env`:
```env
# 中继端口
RELAY_PORT=7900
# JWT 密钥 (必须与主服务器一致)
JWT_SECRET=your-super-secret-jwt-key-at-least-32-characters
# 日志级别
RUST_LOG=funmc_relay_server=info
```
### 5. 运行数据库迁移
```bash
cd /path/to/funmc/server
# 安装 sqlx-cli
cargo install sqlx-cli --no-default-features --features postgres
# 运行迁移
DATABASE_URL=postgres://funmc:your_password@localhost/funmc sqlx migrate run
```
### 6. 创建 Systemd 服务
主服务器 `/etc/systemd/system/funmc-server.service`:
```ini
[Unit]
Description=FunMC API Server
After=network.target postgresql.service
[Service]
Type=simple
User=funmc
Group=funmc
WorkingDirectory=/opt/funmc
EnvironmentFile=/etc/funmc/server.env
ExecStart=/opt/funmc/bin/funmc-server
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
```
中继服务器 `/etc/systemd/system/funmc-relay.service`:
```ini
[Unit]
Description=FunMC Relay Server
After=network.target
[Service]
Type=simple
User=funmc
Group=funmc
WorkingDirectory=/opt/funmc
EnvironmentFile=/etc/funmc/relay.env
ExecStart=/opt/funmc/bin/funmc-relay-server
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
```
创建服务用户并启动:
```bash
# 创建用户
sudo useradd -r -s /bin/false funmc
# 设置权限
sudo chown -R funmc:funmc /opt/funmc
# 重载 systemd
sudo systemctl daemon-reload
# 启动服务
sudo systemctl enable funmc-server funmc-relay
sudo systemctl start funmc-server funmc-relay
# 检查状态
sudo systemctl status funmc-server funmc-relay
```
---
## 生产环境配置
### Nginx 反向代理
安装 Nginx:
```bash
sudo apt install -y nginx
```
创建配置 `/etc/nginx/sites-available/funmc`:
```nginx
# HTTP 重定向到 HTTPS
server {
listen 80;
server_name funmc.example.com;
return 301 https://$server_name$request_uri;
}
# HTTPS 配置
server {
listen 443 ssl http2;
server_name funmc.example.com;
# SSL 证书
ssl_certificate /etc/letsencrypt/live/funmc.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/funmc.example.com/privkey.pem;
# SSL 安全配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers off;
# 日志
access_log /var/log/nginx/funmc_access.log;
error_log /var/log/nginx/funmc_error.log;
# API 代理
location / {
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
# WebSocket 代理
location /api/v1/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;
proxy_read_timeout 86400;
}
}
```
启用配置:
```bash
sudo ln -s /etc/nginx/sites-available/funmc /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```
### 防火墙配置
```bash
# UFW (Ubuntu)
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 7900/udp
sudo ufw allow 7901/udp
sudo ufw enable
# firewalld (CentOS)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-port=7900/udp
sudo firewall-cmd --permanent --add-port=7901/udp
sudo firewall-cmd --reload
```
---
## 监控与维护
### 日志查看
```bash
# 主服务器日志
sudo journalctl -u funmc-server -f
# 中继服务器日志
sudo journalctl -u funmc-relay -f
# Nginx 访问日志
sudo tail -f /var/log/nginx/funmc_access.log
```
### 数据库备份
```bash
# 备份
pg_dump -U funmc -d funmc > backup_$(date +%Y%m%d).sql
# 恢复
psql -U funmc -d funmc < backup_20240101.sql
```
### 更新服务
```bash
cd /path/to/funmc
git pull
# 重新编译
cargo build --release -p funmc-server -p funmc-relay-server
# 更新二进制
sudo systemctl stop funmc-server funmc-relay
sudo cp target/release/funmc-server /opt/funmc/bin/
sudo cp target/release/funmc-relay-server /opt/funmc/bin/
sudo systemctl start funmc-server funmc-relay
```
---
## 局域网部署
如果只需要在局域网内使用 FunMC可以使用简化配置。
### 局域网服务器配置
1. **安装依赖**(同上)
2. **简化配置** `/etc/funmc/server.env`:
```env
DATABASE_URL=postgres://funmc:password@localhost/funmc
JWT_SECRET=local-development-secret-key-32chars
BIND_ADDR=0.0.0.0:3000
QUIC_PORT=3001
RUST_LOG=info
```
3. **启动服务**:
```bash
# 直接运行
./funmc-server
# 或使用 systemd
sudo systemctl start funmc-server
```
### 客户端配置
编辑客户端配置文件,将服务器地址改为局域网 IP:
文件位置: `client/src/config.rs`
```rust
pub const DEFAULT_SERVER_URL: &str = "http://192.168.1.100:3000";
pub const DEFAULT_RELAY_URL: &str = "192.168.1.100:7900";
```
或者在客户端设置页面修改服务器地址。
### 局域网联机测试
1. **启动 Minecraft 服务器**
- 在一台电脑上启动 Minecraft 服务器
- 或在单人世界中开启局域网联机
2. **主机操作**
- 打开 FunMC 客户端
- 登录账号(首次需要注册)
- 创建房间
- 点击"开始托管"
3. **玩家操作**
- 打开 FunMC 客户端
- 登录账号
- 在大厅找到房间并加入
- 点击"连接"
- 复制显示的地址(如 `127.0.0.1:25566`
- 在 Minecraft 中添加服务器并连接
4. **验证连接**
- 检查 FunMC 显示的连接类型
- 局域网内通常会显示"P2P 直连"
- 如果是"中继",检查防火墙设置
---
## 常见问题
### 数据库连接失败
```
Error: connection refused
```
解决方案:
1. 检查 PostgreSQL 服务是否运行: `sudo systemctl status postgresql`
2. 检查 pg_hba.conf 配置
3. 确认用户名密码正确
### QUIC 端口无法连接
```
Error: connection timed out
```
解决方案:
1. 检查防火墙是否开放 UDP 端口
2. 确认端口没有被其他程序占用: `sudo netstat -ulnp | grep 7900`
### WebSocket 连接断开
解决方案:
1. 检查 Nginx 配置中的 `proxy_read_timeout`
2. 确认客户端心跳正常发送
---
## 支持
如有问题,请通过以下方式获取帮助:
- GitHub Issues: https://github.com/mofangfang/funmc/issues
- 官方文档: https://docs.funmc.com
- 邮箱: support@funmc.com
---
*魔幻方开发 © 2024*

309
docs/LAN_TEST.md Normal file
View File

@@ -0,0 +1,309 @@
# FunMC 局域网联机测试指南
本文档介绍如何测试 FunMC 的局域网联机功能。
## 测试环境准备
### 硬件要求
- 至少 2 台电脑(或使用虚拟机)
- 所有设备在同一局域网内
- 每台设备需安装 Minecraft Java Edition
### 软件要求
- PostgreSQL 14+
- Rust 1.75+
- Node.js 18+
- Minecraft Java Edition 1.16+
---
## 测试步骤
### 第一步:部署本地服务器
在其中一台电脑上部署 FunMC 服务器:
```bash
# 1. 克隆项目
git clone https://github.com/mofangfang/funmc.git
cd funmc
# 2. 启动数据库
docker run -d --name funmc-db \
-p 5432:5432 \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=funmc \
postgres:14
# 3. 配置环境变量
cat > server/.env << EOF
DATABASE_URL=postgres://postgres:password@localhost/funmc
JWT_SECRET=test-jwt-secret-for-local-development
BIND_ADDR=0.0.0.0:3000
QUIC_PORT=3001
RUST_LOG=info
EOF
# 4. 运行数据库迁移
cd server
cargo sqlx database create
cargo sqlx migrate run
# 5. 启动主服务器
cargo run
```
记录服务器的局域网 IP 地址(如 `192.168.1.100`)。
### 第二步:配置客户端
在所有参与测试的电脑上:
1. 修改客户端配置文件 `client/src/config.rs`:
```rust
pub const DEFAULT_SERVER_URL: &str = "http://192.168.1.100:3000";
```
2. 编译并运行客户端:
```bash
cd client/ui
npm install
cd ..
cargo tauri dev
```
### 第三步:测试场景
#### 场景 1基本局域网联机
**主机操作:**
1. 启动 Minecraft创建单人世界
2.`Esc``对局域网开放`
3. 选择游戏模式,点击「开始局域网世界」
4. 记下显示的端口号(如 25565
5. 打开 FunMC 客户端
6. 注册/登录账号
7. 创建房间(填写房间名、游戏版本)
8. 点击「开始托管」
**预期结果:**
- FunMC 显示"托管中"状态
- 显示 QUIC 端口号
**玩家操作:**
1. 打开 FunMC 客户端
2. 登录账号
3. 在大厅找到主机创建的房间
4. 点击加入房间
5. 在房间页面点击「连接」
6. 等待连接建立
7. 复制显示的地址(如 `127.0.0.1:25566`
8. 打开 Minecraft → 多人游戏 → 添加服务器
9. 粘贴地址并连接
**预期结果:**
- FunMC 显示连接类型P2P 直连 或 中继)
- 能够成功进入 Minecraft 服务器
#### 场景 2P2P 直连测试
在局域网环境下,两台电脑应该能够建立 P2P 直连。
**验证方法:**
1. 连接成功后,检查 FunMC 显示的连接类型
2. 应显示「P2P 直连」
3. 延迟应该很低(通常 < 10ms
**如果显示「中继」:**
- 检查防火墙设置
- 确认 UDP 端口 34000-34100 未被阻止
- 检查路由器是否启用了 UPnP
#### 场景 3房间聊天测试
1. 主机和玩家都进入同一房间
2. 在房间页面的聊天框中发送消息
3. 验证双方都能收到消息
**预期结果:**
- 消息实时显示
- 显示发送者用户名和时间
#### 场景 4多玩家测试
1. 让 3 人以上加入同一房间
2. 所有人都点击「连接」
3. 所有人都进入 Minecraft 服务器
**预期结果:**
- 所有玩家都能成功连接
- 游戏内能看到所有玩家
#### 场景 5断线重连测试
1. 建立连接并进入游戏
2. 在 FunMC 中点击「断开连接」
3. 重新点击「连接」
4. 在 Minecraft 中重新连接服务器
**预期结果:**
- 能够重新建立连接
- 游戏继续正常进行
---
## 测试检查清单
### 服务端检查
| 检查项 | 预期结果 | 实际结果 |
|--------|---------|---------|
| 服务器启动 | 无错误日志 | |
| 数据库连接 | 连接成功 | |
| API 响应 | 返回 200 OK | |
| WebSocket | 能够建立连接 | |
### 客户端检查
| 检查项 | 预期结果 | 实际结果 |
|--------|---------|---------|
| 注册功能 | 成功创建账号 | |
| 登录功能 | 成功登录 | |
| 创建房间 | 房间出现在大厅 | |
| 加入房间 | 成功进入房间 | |
| 开始托管 | 状态显示"托管中" | |
| 连接功能 | 显示代理地址 | |
| 聊天功能 | 消息实时同步 | |
### 网络检查
| 检查项 | 预期结果 | 实际结果 |
|--------|---------|---------|
| P2P 连接 | 局域网内成功 | |
| 中继连接 | 作为备用可用 | |
| 延迟 | P2P < 10ms | |
| 数据传输 | Minecraft 流量正常 | |
---
## 常见问题排查
### 问题 1无法连接到服务器
**症状:** 客户端显示"连接失败"
**排查步骤:**
1. 确认服务器正在运行:
```bash
curl http://192.168.1.100:3000/api/v1/rooms
```
2. 检查防火墙:
```bash
# Windows
netsh advfirewall firewall add rule name="FunMC" dir=in action=allow protocol=TCP localport=3000
# Linux
sudo ufw allow 3000/tcp
```
3. 确认网络连通:
```bash
ping 192.168.1.100
```
### 问题 2P2P 连接失败
**症状:** 始终使用中继连接
**排查步骤:**
1. 检查 UDP 端口:
```bash
# 确认端口 34000-34100 未被占用
netstat -an | grep 34000
```
2. 检查 NAT 类型(对称型 NAT 无法打洞)
3. 暂时禁用防火墙测试
### 问题 3Minecraft 无法连接
**症状:** 在 Minecraft 中添加服务器后连接失败
**排查步骤:**
1. 确认 FunMC 显示"已连接"
2. 检查代理地址是否正确复制
3. 确认 Minecraft 服务器正在运行
4. 检查 Minecraft 版本兼容性
### 问题 4延迟过高
**症状:** 游戏卡顿,延迟 > 100ms
**排查步骤:**
1. 检查是否使用 P2P 直连
2. 检查网络带宽
3. 关闭其他占用带宽的程序
4. 尝试使用有线网络代替 WiFi
---
## 性能测试
### 延迟测试
使用 FunMC 内置的延迟显示功能:
| 连接类型 | 预期延迟 |
|---------|---------|
| P2P (局域网) | < 5ms |
| P2P (公网) | 10-50ms |
| 中继 | 50-150ms |
### 带宽测试
Minecraft 典型带宽需求:
- 单人连接:约 50-100 KB/s
- 多人服务器:每人约 100-200 KB/s
---
## 测试报告模板
```
测试日期: ____________
测试人员: ____________
FunMC 版本: ____________
测试环境:
- 服务器 IP: ____________
- 参与电脑数量: ____________
- Minecraft 版本: ____________
测试结果:
- 基本联机: [ ] 通过 [ ] 失败
- P2P 直连: [ ] 通过 [ ] 失败
- 房间聊天: [ ] 通过 [ ] 失败
- 多玩家: [ ] 通过 [ ] 失败
- 断线重连: [ ] 通过 [ ] 失败
问题记录:
____________________________________________
建议改进:
____________________________________________
```
---
## 联系支持
如测试中遇到问题,请通过以下方式反馈:
- GitHub Issues: https://github.com/mofangfang/funmc/issues
- 邮箱: support@funmc.com
---
*魔幻方开发 © 2024*

218
docs/NO_PUBLIC_IP.md Normal file
View File

@@ -0,0 +1,218 @@
# 无公网 IP 部署方案
如果你的服务器没有公网 IP比如家庭宽带、公司内网可以使用以下方案
## 方案一:使用云服务器(推荐)
购买一台云服务器阿里云、腾讯云、AWS 等),价格低至几十元/月:
```bash
# 在云服务器上一键部署
curl -fsSL https://raw.githubusercontent.com/mofangfang/funmc/main/deploy.sh | bash
```
优点:
- 稳定可靠24小时在线
- 有固定公网 IP
- 部署简单
## 方案二:使用内网穿透工具
### 使用 frp免费开源
1. **在有公网 IP 的服务器上部署 frps**
```bash
# 下载 frp
wget https://github.com/fatedier/frp/releases/download/v0.52.0/frp_0.52.0_linux_amd64.tar.gz
tar -xzf frp_0.52.0_linux_amd64.tar.gz
cd frp_0.52.0_linux_amd64
# 配置 frps.toml
cat > frps.toml << 'EOF'
bindPort = 7000
auth.token = "your_secret_token"
EOF
# 启动
./frps -c frps.toml
```
2. **在内网服务器上部署 frpc + FunMC**
```bash
# 先部署 FunMC
docker-compose up -d
# 配置 frpc.toml
cat > frpc.toml << 'EOF'
serverAddr = "你的frps服务器IP"
serverPort = 7000
auth.token = "your_secret_token"
[[proxies]]
name = "funmc-api"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3000
remotePort = 3000
[[proxies]]
name = "funmc-quic"
type = "udp"
localIP = "127.0.0.1"
localPort = 3001
remotePort = 3001
[[proxies]]
name = "funmc-relay1"
type = "udp"
localIP = "127.0.0.1"
localPort = 7900
remotePort = 7900
[[proxies]]
name = "funmc-relay2"
type = "udp"
localIP = "127.0.0.1"
localPort = 7901
remotePort = 7901
EOF
# 启动 frpc
./frpc -c frpc.toml
```
### 使用 Cloudflare Tunnel免费
适合只需要 HTTP/WebSocket 的场景(不支持 UDP中继功能需要单独处理
```bash
# 安装 cloudflared
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared
chmod +x cloudflared
# 登录
./cloudflared tunnel login
# 创建隧道
./cloudflared tunnel create funmc
# 配置
cat > ~/.cloudflared/config.yml << 'EOF'
tunnel: funmc
credentials-file: ~/.cloudflared/<tunnel-id>.json
ingress:
- hostname: funmc.your-domain.com
service: http://localhost:3000
- service: http_status:404
EOF
# 添加 DNS 记录
./cloudflared tunnel route dns funmc funmc.your-domain.com
# 启动
./cloudflared tunnel run funmc
```
**注意**: Cloudflare Tunnel 不支持 UDP中继服务器需要单独使用 frp 或其他方案。
### 使用 Ngrok简单但有限制
```bash
# 安装
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo apt update && sudo apt install ngrok
# 配置 token
ngrok config add-authtoken <your-token>
# 启动(免费版每次地址会变)
ngrok http 3000
```
## 方案三:使用 ZeroTier/Tailscale 组建虚拟局域网
适合小团队内部使用:
### Tailscale
```bash
# 服务器和所有客户端都安装 Tailscale
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up
# 使用 Tailscale 分配的内网 IP 访问
# 例如100.x.x.x:3000
```
### ZeroTier
```bash
# 安装
curl -s https://install.zerotier.com | sudo bash
# 加入网络
sudo zerotier-cli join <network-id>
# 使用 ZeroTier 分配的内网 IP
```
## 方案四:端口映射(如果路由器支持)
如果你的宽带有公网 IP可能是动态的
1. 登录路由器管理页面
2. 找到 "端口映射" 或 "虚拟服务器" 或 "NAT"
3. 添加映射规则:
- 外部端口 3000 -> 内部 IP:3000 (TCP)
- 外部端口 3001 -> 内部 IP:3001 (UDP)
- 外部端口 7900 -> 内部 IP:7900 (UDP)
- 外部端口 7901 -> 内部 IP:7901 (UDP)
4. 使用动态 DNSDDNS获取固定域名
- 花生壳
- No-IP
- DuckDNS
## 配置客户端连接
无论使用哪种方案,都需要更新 FunMC 服务器配置:
```bash
# 编辑 .env 文件
nano /opt/funmc/.env
# 设置为穿透后的公网地址
SERVER_IP=frps服务器IP
# 或者设置域名
SERVER_DOMAIN=funmc.your-domain.com
```
然后重启服务:
```bash
docker-compose restart
```
## 客户端连接流程
1. 客户端启动时会显示服务器连接页面
2. 输入穿透后的地址(如 `frps服务器IP:3000``funmc.your-domain.com`
3. 客户端会自动获取服务器配置
4. 之后每次启动都会自动连接
## 推荐方案
| 场景 | 推荐方案 |
|------|---------|
| 生产环境/公开服务 | 云服务器 |
| 个人/小团队 | frp + 便宜云服务器 |
| 内部测试 | Tailscale/ZeroTier |
| 临时使用 | Ngrok |
---
**魔幻方开发** - 让 Minecraft 联机变得简单