frp开机自启动命令配置详解

frp(Fast Reverse Proxy)允许你通过一个中心服务器(frps)来转发流量到内网中的机器。在某些场景下,你可能需要 frp 在系统启动时自动启动,以确保内网穿透服务的连续性和稳定性。

提示:如Linux上没有安装 systemd,可以使用 yum 或 apt 等命令安装 systemd(本地设备同理)

# yum
yum install systemd
# apt
apt install systemd

使用 创建并编辑 文件。此处的文件名称决定了服务的名称。

服务器端为frps

本地设备为frpc

服务器端使用
vim /etc/systemd/system/frps.service

本地设备端使用
vim /etc/systemd/system/frps.service

1、编辑服务端

[Unit]
#服务描述
Description=frpc service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
#执行命令
ExecStart=/root/frpc/frps -c /root/frpc/frps.ini

ExecStop=/bin/kill $MAINPID
Restart=always #监控服务是否成功启动,未启动等待5分钟后从新启动
RestartSec=5 #等待时间
StartLimitInterval=0

[Install]
WantedBy=multi-user.target

2、编辑本地设备端

[Unit]
#服务描述
Description=frpc service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
#执行命令
ExecStart=/root/frpc/frpc -c /root/frpc/frpc.ini

ExecStop=/bin/kill $MAINPID
Restart=always #监控服务是否成功启动,未启动等待5分钟后从新启动
RestartSec=5 #等待时间
StartLimitInterval=0

[Install]
WantedBy=multi-user.target
以下命令双端都需运行

3、更新systemctl
systemctl daemon-reload

配置 frps 开机自启
systemctl enable frps

4、Linux下systemd常用命令

使用 命令,管理 frps

# 启动frp
systemctl start frps
# 停止frp
systemctl stop frps
# 重启frp
systemctl restart frps
# 查看frp状态
systemctl status frps
linux下FRP常用命令

后台运行frp

#定位至frp文件所在位置
#服务端:
nohup ./frps -c frps.ini >/dev/null 2>&1 &
#客户端:
nohup ./frpc -c frpc.ini >/dev/null 2>&1 &

查看frp进程
ps -aux|grep frp| grep -v grep

结束frp进程
kill -9 12345(找到的进程号)

原文地址:
https://www.bilibili.com/read/cv28849638/
https://blog.csdn.net/qq_30163677/article/details/143479378

Related Posts