痛点:我在星巴克,服务器在家里
上一篇文章我们用 Minisforum N5 Pro 搭建了完美的 P
xVE + TrueNAS 底座。但问题随之而来:当我带着 MacBook 出门,坐在星巴克想查看家里正在跑的 ST-GNN 模型训练进度,或者想远程 SSH 修复一个 Bug 时,却发现连不上家里的局域网。
没有公网 IPv4?不想用慢吞吞的向日葵/TeamViewer?
FRP 是目前最适合技术人员的解决方案:稳定、开源、配置灵活。
准备工作
- 一台有公网 IP 的 VPS:作为中转服务器(Server)。配置要求极低,阿里云/腾讯云最便宜的实例即可(带宽建议 5Mbps 以上)。
- 家里的 HomeLab:作为客户端(Client),即我们的 N5 Pro。
1. 服务端配置 (VPS)
注意:从 v0.52 版本开始,FRP 全面拥抱 TOML 格式,旧的 INI 配置已不推荐使用。
首先在 VPS 上下载对应架构的 FRP(通常是 linux_amd64),解压后我们只需要 frps 和 frps.toml。
编辑 frps.toml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# frps.toml (服务端配置)
bindPort = 7000 # FRP 服务监听端口
vhostHTTPPort = 8080 # HTTP 穿透端口 (可选)
vhostHTTPSPort = 443 # HTTPS 穿透端口 (可选)
# 身份验证 (非常重要!)
auth.method = "token"
auth.token = "Yuansi_Lab_Secret_2026_Key" # 请换成复杂的密码
# 控制台 (可选,用于查看连接状态)
webServer.addr = "0.0.0.0"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin123"
|
启动服务端(建议使用Systemd托管,这里演示临时启动):
###2.客户端配置(HomeLab / N5 Pro)在家里的Ubuntu虚拟机或直接在PVE宿主机上配置客户端。我们需要frpc和
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
|
# frpc.toml (客户端配置)
serverAddr = "1.2.3.4" # 你的 VPS 公网 IP
serverPort = 7000
auth.method = "token"
auth.token = "Yuansi_Lab_Secret_2026_Key" # 必须与服务端一致
# --- 穿透规则 ---
# 1. SSH 穿透 (最常用)
[[proxies]]
name = "ssh-home"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000 # 以后访问 VPS:6000 就是访问家里的 SSH
# 2. PVE 管理后台
[[proxies]]
name = "pve-web"
type = "tcp"
localIP = "192.168.1.100" # PVE 的局域网 IP
localPort = 8006
remotePort = 8006
# 3. 量化交易面板 (Jupyter/Grafana)
[[proxies]]
name = "quant-dashboard"
type = "tcp"
localIP = "192.168.1.102"
localPort = 8888
remotePort = 888
|
启动客户端:
bash
./frpc -c frpc.toml
3.进阶:Systemd自动启动
为了保证服务器重启后FRP自动拉起,我们需要编写systemd 服务文件。
以客户端为例,创建/etc/systemd/system/frpc.service:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/frpc -c /etc/frp/frpc.toml
[Install]
WantedBy=multi-user.target
|
然后启用并运行:
1
2
|
sudo systemctl enable frpc
sudo systemctl start frpc
|
安全警示
把内网端口暴露在公网是一把双刃剑。远思技术实验室 建议:
1.强密码:PVE和SSH的密码必须极其复杂。
2.防火墙:VPS上的安全组只开放必要的端口(如6000, 8006)。
3.Fail2Ban:在服务端部署Fail2Ban,防止暴力破解。
有了这条加密通道,无论身在何处,我的HomeLab就在指尖。