服务端

下载安装包

https://github.com/fatedier/frp/releases 中下载对应架构的安装包,解压放置到 /usr/local 目录下。

使用 Docker

docker run --restart=always --network host -d -v /opt/frp:/etc/frp --name frps snowdreamtech/frps

编写配置文件

根据业务需求修改 frps.ini

vim /usr/local/frp/frps.ini
[common]
# 绑定端口
bind_port = 7000
# bind_udp_port = 7001

# 管理面板
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = passwd

# 使用宝塔的自签证书
dashboard_tls_mode = true
dashboard_tls_cert_file = /www/server/panel/ssl/certificate.pem
dashboard_tls_key_file = /www/server/panel/ssl/privateKey.pem

# 日志
# log_file = ./frps.log
# trace, debug, info, warn, error
log_level = info
log_max_days = 7

# auth token
token = yourtoken

根据配置文件开放对应端口,测试运行

cd /usr/local/frp
./frps -c ./frps.ini

使用 systemd 持久化运行

安装 systemd

# yum
yum install systemd
# apt
apt install systemd

使用文本编辑器,如 vim 创建并编辑 frps.service 文件

vim /etc/systemd/system/frps.service

写入内容

[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动 frps 的命令,需修改为您的 frps 的安装路径
ExecStart = /usr/local/frp/frps -c /usr/local/frp/frps.ini

[Install]
WantedBy = multi-user.target

使用 systemd 命令,管理 frps。

# 启动frp
systemctl start frps
# 停止frp
systemctl stop frps
# 重启frp
systemctl restart frps
# 查看frp状态
systemctl status frps
# 查看frp日志
journalctl -u frps
tail -f /usr/local/frp/frps.ini

配置 frps 开机自启。

systemctl enable frps

客户端

https://github.com/fatedier/frp/releases 中下载对应架构的安装包,或使用 Docker 部署。

[common]
server_addr = 服务器地址
server_port = 7000
token = yourtoken
tls_enable =  true
# http_proxy = socks5://192.168.31.166:7890

[dsm]
type = tcp
use_encryption = true
local_ip = 127.0.0.1
local_port = 5000
remote_port = 7006

[jellyfin]
type = tcp
use_encryption = true
local_ip = 127.0.0.1
local_port = 8096
remote_port = 7007

[homeassistance]
type = tcp
use_encryption = true
local_ip = 127.0.0.1
local_port = 8123
remote_port = 7008

[openvpn]
type = tcp
use_encryption = true
local_ip = 127.0.0.1
local_port = 1194
remote_port = 7009

[dsm1-https2http]
type = tcp
local_ip = 172.17.0.1
remote_port = 40020
plugin = https2http
plugin_local_addr = 172.17.0.1:5000
plugin_crt_path = /etc/frp/example.com.pem
plugin_key_path = /etc/frp/example.com.key