systemctl设置服务器frp服务自启动

937次阅读
没有评论

这里以启动frp客户端为例

创建服务service文件

vi /etc/systemd/system/frpc.service

内容如下:

[Unit]
Description=frp client
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/local/frpc/frpc -c /usr/local/frpc/frpc.toml

[Install]
WantedBy=multi-user.target

配置详解

service参数详解

启动服务

systemctl start frpc.service

停止服务

systemctl stop frpc.service

重新启动服务

systemctl restart frpc.service

设置开启自启动

systemctl enable frpc.service

配置更新

当修改了.services配置文件需要重启服务时,可以使用下面命令

systemctl daemon-reload

错误排查

使用journalctl -xe命令查看具体的日志

注意:如果设置了:Restart=alwaysRestartSec=1,在宝塔的控制面板中重启服务,会导致每点击一次重启就多一个进程在运行,这是因为每次点击重启,实际上会kill掉进程,并且启动一个新的进程,但是在进程被kill到重启的过程中,进程守卫监测到服务挂掉了,就会自动的创建一个新进程。

解决方法就是要么不使用宝塔的重启服务功能,而是停止功能,由于停止进程了,进程守卫监测到服务挂掉了,就会自动启动一个新的进程。要么就是修改Restart=alwaysRestartSec=1,具体查阅:解决 Linux 服务重启导致进程过多的问题 – WUJINGQUAN

参考

正文完
 1
wujingquan
版权声明:本站原创文章,由 wujingquan 于2024-09-20发表,共计856字。
转载说明:Unless otherwise specified, all articles are published by cc-4.0 protocol. Please indicate the source of reprint.
评论(没有评论)