主要是使用system进行开机启动设置,需要后台运行的服务,创建一个 systemd 服务。

1
cd /etc/systemd/system

添加frp开机启动

Server端启动

编辑frps.service,如下:

1
2
# server端
sudo vim /etc/systemd/system/frps.service

复制如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Frp Server Daemon
After=network.target

[Service]
Type=simple
ExecStart=/home/ubuntu/frp/frps -c /home/ubuntu/frp/frps.ini
Restart=always
RestartSec=10
User=root
Group=root

[Install]
WantedBy=multi-user.target

设置开机启动:

1
2
3
sudo systemctl enable frps.service
sudo systemctl start frps.service
sudo systemctl stop frps.service

查看看机启动状态

1
sudo systemctl status frps.service

客户端启动

1
sudo vim /etc/systemd/system/frpc.service

复制如下,记得修改对应路径的位置

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=frpc Service
After=network.target

[Service]
ExecStart=/home/ubuntu/frp/frpc -c /home/ubuntu/frp/frpc.toml #此处修改自己的位置
Restart=always
User=root
Group=root

[Install]
WantedBy=multi-user.target

设置开机启动:

1
2
3
4
5
6
sudo systemctl enable frpc.service
sudo systemctl start frpc.service
sudo systemctl stop frpc.service

sudo systemctl daemon-reload
sudo systemctl restart frpc.service

查看看机启动状态

1
sudo systemctl status frpc.service