前言
Frp可以通过有公网IP的的服务器将内网的主机暴露给互联网,从而实现通过外网能直接访问到内网主机;frp有服务端和客户端,服务端需要装在有公网ip的服务器上,客户端装在内网主机上。
因为博主有一个低配置的云服务器,需要将家里的高性能服务器一些端口映射到云服务,从而进行更高效的访问。
GitHub仓库地址:github.com/fatedier/frp
准备工作
Linux下载frp_xxxx_linux_amd64的

frpc为客户端
frps为服务端
客户端不需要公网ip,服务端需要公网ip,并且将服务端口映射出来。
配置文件
服务端配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| bindPort = 65001
transport.tls.force = true
auth.token = "token"
webServer.addr = "0.0.0.0" webServer.port = 65002 webServer.user = "admin" webServer.password = "admin"
bindAddr = "0.0.0.0" bindPort = 65001
auth.method = "token" auth.token = "Aa135790Toekn"
webServer.addr = "0.0.0.0" webServer.port = 65002 webServer.user = "jianglin" webServer.password = "Frp65022"
|
客户端配置
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
| transport.tls.enable = true serverAddr = "47.101.69.145" serverPort = 65001
auth.token = "Aa135790Toekn"
webServer.addr = "0.0.0.0" webServer.port = 65002
webServer.pprofEnable = false
[[proxies]] name = "bt" type = "tcp" localIP = "127.0.0.1" localPort = 65000 remotePort = 65100
[[proxies]] name = "web80" type = "tcp" localIP = "127.0.0.1" localPort = 80 remotePort = 80
[[proxies]] name = "web443" type = "tcp" localIP = "127.0.0.1" localPort = 443 remotePort = 443
|
后台运行
宝塔面板
如果使用宝塔面板,可以使用进程守护管理器这个插件,配置一个守护进程
按照下图进行配置

systemctl
使用systemctl 管理Frp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
vim /usr/lib/systemd/system/frps.service
[Unit] Description=frps After=network.target syslog.target Wants=network.target [Service] TimeoutStartSec=30 ExecStart=/opt/frps/frps -c /opt/frps/frps.ini ExecStop=/bin/kill $MAINPID [Install] WantedBy=multi-user.target
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
vim /usr/lib/systemd/system/frpc.service
[Unit] Description=frpc After=network.target syslog.target Wants=network.target [Service] TimeoutStartSec=30 ExecStart=/opt/frpc/frpc -c /opt/frpc/frpc.ini ExecStop=/bin/kill $MAINPID [Install] WantedBy=multi-user.target
|
管理
1 2 3 4 5 6 7 8 9
| systemctl enable frps systemctl start frps systemctl status frps
systemctl enable frps.service systemctl start frps.service systemctl status frps.service
|
至此,配置完成