You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22下将手动编译安装的ocserv配置为系统服务求助

Ubuntu 22下将手动编译安装的ocserv配置为系统服务求助

没问题,我来帮你把手动编译的ocserv配置成systemd系统服务,这样就能实现开机自启、后台运行,还能方便地管理服务状态了。

步骤1:创建systemd服务文件

因为你是手动编译安装的ocserv,系统默认没有自带它的服务配置文件,我们需要自己创建一个。打开终端执行:

sudo nano /etc/systemd/system/ocserv.service

然后把下面的内容粘贴进去(注意检查ExecStart里的ocserv路径,如果你的ocserv不在默认PATH里,比如实际路径是/usr/local/sbin/ocserv,就替换成绝对路径):

[Unit]
Description=OpenConnect VPN Server (ocserv)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/sbin/ocserv -c /etc/ocserv/ocserv.conf
ExecStop=/usr/local/sbin/ocserv -c /etc/ocserv/ocserv.conf --shutdown
Restart=always
RestartSec=5
User=root
Group=root

[Install]
WantedBy=multi-user.target

粘贴完成后,按Ctrl+O保存,Ctrl+X退出编辑器。

步骤2:重新加载systemd配置

让systemd识别我们刚创建的服务文件:

sudo systemctl daemon-reload

步骤3:设置开机自启

执行下面的命令,让ocserv在系统启动时自动运行:

sudo systemctl enable ocserv

步骤4:启动服务并验证状态

现在可以启动ocserv服务了:

sudo systemctl start ocserv

然后用下面的命令检查服务是否正常运行:

sudo systemctl status ocserv

如果输出显示active (running),就说明配置成功了!

额外提示

  • 如果启动失败,先检查/etc/ocserv/ocserv.conf配置文件是否存在、格式是否正确,权限是否为root可读。
  • 后续管理服务常用命令:
    • 停止服务:sudo systemctl stop ocserv
    • 重启服务:sudo systemctl restart ocserv

备注:内容来源于stack exchange,提问作者Ethan_m

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 15:18:14