first commit

This commit is contained in:
root
2026-02-17 17:28:37 +08:00
commit 192078dc3b
52 changed files with 18158 additions and 0 deletions

37
frp/frp/frpc.toml Normal file
View File

@@ -0,0 +1,37 @@
#===========================================
#===================基础设置===================
#===========================================
serverAddr = "47.108.90.0"
serverPort = 7000
auth.method = "token"
auth.token = "smy"
webServer.addr = "0.0.0.0"
webServer.port = 7400
webServer.user = "shumengya"
webServer.password = "tyh@19900420"
webServer.pprofEnable = false
# 日志配置
log.to = "console"
log.level = "info"
#===========================================
#===================Http服务===================
#===========================================
#大萌芽frp客户端-frpc
[[proxies]]
name = "frpc"
type = "http"
localIP = "127.0.0.1"
localPort = 7400
customDomains = ["frpc.shumengya.top"]

26
frp/frp/frps.toml Normal file
View File

@@ -0,0 +1,26 @@
# frp服务端配置 - 作为nginx后端服务
# 与nginx配合使用提供HTTPS支持
bindAddr = "0.0.0.0"
bindPort = 7000
auth.method = "token"
auth.token = "smy"
# HTTP配置 - 作为后端服务nginx代理
vhostHTTPPort = 8080 # nginx代理到此端口
# 日志配置
log.to = "console"
log.level = "info"
# 管理界面
webServer.addr = "0.0.0.0"
webServer.port = 7500
webServer.user = "shumengya"
webServer.password = "tyh@19900420"

BIN
frp/frp/linux_amd64/frpc Normal file

Binary file not shown.

BIN
frp/frp/linux_amd64/frps Normal file

Binary file not shown.

BIN
frp/frp/linux_arm64/frpc Normal file

Binary file not shown.

BIN
frp/frp/linux_arm64/frps Normal file

Binary file not shown.

0
frp/frp/smy-frpc.serivce Normal file
View File

0
frp/frp/smy-frps.serivce Normal file
View File

192
frp/install_frp.sh Normal file
View File

@@ -0,0 +1,192 @@
#!/usr/bin/env bash
set -euo pipefail
# FRP 一键安装脚本
# 用法示例curl -fsSL "https://pan.shumengya.top/d/scripts/frp/install_frp.sh" | sudo bash
# 包含 frps (服务端) 和 frpc (客户端) 的安装
# 目录结构假设:
# BASE_URL/linux_amd64/frps
# BASE_URL/linux_amd64/frpc
# BASE_URL/frps.toml
# BASE_URL/frpc.toml
# BASE_URL/smy-frps.service (模板)
# BASE_URL/smy-frpc.service (模板)
BASE_URL="https://pan.shumengya.top/d/scripts/frp/frp"
INSTALL_DIR="/shumengya/bin/frp"
SERVICE_PREFIX="smy-frp"
log() { printf '[frp-安装] %s\n' "$*" >&2; }
fail() { log "错误: $*" >&2; exit 1; }
# 进度条函数
show_progress() {
local pid=$1
local text=$2
local delay=0.1
local spin='-\|/'
printf "[frp-安装] %s... " "$text" >&2
while ps -p "$pid" > /dev/null 2>&1; do
local temp=${spin#?}
printf "\b%c" "$spin" >&2
local spin=$temp${spin%"$temp"}
sleep $delay
done
printf "\b完成\n" >&2
}
require_root() {
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
fail "请使用 root 权限运行 (sudo bash install_frp.sh)"
fi
}
detect_arch() {
local machine
machine=$(uname -m)
case "$machine" in
x86_64|amd64) echo "linux_amd64" ;;
aarch64|arm64) echo "linux_arm64" ;;
*) fail "不支持的架构: $machine" ;;
esac
}
select_mode() {
echo "请选择安装模式:" >&2
echo "1) 安装客户端 (frpc)" >&2
echo "2) 安装服务端 (frps)" >&2
echo "3) 同时安装" >&2
read -p "请输入选项 [1-3]: " choice < /dev/tty
case "$choice" in
1) echo "client" ;;
2) echo "server" ;;
3) echo "both" ;;
*) fail "无效选项" ;;
esac
}
download_and_install() {
local mode=$1
local arch=$2
local tmp_dir
tmp_dir=$(mktemp -d)
trap 'if [ -n "${tmp_dir:-}" ] && [ -d "$tmp_dir" ]; then rm -rf "$tmp_dir"; fi' EXIT
mkdir -p "$INSTALL_DIR"
if [ "$mode" = "client" ] || [ "$mode" = "both" ]; then
install_component "frpc" "$arch" "$tmp_dir"
fi
if [ "$mode" = "server" ] || [ "$mode" = "both" ]; then
install_component "frps" "$arch" "$tmp_dir"
fi
}
install_component() {
local name=$1 # frpc or frps
local arch=$2
local tmp_dir=$3
local bin_url="${BASE_URL}/${arch}/${name}"
local conf_url="${BASE_URL}/${name}.toml"
local service_name="${SERVICE_PREFIX}${name:3}" # smy-frpc or smy-frps
log "正在处理 $name ..."
# 停止旧服务
systemctl stop "${service_name}.service" 2>/dev/null || true
# 强制清理可能残留的进程 (避免 Text file busy)
pids=$(pgrep -x "$name" || true)
if [ -n "$pids" ]; then
log "清理 $name 残留进程..."
kill -9 $pids 2>/dev/null || true
fi
# 下载二进制
curl -fsSL "$bin_url" -o "$tmp_dir/$name" &
show_progress $! "下载 $name 二进制文件"
[ -f "$tmp_dir/$name" ] || fail "下载 $name 失败"
# 下载配置
curl -fsSL "$conf_url" -o "$tmp_dir/${name}.toml" &
show_progress $! "下载 $name 配置文件"
[ -f "$tmp_dir/${name}.toml" ] || fail "下载配置文件失败"
# 安装文件
cp "$tmp_dir/$name" "$INSTALL_DIR/$name"
chmod +x "$INSTALL_DIR/$name"
if [ ! -f "$INSTALL_DIR/${name}.toml" ]; then
cp "$tmp_dir/${name}.toml" "$INSTALL_DIR/${name}.toml"
else
log "保留现有配置文件: $INSTALL_DIR/${name}.toml"
fi
# 配置服务
write_service "$name"
# 启动服务
systemctl daemon-reload
systemctl enable "${service_name}.service"
systemctl restart "${service_name}.service"
sleep 2
if systemctl is-active --quiet "${service_name}.service"; then
log "$name 服务启动成功"
else
log "警告: $name 服务启动失败,查看日志:"
journalctl -u "${service_name}.service" --no-pager -n 10
fi
}
write_service() {
local name=$1
local service_name="${SERVICE_PREFIX}${name:3}"
local service_file="/etc/systemd/system/${service_name}.service"
cat > "$service_file" <<EOF
[Unit]
Description=${service_name}
After=network.target
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$INSTALL_DIR/$name -c $INSTALL_DIR/${name}.toml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
}
main() {
require_root
local arch
arch=$(detect_arch)
log "检测到架构: $arch"
local mode
if [ $# -gt 0 ]; then
case "$1" in
client|frpc) mode="client" ;;
server|frps) mode="server" ;;
both) mode="both" ;;
*) fail "无效参数: $1 (可用: client, server, both)" ;;
esac
else
mode=$(select_mode)
fi
download_and_install "$mode" "$arch"
log "=========================================="
log "安装任务完成!"
log "安装目录: $INSTALL_DIR"
log "=========================================="
}
main "$@"

66
frp/start_frp.sh Normal file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail
# 恢复并启动 frp 服务
# 该脚本自动检测已安装的 frp 服务 (客户端/服务端) 并恢复其运行和开机自启
# 用法curl -fsSL "https://pan.shumengya.top/d/scripts/frp/start_frp.sh" | sudo bash
SERVICE_FRPC="smy-frpc"
SERVICE_FRPS="smy-frps"
log() { printf '[frp-启动] %s\n' "$*" >&2; }
fail() { log "错误: $*" >&2; exit 1; }
# 检查 root 权限
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
fail "请使用 root 权限运行"
fi
start_service() {
local svc=$1
local service_file="/etc/systemd/system/${svc}.service"
if [ -f "$service_file" ]; then
log "检测到已安装服务: $svc"
# 重置失败状态
systemctl reset-failed "$svc" 2>/dev/null || true
log "正在启用并启动 $svc..."
systemctl enable --now "$svc"
sleep 1
if systemctl is-active --quiet "$svc"; then
log "$svc 启动成功 (状态: $(systemctl is-active "$svc"))"
else
log "$svc 启动失败"
systemctl status "$svc" --no-pager -n 5 || true
fi
else
# 仅在调试时显示,避免干扰普通用户
# log "未检测到 $svc跳过"
:
fi
}
log "正在扫描并恢复 frp 服务..."
found_any=false
if [ -f "/etc/systemd/system/${SERVICE_FRPC}.service" ]; then
start_service "$SERVICE_FRPC"
found_any=true
fi
if [ -f "/etc/systemd/system/${SERVICE_FRPS}.service" ]; then
start_service "$SERVICE_FRPS"
found_any=true
fi
if [ "$found_any" = false ]; then
log "未检测到任何已安装的 frp 服务 (smy-frpc 或 smy-frps)。"
log "请先运行安装脚本进行安装。"
exit 1
fi
log "操作完成。"

66
frp/stopkill_frp.sh Normal file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail
# 强制停止 frp 服务并清理进程
# 用法curl -fsSL "https://pan.shumengya.top/d/scripts/frp/stopkill_frp.sh" | sudo bash
SERVICE_FRPC="smy-frpc"
SERVICE_FRPS="smy-frps"
log() { printf '[frp-停止] %s\n' "$*" >&2; }
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
log "请使用 root 权限运行"
exit 1
fi
stop_service() {
local svc=$1
if systemctl is-active --quiet "$svc"; then
log "正在停止服务 $svc..."
systemctl disable --now "$svc" 2>/dev/null || true
systemctl stop "$svc" 2>/dev/null || true
fi
# 即使服务不活跃,也要尝试 disable防止开机自启
systemctl disable "$svc" 2>/dev/null || true
# 重置失败状态
systemctl reset-failed "$svc" 2>/dev/null || true
}
kill_process() {
local name=$1
local pids
local current_pid=$$
# 尝试精确匹配
pids=$(pgrep -x "$name" || true)
# 如果没找到,尝试模糊匹配但排除当前脚本
if [ -z "$pids" ]; then
pids=$(pgrep -f "$name" | grep -v "$current_pid" || true)
fi
if [ -n "$pids" ]; then
log "发现 $name 残留进程 PID: $pids,正在强制终止..."
kill -9 $pids 2>/dev/null || true
fi
}
log "开始清理 frp 相关服务..."
# Stop Services
stop_service "$SERVICE_FRPC"
stop_service "$SERVICE_FRPS"
# Kill Processes
kill_process "frpc"
kill_process "frps"
log "正在验证服务状态..."
if pgrep -x "frpc" >/dev/null || pgrep -x "frps" >/dev/null; then
log "警告: 仍有 frp 进程在运行!"
ps -fp $(pgrep -x "frpc" "frps" 2>/dev/null) || true
else
log "frp 相关服务及进程已完全停止 (服务已禁用)。"
fi

145
frp/uninstall_frp.sh Normal file
View File

@@ -0,0 +1,145 @@
#!/usr/bin/env bash
set -euo pipefail
# FRP 一键卸载脚本
# 用法curl -fsSL "https://pan.shumengya.top/d/scripts/frp/uninstall_frp.sh" | sudo bash
INSTALL_DIR="/shumengya/bin/frp"
SERVICE_PREFIX="smy-frp"
log() { printf '[frp-卸载] %s\n' "$*" >&2; }
fail() { log "错误: $*" >&2; exit 1; }
show_progress() {
local pid=$1
local text=$2
local delay=0.1
local spin='-\|/'
printf "[frp-卸载] %s... " "$text" >&2
while ps -p "$pid" > /dev/null 2>&1; do
local temp=${spin#?}
printf "\b%c" "$spin" >&2
local spin=$temp${spin%"$temp"}
sleep $delay
done
printf "\b完成\n" >&2
}
require_root() {
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
fail "请使用 root 权限运行 (sudo bash uninstall_frp.sh)"
fi
}
select_mode() {
echo "请选择卸载模式:" >&2
echo "1) 卸载客户端 (frpc)" >&2
echo "2) 卸载服务端 (frps)" >&2
echo "3) 全部卸载" >&2
read -p "请输入选项 [1-3]: " choice < /dev/tty
case "$choice" in
1) echo "client" ;;
2) echo "server" ;;
3) echo "both" ;;
*) fail "无效选项" ;;
esac
}
stop_and_disable_service() {
local name=$1
local service_name="${SERVICE_PREFIX}${name:3}"
if systemctl is-active --quiet "${service_name}.service"; then
systemctl stop "${service_name}.service"
fi
if systemctl is-enabled --quiet "${service_name}.service" 2>/dev/null; then
systemctl disable "${service_name}.service"
fi
}
remove_service_file() {
local name=$1
local service_name="${SERVICE_PREFIX}${name:3}"
local service_file="/etc/systemd/system/${service_name}.service"
if [ -f "$service_file" ]; then
rm -f "$service_file"
systemctl daemon-reload
fi
}
cleanup_process() {
local name=$1
# 查找并杀掉所有匹配的进程
local pids
pids=$(pgrep -f "$INSTALL_DIR/$name" || true)
if [ -n "$pids" ]; then
kill -9 $pids 2>/dev/null || true
fi
}
uninstall_component() {
local name=$1
log "正在卸载 $name ..."
(stop_and_disable_service "$name") &
show_progress $! "停止服务"
cleanup_process "$name"
(remove_service_file "$name") &
show_progress $! "删除服务文件"
if [ -f "$INSTALL_DIR/$name" ]; then
rm -f "$INSTALL_DIR/$name"
fi
# 注意:不自动删除配置文件,以免误删用户配置
# if [ -f "$INSTALL_DIR/${name}.toml" ]; then
# rm -f "$INSTALL_DIR/${name}.toml"
# fi
}
main() {
require_root
local mode
if [ $# -gt 0 ]; then
case "$1" in
client|frpc) mode="client" ;;
server|frps) mode="server" ;;
both) mode="both" ;;
*) fail "无效参数: $1 (可用: client, server, both)" ;;
esac
else
mode=$(select_mode)
fi
if [ "$mode" = "client" ] || [ "$mode" = "both" ]; then
uninstall_component "frpc"
fi
if [ "$mode" = "server" ] || [ "$mode" = "both" ]; then
uninstall_component "frps"
fi
# 如果目录为空,则删除目录
if [ -d "$INSTALL_DIR" ]; then
if [ -z "$(ls -A "$INSTALL_DIR")" ]; then
rm -rf "$INSTALL_DIR"
log "已删除空安装目录"
else
log "保留安装目录 (包含配置文件): $INSTALL_DIR"
fi
fi
log "=========================================="
log "卸载任务完成"
log "=========================================="
}
main "$@"