frp服务注册以及systemd语法

本文详细介绍了如何使用frp的systemd配置文件来灵活启动和管理多个frpc服务实例。通过创建模板.service文件并利用%i参数,可以针对不同的配置文件启动独立的服务,实现高效的服务管理和自动化操作。

https://github.com/fatedier/frp/releases
从github上面下载了frp的release以后解压,里面有一个systemd的文件夹,这是干什么用的呢?
在这里插入图片描述
打开之后,会发现文件夹里面有一些文件名为frps、或者是frps@,其实这些就是systemd注册的配置。
在这里插入图片描述
点开查看如下

在这里插入图片描述

在这里插入图片描述可以看到frpc和frpc@文件里面只相差一个%i,我们可以从linux配置文件说明里找到这样做的理由。

Units names can be parameterized by a single argument called the “instance name”. The unit is then constructed based on a “template file” which serves as the definition of multiple services or other units. A template unit must have a single “@” at the end of the name (right before the type suffix). The name of the full unit is formed by inserting the instance name between “@” and the unit type suffix. In the unit file itself, the instance parameter may be referred to using “%i” and other specifiers, see below.

也就是说,带有@的.service文件相当于一个模版文件,能够根据启动时候加的参数不同,替换文件里面的%i位置的内容,从而可以根据不同的参数启动不同的服务,比如说这个frpc@.service文件,里面的%i标记是加在.ini前面的,那么启动服务的时候就可以通过参数的形式传入不同的配置文件从而启动不同配置的frpc服务。
我们把下载好的所有*.ini文件放到/etc/frpc/目录下,同时在相同目录里面新建一个文件名为test.ini,把所有*.service文件放到/etc/systemd/system/目录下
然后输入命令

systemctl enable frpc@test#这步用来注册服务
systemctl start frpc@test#这步用来启动服务

那么系统就会注册一个名为frpc@test的服务,但是显然这个服务是你用模版灵活启动的。
服务注册相关资料:
系统注册systemd.unit

Warning: The unit file, source configuration file or drop-ins of frps.service changed on disk. Run 'systemctl daemon-reload' to relo> ● frps.service - frp server Loaded: bad-setting (Reason: Unit frps.service has a bad unit file setting.) Active: failed (Result: exit-code) since Tue 2025-08-05 20:07:05 CST; 2min 36s ago Main PID: 34070 (code=exited, status=203/EXEC) Aug 05 20:07:01 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Main process exited, code=exited, status=203/EXEC Aug 05 20:07:01 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed with result 'exit-code'. Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: /etc/systemd/system/frps.service:10: Neither a valid executable name nor an abso> Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Service RestartSec=100ms expired, scheduling restart. Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed to schedule restart job: Unit frps.service has a bad unit f> Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed with result 'exit-code'. Aug 05 20:09:34 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: /etc/systemd/system/frps.service:10: Neither a valid executable name nor an abso> lines 1-13/13 (END)...skipping... Warning: The unit file, source configuration file or drop-ins of frps.service changed on disk. Run 'systemctl daemon-reload' to reload units. ● frps.service - frp server Loaded: bad-setting (Reason: Unit frps.service has a bad unit file setting.) Active: failed (Result: exit-code) since Tue 2025-08-05 20:07:05 CST; 2min 36s ago Main PID: 34070 (code=exited, status=203/EXEC) Aug 05 20:07:01 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Main process exited, code=exited, status=203/EXEC Aug 05 20:07:01 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed with result 'exit-code'. Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: /etc/systemd/system/frps.service:10: Neither a valid executable name nor an absolute path: root/fprs/frps.toml Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Service RestartSec=100ms expired, scheduling restart. Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed to schedule restart job: Unit frps.service has a bad unit file setting. Aug 05 20:07:05 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: frps.service: Failed with result 'exit-code'. Aug 05 20:09:34 iZ7xvbt3zhm0gi3crn9h7bZ systemd[1]: /etc/systemd/system/frps.service:10: Neither a valid executable name nor an absolute path: root/fpr/frps.toml
08-06
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值