给frp设置开机自启
好的,明白了。如果你确定只需要 yuuu
用户运行,并且接受这种方式(虽然不是系统服务的标准做法,但对于单用户服务器上的个人应用来说通常没问题),那么配置会简单很多,因为不需要担心 nobody
用户访问 /home/yuuu
目录的权限问题。
下面是为 yuuu
用户量身定制的 frpc.service
文件内容:
-
创建并编辑
systemd
服务文件:sudo vim /etc/systemd/system/frpc.service
-
粘贴以下内容:
按i
进入插入模式,然后粘贴:[Unit] Description=FRP Client Service (run as yuuu) # Start after the network is available After=network.target syslog.target Wants=network.target[Service] Type=simple# --- Run the service as user yuuu --- User=yuuu # Use the primary group of user yuuu. Usually, it's the same as the username. # You can double-check with the command: id -gn yuuu Group=yuuu# Restart the service if it fails Restart=on-failure RestartSec=5s# Command to start frpc with your specific paths ExecStart=/home/yuuu/data/frp/frp_0.62.1_linux_amd64/frpc -c /home/yuuu/data/frp/frp_0.62.1_linux_amd64/frpc.toml# Set the working directory (good practice) WorkingDirectory=/home/yuuu/data/frp/frp_0.62.1_linux_amd64/[Install] # Enable the service for multi-user mode (standard runlevel) WantedBy=multi-user.target
-
保存并退出:
- 按
Esc
键退出插入模式。 - 输入
:wq
并按Enter
保存并退出vim
。
说明:
User=yuuu
: 指定服务以yuuu
用户身份运行。Group=yuuu
: 指定服务以yuuu
用户的主用户组身份运行。在大多数 Ubuntu 系统上,默认创建用户时会创建一个同名的组。你可以通过运行id -gn yuuu
命令来确认yuuu
用户的主用户组名。如果命令输出的不是yuuu
,请将Group=
后面的值修改为实际的组名。ExecStart
: 已经根据你提供的路径设置好了。WorkingDirectory
: 也设置好了。
- 按
-
执行后续命令:
现在,你可以像之前一样执行命令来管理这个服务了:- 重新加载 systemd 配置:
sudo systemctl daemon-reload
- 启用服务 (设置开机自启):
sudo systemctl enable frpc.service
- 立即启动服务:
sudo systemctl start frpc.service
- 检查服务状态:
(应该显示sudo systemctl status frpc.service
Active: active (running)
) - 查看日志 (如果需要):
sudo journalctl -u frpc.service -f --no-pager
- 重新加载 systemd 配置:
这样配置后,frpc
就会在开机时以 yuuu
用户的身份自动启动,并且可以访问其家目录下的配置文件和程序。