Initial commit: FunConnect project with server, relay, client and admin panel
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
39
deploy/funmc-relay.service
Normal file
39
deploy/funmc-relay.service
Normal file
@@ -0,0 +1,39 @@
|
||||
[Unit]
|
||||
Description=FunMC Relay Server - QUIC Relay for Minecraft Traffic
|
||||
Documentation=https://github.com/mofangfang/funmc
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=funmc
|
||||
Group=funmc
|
||||
WorkingDirectory=/opt/funmc
|
||||
ExecStart=/opt/funmc/relay-server
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=funmc-relay
|
||||
|
||||
# 环境变量
|
||||
Environment=RUST_LOG=funmc_relay_server=info
|
||||
Environment=RELAY_LISTEN_ADDR=0.0.0.0:7900
|
||||
EnvironmentFile=/opt/funmc/.env
|
||||
|
||||
# 安全限制
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
|
||||
# 网络优先 - 中继服务器需要低延迟
|
||||
Nice=-5
|
||||
IOSchedulingClass=realtime
|
||||
IOSchedulingPriority=0
|
||||
|
||||
# 资源限制
|
||||
LimitNOFILE=65536
|
||||
LimitNPROC=4096
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
36
deploy/funmc-server.service
Normal file
36
deploy/funmc-server.service
Normal file
@@ -0,0 +1,36 @@
|
||||
[Unit]
|
||||
Description=FunMC Main Server - Minecraft Multiplayer Assistant API
|
||||
Documentation=https://github.com/mofangfang/funmc
|
||||
After=network.target postgresql.service
|
||||
Requires=postgresql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=funmc
|
||||
Group=funmc
|
||||
WorkingDirectory=/opt/funmc
|
||||
ExecStart=/opt/funmc/server
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=funmc-server
|
||||
|
||||
# 环境变量
|
||||
Environment=RUST_LOG=funmc_server=info,tower_http=info
|
||||
Environment=LISTEN_ADDR=0.0.0.0:3000
|
||||
EnvironmentFile=/opt/funmc/.env
|
||||
|
||||
# 安全限制
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ReadWritePaths=/var/log/funmc
|
||||
PrivateTmp=yes
|
||||
|
||||
# 资源限制
|
||||
LimitNOFILE=65536
|
||||
LimitNPROC=4096
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
97
deploy/install.sh
Normal file
97
deploy/install.sh
Normal 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 ""
|
||||
Reference in New Issue
Block a user