添加 frpc.sh
This commit is contained in:
parent
77b84d1818
commit
714e000cb9
93
frpc.sh
Normal file
93
frpc.sh
Normal file
@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 定义变量
|
||||
FRPC_VERSION="0.52.3"
|
||||
INSTALL_DIR="/usr/local/bin"
|
||||
SERVICE_NAME="frpc"
|
||||
CONFIG_DIR="/etc/frp"
|
||||
CONFIG_FILE="$CONFIG_DIR/frpc.ini"
|
||||
|
||||
# 检测系统架构
|
||||
ARCH=$(uname -m)
|
||||
case $ARCH in
|
||||
x86_64)
|
||||
ARCH="amd64"
|
||||
;;
|
||||
aarch64)
|
||||
ARCH="arm64"
|
||||
;;
|
||||
armv7l)
|
||||
ARCH="arm"
|
||||
;;
|
||||
*)
|
||||
echo "不支持的架构: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# 下载 frpc
|
||||
echo "正在下载 frpc v$FRPC_VERSION ..."
|
||||
DOWNLOAD_URL="https://ghub.z1.mk/https://github.com/fatedier/frp/releases/download/v${FRPC_VERSION}/frp_${FRPC_VERSION}_linux_${ARCH}.tar.gz"
|
||||
wget -q --show-progress -O /tmp/frp.tar.gz $DOWNLOAD_URL
|
||||
|
||||
# 解压并安装
|
||||
echo "正在安装 frpc ..."
|
||||
tar -xzf /tmp/frp.tar.gz -C /tmp
|
||||
sudo mv /tmp/frp_${FRPC_VERSION}_linux_${ARCH}/frpc $INSTALL_DIR/
|
||||
sudo chmod +x $INSTALL_DIR/frpc
|
||||
|
||||
# 创建配置文件目录
|
||||
echo "正在创建配置文件目录 ..."
|
||||
sudo mkdir -p $CONFIG_DIR
|
||||
|
||||
# 用户输入 frps 服务器地址和端口号
|
||||
echo "请输入 frps 服务器地址(例如: frps.example.com): "
|
||||
read FRPS_SERVER
|
||||
echo "请输入 frps 服务器端口号(例如: 7000): "
|
||||
read FRPS_PORT
|
||||
|
||||
# 写入配置文件
|
||||
echo "正在写入配置文件 ..."
|
||||
sudo bash -c "cat > $CONFIG_FILE" <<EOF
|
||||
[common]
|
||||
server_addr = $FRPS_SERVER
|
||||
server_port = $FRPS_PORT
|
||||
|
||||
# 添加您的隧道规则,例如:
|
||||
# [web]
|
||||
# type = http
|
||||
# local_port = 80
|
||||
# custom_domains = example.com
|
||||
EOF
|
||||
|
||||
# 创建 Systemd 服务
|
||||
echo "正在创建 Systemd 服务 ..."
|
||||
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
|
||||
sudo bash -c "cat > $SERVICE_FILE" <<EOF
|
||||
[Unit]
|
||||
Description=Frp Client Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=$INSTALL_DIR/frpc -c $CONFIG_FILE
|
||||
Restart=on-failure
|
||||
User=nobody
|
||||
RestartSec=5s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# 重载 Systemd 并启动服务
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable $SERVICE_NAME
|
||||
sudo systemctl start $SERVICE_NAME
|
||||
|
||||
# 检查服务状态
|
||||
echo "frpc 安装完成!"
|
||||
echo "服务状态:"
|
||||
sudo systemctl status $SERVICE_NAME
|
||||
|
||||
# 清理临时文件
|
||||
rm -rf /tmp/frp_${FRPC_VERSION}_linux_${ARCH} /tmp/frp.tar.gz
|
Loading…
x
Reference in New Issue
Block a user