用内网穿透部署 LLM 端口转发

First Post:
Last Update:
Word Count:
427
Read Time:
2 min
Page View: loading...

先贴客户端脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash

# Define FRP version and file details
FRP_VERSION="0.56.0"
FRP_TAR_FILE="frp_${FRP_VERSION}_linux_amd64.tar.gz"
FRP_DIR="frp_${FRP_VERSION}_linux_amd64"
DOWNLOAD_URL="https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FRP_TAR_FILE}"

# Define server configuration
SERVER_ADDR="your.server.ip"
SERVER_PORT=7000
AUTH_TOKEN="your_secure_token"

# Define proxy configuration for the LLM service
PROXY_NAME="llm-service"
LOCAL_IP="127.0.0.1"
LOCAL_PORT=8888
REMOTE_PORT=10001

# Check if the FRP directory already exists to avoid redundant downloads
if [ ! -d "$FRP_DIR" ]; then
echo "Downloading FRP version ${FRP_VERSION}..."
wget -q --show-progress "$DOWNLOAD_URL"

echo "Extracting the archive..."
tar -zxvf "$FRP_TAR_FILE"
else
echo "FRP directory already exists. Skipping download and extraction."
fi

# Navigate to the extracted directory
cd "$FRP_DIR" || exit

# Generate the frpc.toml configuration file dynamically
echo "Generating frpc.toml configuration file..."
cat <<EOF > frpc.toml
serverAddr = "${SERVER_ADDR}"
serverPort = ${SERVER_PORT}
auth.token = "${AUTH_TOKEN}"

[[proxies]]
name = "${PROXY_NAME}"
type = "tcp"
localIP = "${LOCAL_IP}"
localPort = ${LOCAL_PORT}
remotePort = ${REMOTE_PORT}
EOF

echo "Configuration file generated successfully."

# Kill any existing frpc processes to prevent port conflicts
echo "Stopping any existing frpc instances..."
pkill -f "./frpc -c ./frpc.toml" || true

# Run the FRP client in the background using nohup
echo "Starting the FRP client in the background..."
nohup ./frpc -c ./frpc.toml > frpc.log 2>&1 &

# Output final status to the user
echo "------------------------------------------------------"
echo "Deployment Complete!"
echo "Your local LLM service (Port: ${LOCAL_PORT}) is now forwarded to: ${SERVER_ADDR}:${REMOTE_PORT}"
echo "To view the live logs, run: tail -f $(pwd)/frpc.log"
echo "------------------------------------------------------"

服务端

服务端只需要一个 frps.toml,把监听端口和认证 token 对上即可。

1
2
3
4
bindPort = 7000

auth.method = "token"
auth.token = "your_secure_token"

启动方式可以保持最朴素:

1
./frps -c ./frps.toml

如果服务端要长期跑,直接配个 systemd 也行:

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=FRP Server
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/frp
ExecStart=/opt/frp/frps -c /opt/frp/frps.toml
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
If you find this helpful, please give my project a ⭐on GitHub! =w=/