加服务为centos开机启动设置

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这个我没试过。应该都是好用的。

猜你喜欢

转载自blog.csdn.net/leonnew/article/details/80916941