溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

centos7怎么添加開機(jī)啟動服務(wù)

發(fā)布時間:2021-08-13 21:15:36 來源:億速云 閱讀:351 作者:chen 欄目:系統(tǒng)運(yùn)維

本篇內(nèi)容介紹了“centos7怎么添加開機(jī)啟動服務(wù)”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

一、添加開機(jī)自啟服務(wù)

在centos7中添加開機(jī)自啟服務(wù)非常方便,只需要兩條命令(以Jenkins為例):

systemctl enable jenkins.service #設(shè)置jenkins服務(wù)為自啟動服務(wù)
sysstemctl start  jenkins.service #啟動jenkins服務(wù)

二、添加開機(jī)自啟腳本

在centos7中增加腳本有兩種常用的方法,以腳本autostart.sh為例:

#!/bin/bash
#description:開機(jī)自啟腳本
/usr/local/tomcat/bin/startup.sh  #啟動tomcat

方法一

1、賦予腳本可執(zhí)行權(quán)限(/opt/script/autostart.sh是你的腳本路徑)

chmod +x /opt/script/autostart.sh

1
2、打開/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、將腳本移動到/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、添加腳本到開機(jī)自動啟動項目中

cd /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on

“centos7怎么添加開機(jī)啟動服務(wù)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI