#前言

ngrok 的证书有点难弄,导致经常 ssh 宕机,换frp

好处:

  • 配置简单
  • 不需要证书

#服务端配置

Github处下载,传上服务器。

修改配置,服务端目前看起来配置只有一个端口号,记得开防火墙(frps.toml):
auth.token用于安全认证。

1
2
bindPort = 4443
auth.token = "abc"

#开机自启&保活

参考使用 systemd

1
sudo nvim /etc/systemd/system/frps.service

内容 👇:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = ~/frp/frps -c ~/code/config/frp/frps.toml
Restart = always

[Install]
WantedBy = multi-user.target
1
2
3
4
5
6
7
8
9
10
11
# 启动frp
sudo systemctl start frps
# 停止frp
sudo systemctl stop frps
# 重启frp
sudo systemctl restart frps
# 查看frp状态
sudo systemctl status frps

# 设置 frps 开机自启动
sudo systemctl enable frps

#客户端配置

同样修改配置(frpc.toml),保证auth.token一致:

1
2
3
4
5
6
7
8
9
10
serverAddr = "aaa.com"
serverPort = 4443
auth.token = "abc"

[[proxies]]
name = "test-tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 7602

#开机自启&保活

细节可自行 Google 或launchd 体验

1
cd /Library/LaunchDaemons && sudo nvim frpc.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>frpc.plist</string>
<key>ProgramArguments</key>
<array>
<string>绝对路径/frpc</string>
<string>-c</string>
<string>绝对路径/frpc.toml</string>
</array>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
1
2
3
4
# 启动并开机自启
sudo launchctl load -w frpc.plist
# 关闭
sudo launchctl unload frpc.plist

#参考链接