ubuntu18实现本地的 rc.local 功能,开机自动启动frpc

最近在实现frp的内网穿透,但是一直开机不能自动启动,这样的设计肯定是不行的,现在将我找到的开机自动启动的方法分享一下。

本博客参考于 https://www.cnblogs.com/airdot/p/9688530.html

ubuntu18 貌似是已经不支持rc.local 这个开机自动启动的脚本了,所以为了能继续用这个脚本,我需要去编写一个ubuntu18 下的启动脚本,通过这个脚本来启动我的rc.local脚本。

创建一个rc-local.service

sudo vi /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target

将上面这段内容写到rc-local.service。

接下来就是创建一个rc.local

sudo vi /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
nohup /home/jeason/frp/frpc -c /home/jeason/frp/frpc.ini & # 启动frp
exit 0

将上述的脚本赋值到rc.local   注意 关于frpc 的运行指令必须包含完整的路径!

接下来是给rc.local 执行的权限

sudo chmod +x /etc/rc.local

接下来是启动服务

sudo systemctl start rc-local.service

测试服务的状态

sudo systemctl status rc-local.service

猜你喜欢

转载自blog.csdn.net/weixin_41534481/article/details/107892325
今日推荐