使用systemd管理frps 服务端的启动、停止、配置后台运行以及开机自启动

在 Linux 系统下,使用 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

2、创建 frps.service 文件

使用文本编辑器 (如 vim) 在 /etc/systemd/system 目录下创建一个 frps.service 文件,用于配置 frps 服务。

sudo 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/frp_0.59.0_linux_amd64/frps -c /usr/local/frp/frp_0.59.0_linux_amd64/frps.toml

[Install]
WantedBy = multi-user.target

3、使用 systemd 命令管理 frps 服务

# 启动frp
sudo systemctl start frps
# 停止frp
sudo systemctl stop frps
# 重启frp
sudo systemctl restart frps
# 查看frp状态
sudo systemctl status frps

4、设置 frps 开机自启动

sudo systemctl enable frps

5、如果Warning: frps.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
警告:磁盘上的网络服务已更改。运行“systemctl daemon-reload”来重装单元。

# 服务端启动命令, & 表示后台运行
./frps -c ./frps.toml &
# 配置文件
frps.toml
# 客户端启动命令, & 表示后台运行
./frpc -c ./frpc.toml &
# 配置文件
frpc.toml

frp服务端搭建教程(linux服务器)

#下载
wget https://github.com/fatedier/frp/releases/download/v0.59.0/frp_0.59.0_linux_amd64.tar.gz
#解压
tar -zxvf frp_0.59.0_linux_amd64.tar.gz
#进入目录
cd frp_0.59.0_linux_amd64

服务端配置:

服务端配置时修改frps.toml文件,官方给出了完整的配置文件说明。

# IPv6的字面地址或主机名必须括起来。
# 在方括号中,如“[::1]:80”、“[ipv6-host]:http”或“[ipv6-host%zone]:80”
# 对于单个 "bindAddr" 字段,不需要方括号,例如 `bindAddr = "::"`。
bindAddr = "0.0.0.0"
# 隧道端口,服务端通过此端口与客户端通信
bindPort = 7000
​
# 用于KCP协议的UDP端口,可以与“bindPort”相同。
# 如果未设置,frps 中的 kcp 将被禁用。
kcpBindPort = 7000
​
# 每个代理中最大池数量。
transport.maxPoolCount = 5
​
# 如果你想支持虚拟主机,你必须设置用于监听的http端口(可选)
# 注意:http端口和https端口可以与bindPort相同。
# 由于备案原因,一般不使用80和443端口,可以自定义
vhostHTTPPort = 7001
vhostHTTPSPort = 7002
​
​
# frps后台
# dashboard is available only if webServer.port is set.
webServer.addr = "127.0.0.1"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin"
​
​
# console or real logFile path like ./frps.log
log.to = "./frps.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 3
# disable log colors when log.to is console, default is false
log.disablePrintColor = false
​
​
# 服务端和客户端使用token鉴权
auth.method = "token"
# 设置token值
auth.token = "12345678"
​
# 每个客户端可以使用的最大端口数,默认值为0表示没有限制。
maxPortsPerClient = 0
​
# 如果服务端主机进行了域名绑定,则填入对应域名,否则填入服务器的公网IP地址
subDomainHost = "baidu.com"

frp安装教程
Frp项目地址:https://github.com/fatedier/frp
Frp文档:https://gofrp.org/zh-cn/docs/
linux服务端:https://github.com/fatedier/frp/releases/download/v0.59.0/frp_0.59.0_linux_amd64.tar.gz
windows客户端:
https://github.com/fatedier/frp/releases/download/v0.59.0/frp_0.59.0_windows_amd64.zip
1、下载frp
2、上传到服务器usr/local目录(以这个为例)
3、解压文件 tar -zxvf frp_0.59.0_linux_amd64.tar.gz
4、cd frp_0.59.0_linux_amd64

赞(1) 支付宝扫码领红包
未经允许不得转载:易语言编程学习 » 使用systemd管理frps 服务端的启动、停止、配置后台运行以及开机自启动

评论 抢沙发

评论前必须登录!

 

有几率领到大红包

支付宝扫一扫