虽然可以通过frp自带的服务文件来做,但事实发现其实不如手动配置来的靠谱,因为还需要做一些修改,所以不如直接手动添加服务。

首先做好frp服务配置,服务端和客户端案例分别如下:


服务端配置和自动设置

创建服务脚本并编辑 vi /etc/systemd/system/frps.service

内容如下:(注意,代码中的frps.ini是服务端配置文件,请依据自己的实际情况做相应修改)

[Unit]
Dcription=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
User=root
Restart=on-failure
ExecStart=/root/frp/frps -c /root/frp/frps.ini
ExecReload=/root/frp/frps -c /root/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit

[Install]
WantedBy=multi-user.target

加入服务列表并设置自启动

#重新加载服务列表
systemctl daemon-reload
#将frps加入开机自启动
systemctl enable frps.service
#启动服务
systemctl start frps.service

#以下是其他常用命令
#关闭服务
systemctl stop frps.service
#重启服务
systemctl restart frps.service
#显示服务的状态
systemctl status frps.service
#禁用服务开机启动
systemctl disable frps.service
#查看服务是否开机启动
systemctl is-enabled frps.service
#查看已经启动的服务列表
systemctl list-unit-files|grep enable
#查看启动失败的服务列表
systemctl --failed配置和自启动设置

客户端配置和自动设置

客户端与服务端配置方法完全一致,代码如下:

创建服务脚本并编辑 vi /etc/systemd/system/frpc.service

内容如下:(注意,代码中的frpc.ini是客户端配置文件,请依据自己的实际情况做相应修改)

[Unit]
Dcription=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
User=root
Restart=on-failure
ExecStart=/root/frp/frpc -c /root/frp/frpc.ini
ExecReload=/root/frp/frpc -c /root/frp/frpc.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit

[Install]
WantedBy=multi-user.target

加入服务列表并设置自启动

#重新加载服务列表
systemctl daemon-reload
#将frpc加入开机自启动
systemctl enable frpc.service
#启动服务
systemctl start frpc.service

#以下是其他常用命令
#关闭服务
systemctl stop frpc.service
#重启服务
systemctl restart frpc.service
#显示服务的状态
systemctl status frpc.service
#禁用服务开机启动
systemctl disable frpc.service
#查看服务是否开机启动
systemctl is-enabled frpc.service
#查看已经启动的服务列表
systemctl list-unit-files|grep enable
#查看启动失败的服务列表
systemctl --failed

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注