linux 添加开机启动

/etc/profile.d/

写好的 .sh 文件放到目录 /etc/profile.d/ 下,系统启动后自动执行目录下全部shell脚本

例如:

#!/bin/sh
#description: 开机自启动脚本

# 执行后台服务启动

编辑rc-local.service

适用于Ubuntu20.04

# vim /lib/systemd/system/rc-local.service
[Install]
WantedBy=multi-user.target

检查 /etc/rc.local 文件是否存在

cat /etc/rc.local

不存在时则创建

vim/etc/rc.local
chmod 755 /etc/rc.local

rc.local 实际为脚本文件,因此需要在顶部添加 #!/bin/bash,之后将开机要执行的脚本或命令添加到 rc.local 即可

启动服务

systemctl enable rc-local
posted @ 2021-01-27 16:46  鲁哒哒  阅读(99)  评论(0编辑  收藏  举报