frp后台运行
1. 使用 & 在后台运行
你可以简单地在命令末尾加上 &,让 frps 以后台进程的形式启动:
这种方式会在后台运行 frps,并且你会看到进程的 PID(进程ID),你可以使用 jobs 或 ps 来查看进程。
2. 使用 nohup 命令
nohup 命令可以让程序在后台运行,并且即使关闭终端会话,进程也不会被终止。你可以这样使用:
1
| nohup ./frps -c ./frps.toml > frps.log 2>&1 &
|
nohup:使程序在后台运行并忽略终端退出的信号。
> frps.log 2>&1:将标准输出和标准错误输出都重定向到 frps.log 文件。
&:将进程放到后台运行。
3. 使用 systemd 管理服务
如果你希望 frps 作为系统服务在后台长期运行,你可以创建一个 systemd 服务来管理它。以下是一个基本的示例:
步骤:
- 创建一个
frps 的 systemd 服务文件:
1
| sudo vi /etc/systemd/system/frps.service
|
- 在文件中添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12
| ini复制代码[Unit] Description=FRP Server After=network.target
[Service] ExecStart=/path/to/frps -c /path/to/frps.toml WorkingDirectory=/path/to/directory Restart=always User=root
[Install] WantedBy=multi-user.target
|
ExecStart:指定 frps 的启动命令。
WorkingDirectory:指定 FRP 所在的工作目录。
Restart=always:如果服务崩溃,systemd 会自动重新启动服务。
User=root:指定服务运行的用户。
- 重新加载
systemd 配置并启动服务:
1 2
| sudo systemctl daemon-reload sudo systemctl start frps
|
- 设置开机启动:
1
| sudo systemctl enable frps
|
- 查看服务状态:
1
| sudo systemctl status frps
|
总结
- 如果你只是希望临时将
frps 放到后台运行,使用 & 或 nohup 都可以。
- 如果你希望将
frps 设置为系统服务,并确保它在系统重启后自动启动,使用 systemd 是最合适的方式。