一、添加開(kāi)機(jī)自啟服務(wù)
在centos7中添加開(kāi)機(jī)自啟服務(wù)非常方便瘦麸,只需要兩條命令(以Jenkins為例):
systemctl enable jenkins.service #設(shè)置jenkins服務(wù)為自啟動(dòng)服務(wù)
sysstemctl start jenkins.service #啟動(dòng)jenkins服務(wù)
二狞换、添加開(kāi)機(jī)自啟腳本
在centos7中增加腳本有兩種常用的方法,以腳本autostart.sh為例:
#!/bin/bash
#description:開(kāi)機(jī)自啟腳本
/usr/local/tomcat/bin/startup.sh #啟動(dòng)tomcat
方法一
1裕坊、賦予腳本可執(zhí)行權(quán)限(/opt/script/autostart.sh是你的腳本路徑)
chmod +x /opt/script/autostart.sh
2雪营、打開(kāi)/etc/rc.d/rc/local文件说庭,在末尾增加如下內(nèi)容
/opt/script/autostart.sh
3、在centos7中,/etc/rc.d/rc.local的權(quán)限被降低了拗军,所以需要執(zhí)行如下命令賦予其可執(zhí)行權(quán)限
chmod +x /etc/rc.d/rc.local
方法二
1、將腳本移動(dòng)到/etc/rc.d/init.d目錄下
mv /opt/script/autostart.sh /etc/rc.d/init.d
2呵曹、增加腳本的可執(zhí)行權(quán)限
chmod +x /etc/rc.d/init.d/autostart.sh
3脏款、添加腳本到開(kāi)機(jī)自動(dòng)啟動(dòng)項(xiàng)目中
cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on
以上兩種方法均已在centos7系統(tǒng)上驗(yàn)證過(guò),如有疑問(wèn)退盯,歡迎大家評(píng)論留言
分類: 腳本