110 lines
2.4 KiB
Bash
110 lines
2.4 KiB
Bash
#!/bin/bash
|
||
# 优化FRP配置以提高稳定性
|
||
|
||
set -e
|
||
|
||
echo "========================================"
|
||
echo "优化FRP配置"
|
||
echo "========================================"
|
||
echo ""
|
||
|
||
# 备份当前配置
|
||
cp /etc/frp/frpc.toml /etc/frp/frpc.toml.bak.$(date +%Y%m%d_%H%M%S)
|
||
echo "✅ 已备份当前配置"
|
||
|
||
# 优化FRP配置
|
||
cat > /etc/frp/frpc.toml << 'EOF'
|
||
serverAddr = "180.97.221.140"
|
||
serverPort = 7000
|
||
|
||
auth.method = "token"
|
||
auth.token = "LiuYunKu_NAS_2024_SecureToken"
|
||
|
||
log.to = "/root/frp/frpc.log"
|
||
log.level = "info"
|
||
log.maxDays = 7
|
||
|
||
# 优化传输配置
|
||
transport.heartbeatInterval = 20 # 减少到20秒,更快检测断线
|
||
transport.heartbeatTimeout = 60 # 减少到60秒
|
||
transport.tcpMux = true
|
||
transport.poolCount = 30 # 增加到30,支持更高并发
|
||
transport.tcpKeepAlive = true
|
||
transport.tcpKeepAliveInterval = 30
|
||
|
||
[[proxies]]
|
||
name = "nas_smb"
|
||
type = "tcp"
|
||
localIP = "192.168.58.20"
|
||
localPort = 445
|
||
remotePort = 445
|
||
transport.useCompression = true
|
||
|
||
[[proxies]]
|
||
name = "nas_netbios"
|
||
type = "tcp"
|
||
localIP = "192.168.58.20"
|
||
localPort = 139
|
||
remotePort = 139
|
||
transport.useCompression = true
|
||
|
||
[[proxies]]
|
||
name = "youyidian-3d"
|
||
type = "tcp"
|
||
localIP = "127.0.0.1"
|
||
localPort = 4320
|
||
remotePort = 2320
|
||
transport.useCompression = true
|
||
# 启用健康检查(如果FRP版本支持)
|
||
healthCheck.type = "tcp"
|
||
healthCheck.intervalSeconds = 10
|
||
healthCheck.maxFailed = 3
|
||
healthCheck.timeoutSeconds = 3
|
||
EOF
|
||
|
||
echo "✅ FRP配置已优化"
|
||
echo ""
|
||
|
||
# 优化Systemd配置
|
||
cp /etc/systemd/system/frpc.service /etc/systemd/system/frpc.service.bak.$(date +%Y%m%d_%H%M%S)
|
||
|
||
cat > /etc/systemd/system/frpc.service << 'EOF'
|
||
[Unit]
|
||
Description=Frp Client Service
|
||
After=network.target
|
||
|
||
[Service]
|
||
Type=simple
|
||
Restart=always
|
||
RestartSec=5s # 减少到5秒,更快恢复
|
||
TimeoutStartSec=30s
|
||
# 资源限制
|
||
LimitNOFILE=8192 # 增加到8192
|
||
MemoryMax=1G # 增加到1GB
|
||
CPUQuota=100% # 移除CPU限制,让FRP使用更多资源
|
||
# 环境变量
|
||
Environment="GOMAXPROCS=2" # 限制Go协程数
|
||
|
||
ExecStart=/root/gongxiangp2/frp_0.52.3_linux_amd64/frpc -c /etc/frp/frpc.toml
|
||
StandardOutput=append:/root/frp/frpc.log
|
||
StandardError=append:/root/frp/frpc.log
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
EOF
|
||
|
||
echo "✅ Systemd配置已优化"
|
||
echo ""
|
||
|
||
# 重新加载systemd
|
||
systemctl daemon-reload
|
||
|
||
# 重启FRP服务
|
||
systemctl restart frpc
|
||
|
||
echo "✅ FRP服务已重启"
|
||
echo ""
|
||
echo "查看状态:"
|
||
echo " systemctl status frpc"
|
||
echo ""
|