1、systemctl enable 服务名 可以使用systemctl is-enabled 服务名 查看是否设置开机启动
很多服务不能用systemctl启动。可以复制服务名.service文件到/lib/systemd/system/
即可使用systemctl命令操作服务,service文件一般在程序目录中都有提供。
2、/etc/rc.d/rc.local文件,可以加启动脚本,例如:sh /opt/abc.sh
给/opt/abc.sh运行权限即可开机运行脚本。如果centos7弱化了rc.local。不成功就给rc.local加执行权限即可。
3、
将脚本移动到/etc/rc.d/init.d目录下
mv /opt/script/autostart.sh /etc/rc.d/init.d
增加脚本的可执行权限
chmod +x /etc/rc.d/init.d/autostart.sh
添加脚本到开机自动启动项目中
cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on
3这个我没试过。应该都是好用的。
本文介绍三种在 CentOS 7 中设置服务或脚本开机自启动的方法:使用 systemctl 工具、编辑 /etc/rc.d/rc.local 文件以及通过 /etc/rc.d/init.d 目录下的脚本。
238

被折叠的 条评论
为什么被折叠?



