概括如何在 CentOS 系统下部署 frps 服务,包括启动、停止、配置后台运行和设置开机自启动;以及如何在 Windows 系统下部署 frpc 服务。

下载

frp 采用 Go 语言编写,支持跨平台,只需下载适用于系统平台的二进制文件即可执行,无需额外依赖。

关闭 CentOS 防火墙

# 关闭防火墙
systemctl stop firewalld

# 开机禁用
systemctl disable firewalld

部署

  1. 解压下载的压缩包。
  2. frpc 复制到内网 Windows 上。
  3. 用FinalShell将 frps 复制到 CentOS 机器上,并将它们放在任意目录(我直接放在root根目录了,注意需要给777权限)。

frps_example.toml

# 连接到 CentOS 的通信端口,需要和frpc.toml配置文件中端口一致
bindPort = 7000

# 与frpc通信鉴权方式和密钥
auth.method = "token"
auth.token = "thisisatoken"

# 允许限制对外开放的端口
allowPorts = [
  { start = 2000, end = 3000 },
  { single = 3001 },
  { single = 3003 },
  { start = 4000, end = 50000 }
]

# 仪表盘的端口、账号、密码
webServer.addr = "127.0.0.1"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin"

frpc_example.toml

# CentOS 的域名
serverAddr = "www.xxx.com"

# 连接到 CentOS 的通信端口,需要和frps.toml配置文件中端口一致
serverPort = 7000

# 与frps通信鉴权方式和密钥
auth.method = "token"
auth.token = "thisisatoken"

# 开放端口连接
[lproxies]]
name = "test-tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 6100
   
# 共享文件访问
[proxies]]
name = "d_drive"
type = "tcp"
remotePort = 6200  # 服务器上用于访问的端口
[proxies. plugin]
type = "static_file"
LocalPath = "D:\\"  # 要对外暴露的目录
stripPrefix = "d_drive"  # 访问路径名,此处即http://x.X.x.X:6001/d_drive/
httpUser = "username" # 用户名
httpPassword = "password" # 密码

# 远程桌面访问
[lproxies]]
name = "RDP-123"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3389
remotePort = 6300

使用 systemd 来管理 frps 服务,包括启动、停止、配置后台运行和设置开机自启动

  1. 安装 systemd

    如果 Linux 服务器上尚未安装 systemd,可以使用包管理器如 `yum`(适用于 CentOS/RHEL)或 `apt`(适用于 Debian/Ubuntu)来安装它:
    
    # 使用 yum 安装 systemd(CentOS/RHEL)
    yum install systemd
    
    # 使用 apt 安装 systemd(Debian/Ubuntu)
    apt install systemd
    
  1. 创建 frps.service 文件

    在 windows 上新建一个文本文档命名为 frps.service 并写入内容

    [Unit]
    # 服务名称,可自定义
    Description = frp server
    After = network.target syslog.target
    Wants = network.target
    
    [Service]
    Type = simple
    # 启动frps的命令,需修改为您的frps的安装路径
    ExecStart = /root/frps -c /root/frps.toml
    
    [Install]
    WantedBy = multi-user.target

    将新建好的 frps.service 文件放到 /etc/systemd/system 目录下,用于配置 frps 服务。

  2. 使用 systemd 命令管理 frps 服务

    # 启动frp
    sudo systemctl start frps
    # 停止frp
    sudo systemctl stop frps
    # 重启frp
    sudo systemctl restart frps
    # 查看frp状态
    sudo systemctl status frps
  3. 设置 frps 开机自启动

    sudo systemctl enable frps

Windows 开机自动启动且后台运行frpc

  1. 创建 frp.vbs 脚本文件

    在 windows 上新建一个文本文档命名为 frp.vbs 并写入内容

    set ws=wscript.createobject("wscript.shell") 
    ws.run"E:\frp_0.64\frpc.exe -c E:\frp_0.64\frpc.ini",0     # 根据frpc的存放路径填写绝对路径
  2. 执行 frp.vbs 脚本文件

    鼠标左键双击运行 frp.vbs 脚本,可以在任务管理器看到 frpc 程序在后台进程中,即成功运行。

  3. 将 frp.vbs 脚本文件复制粘贴放入 Windows 开机自启目录

    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
最后修改:2025 年 09 月 23 日
彩!