12

使用 systemd 管理 frpc 服务

 2 years ago
source link: https://blog.triplez.cn/posts/using-systemd-manage-frpc-service/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Life is short, I use systemd.

前言#

frp[1] 是著名的内网穿透软件,支持 TCP、UDP 协议,且只需简单配置服务端,通过编辑客户端配置即可完成内网穿透的功能。但是其只提供了二进制可执行文件,并没有将其打包,也就无法使用 systemd。而对于一个需要开机启动、失败拉起的基础功能来说,我们有对其通过 systemd 进行管理的需求,也就有了本文。

注册 frpc 服务#

其实使用 systemd 来管理程序相当简单。只需要在 /etc/systemd/system/ 下写一个 *.service 的文件注册即可。

/etc/systemd/system/ 目录下新建 frpc.service

$ sudo touch /etc/systemd/system/frpc.service

将以下内容填入至 frpc.service

[Unit]
Description=FRP Client Daemon
After=network.target
Wants=network.target

[Service]
Type=simple
ExecStart=/path/to/your/frpc -c /path/to/your/frpc.ini
Restart=always
RestartSec=20s
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

frpc.service 的内容遵循 systemd 的配置格式[2][3]。

保存后重载 systemd 配置:

$ sudo systemctl daemon-reload

通过 systemd 控制 frpc#

启动 frpc:

$ sudo systemctl start frpc

停止 frpc:

$ sudo systemctl stop frpc

查看 frpc 状态:

$ systemctl status frpc

将 frpc 设为开机启动:

$ sudo systemctl enable frpc

取消 frpc 开机启动:

$ sudo systemctl disable frpc

使用方法与 systemd units [4]相同。

References#


知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK