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

97
deploy/install.sh Normal file
View File

@@ -0,0 +1,97 @@
#!/bin/bash
# FunMC 服务器安装脚本
# 用于 Linux 服务器部署
set -e
echo "================================"
echo " FunMC 服务器安装脚本"
echo " 魔幻方开发"
echo "================================"
# 检查 root 权限
if [ "$EUID" -ne 0 ]; then
echo "错误: 请使用 root 权限运行此脚本"
exit 1
fi
# 变量
FUNMC_USER="funmc"
FUNMC_DIR="/opt/funmc"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
echo ""
echo "[1/6] 创建系统用户..."
if ! id "$FUNMC_USER" &>/dev/null; then
useradd --system --shell /sbin/nologin --home-dir "$FUNMC_DIR" "$FUNMC_USER"
echo "已创建用户: $FUNMC_USER"
else
echo "用户已存在: $FUNMC_USER"
fi
echo ""
echo "[2/6] 创建安装目录..."
mkdir -p "$FUNMC_DIR"
mkdir -p /var/log/funmc
echo ""
echo "[3/6] 编译服务端..."
cd "$ROOT_DIR"
cargo build --release -p funmc-server
cargo build --release -p funmc-relay-server
echo ""
echo "[4/6] 安装二进制文件..."
cp target/release/server "$FUNMC_DIR/server"
cp target/release/relay-server "$FUNMC_DIR/relay-server"
# 复制迁移文件
cp -r server/migrations "$FUNMC_DIR/"
# 创建环境配置
if [ ! -f "$FUNMC_DIR/.env" ]; then
cp .env.example "$FUNMC_DIR/.env"
echo "请编辑配置文件: $FUNMC_DIR/.env"
fi
# 设置权限
chown -R "$FUNMC_USER:$FUNMC_USER" "$FUNMC_DIR"
chown -R "$FUNMC_USER:$FUNMC_USER" /var/log/funmc
chmod 600 "$FUNMC_DIR/.env"
echo ""
echo "[5/6] 安装 systemd 服务..."
cp deploy/funmc-server.service /etc/systemd/system/
cp deploy/funmc-relay.service /etc/systemd/system/
systemctl daemon-reload
echo ""
echo "[6/6] 配置防火墙..."
if command -v ufw &>/dev/null; then
ufw allow 3000/tcp comment "FunMC API"
ufw allow 3001/udp comment "FunMC Built-in Relay"
ufw allow 7900/udp comment "FunMC Relay"
ufw allow 17900/udp comment "FunMC Relay Ping"
elif command -v firewall-cmd &>/dev/null; then
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --permanent --add-port=3001/udp
firewall-cmd --permanent --add-port=7900/udp
firewall-cmd --permanent --add-port=17900/udp
firewall-cmd --reload
fi
echo ""
echo "================================"
echo " 安装完成!"
echo "================================"
echo ""
echo "后续步骤:"
echo "1. 编辑配置: nano $FUNMC_DIR/.env"
echo "2. 初始化数据库并启动服务:"
echo " systemctl enable --now funmc-server"
echo " systemctl enable --now funmc-relay"
echo "3. 查看日志:"
echo " journalctl -u funmc-server -f"
echo " journalctl -u funmc-relay -f"
echo ""