Initial commit

This commit is contained in:
2026-06-30 15:14:37 +08:00
commit 15dab96872
311 changed files with 95639 additions and 0 deletions
+240
View File
@@ -0,0 +1,240 @@
#!/bin/bash
# MeshRay Debian/Ubuntu 安装脚本
set -e
echo "========================================"
echo " MeshRay Debian/Ubuntu 安装脚本"
echo "========================================"
# 检查是否为root用户
if [ "$EUID" -ne 0 ]; then
echo "❌ 请使用root权限运行此脚本"
echo " sudo bash install-debian.sh"
exit 1
fi
# 检查系统
if ! grep -qi "debian\|ubuntu" /etc/os-release 2>/dev/null; then
echo "⚠️ 警告:此脚本专为Debian/Ubuntu系统设计"
read -p "是否继续?(y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
echo "✅ 系统检查通过"
# 更新系统包
echo "📦 更新系统包..."
apt-get update -qq
# 安装依赖
echo "📦 安装依赖..."
apt-get install -y -qq \
curl \
wget \
tar \
systemd \
> /dev/null 2>&1
echo "✅ 依赖安装完成"
# 创建安装目录
INSTALL_DIR="/opt/meshray"
echo "📁 创建安装目录: $INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR/data"
mkdir -p "$INSTALL_DIR/logs"
mkdir -p "$INSTALL_DIR/web"
# 复制MeshRay文件
if [ ! -f "./meshray" ]; then
echo "❌ 未找到 meshray 二进制文件"
echo ""
echo "请先构建Linux版本:"
echo " GOOS=linux GOARCH=amd64 go build -o meshray ./cmd/meshray"
echo ""
echo "然后将以下文件上传到服务器:"
echo " - meshray (二进制文件)"
echo " - web/dist/ (前端文件)"
echo " - install-debian.sh (本脚本)"
echo ""
exit 1
fi
echo "📦 使用本地二进制文件..."
cp ./meshray "$INSTALL_DIR/"
# 复制前端文件
if [ -d "./web/dist" ]; then
echo "📦 复制前端文件..."
cp -r ./web/dist/* "$INSTALL_DIR/web/" 2>/dev/null || true
else
echo "⚠️ 未找到前端文件,将使用内嵌的静态文件"
fi
# 设置权限
chmod +x "$INSTALL_DIR/meshray"
# 创建配置文件
if [ ! -f "$INSTALL_DIR/config.yaml" ]; then
echo "📝 创建配置文件..."
cat > "$INSTALL_DIR/config.yaml" << 'EOF'
server:
port: 9531
mode: release
static_path: /opt/meshray/web
database:
type: sqlite
path: /opt/meshray/data/meshray.db
jwt:
secret: "$(openssl rand -hex 32)"
access_token_duration: 2h
refresh_token_duration: 7d
log:
level: info
format: json
output: /opt/meshray/logs/meshray.log
max_size: 100
max_backups: 7
max_age: 30
encryption:
network_secret_key: ""
wireguard:
preferred_mode: auto
# STUN 服务器配置
stun:
# 默认 STUN 服务器列表(国内和国外)
default_servers:
# 国内 STUN 服务器
- stun:stun.qq.com:3478
- stun:stun.miwifi.com:3478
- stun:stun.bige0.com:3478
# 国外 STUN 服务器(Google
- stun:stun.l.google.com:19302
- stun:stun1.l.google.com:19302
- stun:stun2.l.google.com:19302
- stun:stun3.l.google.com:19302
- stun:stun4.l.google.com:19302
# 国外 STUN 服务器(其他)
- stun:stun.cloudflare.com:3478
- stun:stun.nextcloud.com:443
- stun:stun.sipgate.net:3478
- stun:stun.antisip.com:3478
- stun:stun.sonetel.com:3478
- stun:stun.voipgate.com:3478
# STUN 服务器选择策略
# auto: 自动选择(优先国内,延迟低的优先)
# domestic: 仅使用国内服务器
# international: 仅使用国外服务器
# custom: 仅使用自定义服务器
selection_strategy: auto
# 是否启用 STUN 服务器自动测试
auto_test: true
# STUN 测试间隔(秒)
test_interval: 300
# STUN 超时时间(秒)
timeout: 5
# TURN 服务器配置(可选)
turn:
# 默认 TURN 服务器
# 如果配置了 TURN 服务器,将作为 STUN 穿透失败时的回退方案
default_servers: []
# 示例配置:
# - url: turn:turn.example.com:3478
# username: user
# credential: pass
# auth_type: credential
EOF
echo "✅ 配置文件已创建"
fi
# 创建systemd服务
echo "🔧 创建系统服务..."
cat > /etc/systemd/system/meshray.service << EOF
[Unit]
Description=MeshRay - 智能组网工具
After=network.target
Wants=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$INSTALL_DIR
ExecStart=$INSTALL_DIR/meshray
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
# 安全设置
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=$INSTALL_DIR
[Install]
WantedBy=multi-user.target
EOF
# 重新加载systemd
systemctl daemon-reload
echo "✅ 系统服务已创建"
# 启动服务
echo "🚀 启动MeshRay服务..."
systemctl enable meshray
systemctl start meshray
# 检查服务状态
sleep 2
if systemctl is-active --quiet meshray; then
echo "✅ MeshRay服务启动成功!"
else
echo "❌ MeshRay服务启动失败"
echo " 查看日志: journalctl -u meshray -f"
exit 1
fi
# 获取服务器IP
SERVER_IP=$(hostname -I | awk '{print $1}')
echo ""
echo "========================================"
echo " 🎉 MeshRay 安装完成!"
echo "========================================"
echo ""
echo "📍 访问地址:"
echo " http://$SERVER_IP:9531"
echo ""
echo "🔧 服务管理:"
echo " 启动: systemctl start meshray"
echo " 停止: systemctl stop meshray"
echo " 重启: systemctl restart meshray"
echo " 状态: systemctl status meshray"
echo " 日志: journalctl -u meshray -f"
echo ""
echo "📁 安装目录:"
echo " 程序: $INSTALL_DIR/meshray"
echo " 配置: $INSTALL_DIR/config.yaml"
echo " 数据: $INSTALL_DIR/data/"
echo " 日志: $INSTALL_DIR/logs/"
echo ""
echo "⚠️ 首次启动会显示管理员初始密码"
echo " 请查看日志获取密码: journalctl -u meshray | grep '初始密码'"
echo ""
echo "========================================"
+70
View File
@@ -0,0 +1,70 @@
#!/bin/bash
# MeshRay Linux 一键安装脚本
set -e
MESHRAY_VERSION="v2.0.0"
INSTALL_DIR="/opt/meshray"
SERVICE_NAME="meshray"
echo "🚀 MeshRay 安装脚本 v${MESHRAY_VERSION}"
echo "======================================"
# 检测系统架构
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*) echo "❌ 不支持的架构:$ARCH"; exit 1 ;;
esac
echo "✅ 检测到系统架构:$ARCH"
# 检测 WireGuard 内核支持
if [ -d "/sys/module/wireguard" ]; then
echo "✅ WireGuard 内核模块已加载"
WG_MODE="kernel"
else
echo "⚠️ WireGuard 内核模块未加载,将使用 wireguard-go 用户态"
WG_MODE="userspace"
fi
# 创建安装目录
sudo mkdir -p $INSTALL_DIR
sudo mkdir -p /opt/meshray/data
sudo mkdir -p /opt/meshray/logs
sudo mkdir -p /opt/meshray/backups
# 下载 MeshRay(需要从 GitHub Releases 下载)
echo "📦 正在下载 MeshRay ${MESHRAY_VERSION}..."
# TODO: 替换为真实的下载链接
# wget -q https://git.zkcoi.com/zkcoi/meshray/releases/download/${MESHRAY_VERSION}/meshray-linux-${ARCH}.tar.gz
# tar -xzf meshray-linux-${ARCH}.tar.gz
# sudo mv meshray $INSTALL_DIR/
# 复制配置文件
if [ ! -f "$INSTALL_DIR/config.yaml" ]; then
echo "📝 创建配置文件..."
sudo cp configs/config.example.yaml $INSTALL_DIR/config.yaml
fi
# 安装 systemd 服务
echo "🔧 安装 systemd 服务..."
sudo cp deploy/systemd/meshray.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE_NAME
# 设置权限
echo "🔐 设置文件权限..."
sudo chown -R root:root $INSTALL_DIR
sudo chmod +x $INSTALL_DIR/meshray
echo ""
echo "✅ MeshRay 安装完成!"
echo ""
echo "启动服务:sudo systemctl start $SERVICE_NAME"
echo "查看状态:sudo systemctl status $SERVICE_NAME"
echo "查看日志:sudo journalctl -u $SERVICE_NAME -f"
echo ""
echo "Web UI: http://localhost:9531"
echo "默认端口可在 $INSTALL_DIR/config.yaml 中修改"