操作系统和 frpc 版本信息如下:
# 系统信息 hxstrive@g450:~$ uname -a Linux g450 5.15.0-141-generic #151-Ubuntu SMP Sun May 18 21:35:19 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux # frpc 版本信息 hxstrive@g450:~$ ll frp_0.61.1_linux_amd64/ total 153148 drwxr-xr-x 2 hxstrive hxstrive 4096 Jun 12 14:17 ./ drwxr-x--- 13 hxstrive hxstrive 4096 Jun 12 14:38 ../ -rwxr-xr-x 1 hxstrive hxstrive 15245464 Dec 16 11:44 frpc* -rw-r--r-- 1 hxstrive hxstrive 291 Jun 1 11:51 frpc.toml -rwxr-xr-x 1 hxstrive hxstrive 19394712 Dec 16 11:44 frps* -rw-r--r-- 1 hxstrive hxstrive 161 Dec 27 02:28 frps.toml -rw-r--r-- 1 hxstrive hxstrive 11358 Dec 16 11:47 LICENSE -rw------- 1 hxstrive hxstrive 122140677 Jun 12 14:17 nohup.out -rwxr-xr-x 1 hxstrive hxstrive 116 Jun 12 14:17 start-frpc.sh*
# 进入 /etc/systemd/system 目录 root@g450:/home/hxstrive# cd /etc/systemd/system # 创建 frpc.service 文件 root@g450:/etc/systemd/system# vim frpc.service
frpc.service 文件内容如下:
[Unit] Description=frp client service After=network.target network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/home/hxstrive/frp_0.61.1_linux_amd64/frpc -c /home/hxstrive/frp_0.61.1_linux_amd64/frpc.toml User=hxstrive Group=hxstrive Restart=on-failure RestartSec=5 LimitNOFILE=65535 [Install] WantedBy=multi-user.target
上述配置文件主要分为三个部分:
[Unit] 部分:
Description: 服务描述信息
After: 指定服务启动顺序,确保网络完全启动后再启动 FRPC
Wants: 与 After 配合,声明弱依赖关系
[Service] 部分:
Type: 服务类型,simple 表示直接执行 ExecStart 命令
ExecStart: 启动命令,指定 FRPC 程序路径和配置文件
User/Group: 指定服务运行的用户和用户组
Restart: 失败后自动重启
RestartSec: 重启前等待的秒数
LimitNOFILE: 设置最大文件描述符数量
[Install] 部分:
WantedBy: 指定服务在哪个运行级别下启用
成功创建 frpc.service 文件后,执行如下命令,开启开机自动启动:
sudo systemctl enable frpc.service
重启系统,重启后查看 frpc.service 服务信息,如下:
root@g450:/etc/systemd/system# systemctl status frpc.service ● frpc.service - frp client service Loaded: loaded (/etc/systemd/system/frpc.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2025-06-12 14:49:01 UTC; 10min ago Main PID: 692 (frpc) Tasks: 4 (limit: 4516) Memory: 15.1M CPU: 136ms CGroup: /system.slice/frpc.service └─692 /home/hxstrive/frp_0.61.1_linux_amd64/frpc -c /home/hxstrive/frp_0.61.1_linux_amd64/frpc.toml Jun 12 14:49:01 g450 systemd[1]: Started frp client service. Jun 12 14:49:02 g450 frpc[692]: 2025-06-12 14:49:02.244 [I] [sub/root.go:142] start frpc service for config file [/home/hxstrive/frp_0.61.1_linux_amd64/frpc.toml] Jun 12 14:49:02 g450 frpc[692]: 2025-06-12 14:49:02.245 [I] [client/service.go:295] try to connect to server... Jun 12 14:49:02 g450 frpc[692]: 2025-06-12 14:49:02.420 [I] [client/service.go:287] [4e6271a5c3493a54] login to server success, get run id [4e6271a5c3493a54] Jun 12 14:49:02 g450 frpc[692]: 2025-06-12 14:49:02.420 [I] [proxy/proxy_manager.go:173] [4e6271a5c3493a54] proxy added: [g450-ssh] Jun 12 14:49:02 g450 frpc[692]: 2025-06-12 14:49:02.465 [I] [client/control.go:168] [4e6271a5c3493a54] [g450-ssh] start proxy success
在使用 ps -ef 命令查看进程信息,如下:
root@g450:/etc/systemd/system# ps -ef | grep frpc hxstrive 692 1 0 14:49 ? 00:00:00 /home/hxstrive/frp_0.61.1_linux_amd64/frpc -c /home/hxstrive/frp_0.61.1_linux_amd64/frpc.toml root 2313 2095 0 15:00 pts/0 00:00:00 grep --color=auto frpc
到这里,设置 frpc 开机自动启动就成功了。