Files
Linux-Shell/System-Init/install_frps.sh
2026-03-19 14:46:59 +08:00

95 lines
2.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# 设置版本号
FRP_VERSION="0.54.0"
# 检查是否为root用户
if [ "$EUID" -ne 0 ]; then
echo "请使用 root 权限运行此脚本 (Please run as root)"
exit 1
fi
# 强制使用 amd64 架构
FRP_ARCH="amd64"
echo "=========================================="
echo "准备安装 FRPS ${FRP_VERSION} (${FRP_ARCH})"
echo "=========================================="
# 交互式输入 token
read -p "请输入 FRPS 认证 Token (留空则生成随机 Token): " FRP_TOKEN
if [ -z "$FRP_TOKEN" ]; then
FRP_TOKEN=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 16)
echo "已生成随机 Token: $FRP_TOKEN"
fi
FRP_FILE="frp_${FRP_VERSION}_linux_${FRP_ARCH}.tar.gz"
FRP_URL="https://s3.cloudyun.top/downloads/frp_0.54.0_linux_amd64.tar.gz"
echo "正在下载 frp 安装包..."
if command -v wget >/dev/null 2>&1; then
wget -c --show-progress "$FRP_URL"
elif command -v curl >/dev/null 2>&1; then
curl -O -L "$FRP_URL"
else
echo "未找到 wget 或 curl请先安装其中一个。"
exit 1
fi
echo "正在解压安装包..."
tar -zxf "${FRP_FILE}"
cd "frp_${FRP_VERSION}_linux_${FRP_ARCH}"
echo "正在安装 frps 到 /usr/local/bin/..."
cp frps /usr/local/bin/
chmod +x /usr/local/bin/frps
echo "正在配置 frps..."
mkdir -p /etc/frp
cat > /etc/frp/frps.toml <<EOF
bindPort = 7000
[auth]
method = "token"
token = "${FRP_TOKEN}"
EOF
echo "正在配置 systemd 服务..."
cat > /etc/systemd/system/frps.service <<EOF
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/frps -c /etc/frp/frps.toml
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
echo "启动 frps 服务并设置开机自启..."
systemctl daemon-reload
systemctl enable frps
systemctl start frps
echo "清理临时文件..."
cd ..
rm -rf "frp_${FRP_VERSION}_linux_${FRP_ARCH}"
rm -f "${FRP_FILE}"
echo "=========================================="
echo "FRPS 安装成功并已启动!"
echo "版本: ${FRP_VERSION}"
echo "绑定端口: 7000"
echo "认证 Token: ${FRP_TOKEN}"
echo "查看服务状态: systemctl status frps"
echo "查看服务日志: journalctl -u frps -f"
echo "=========================================="