在CentOS系統(tǒng)下,主要有兩種方法設(shè)置自己安裝的程序開(kāi)機(jī)啟動(dòng)。
1、把啟動(dòng)程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是設(shè)置開(kāi)機(jī)啟動(dòng)httpd。
#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff. touch /var/lock/subsys/local/usr/local/apache/bin/apachectl start
2、把寫(xiě)好的啟動(dòng)腳本添加到目錄/etc/rc.d/init.d/,然后使用命令chkconfig設(shè)置開(kāi)機(jī)啟動(dòng)。
chkconfig 功能說(shuō)明:檢查,設(shè)置系統(tǒng)的各種服務(wù)。
語(yǔ)法:chkconfig [--add][--del][--list][系統(tǒng)服務(wù)] 或 chkconfig [--level <等級(jí)代號(hào)>][系統(tǒng)服務(wù)][on/off/reset]
--add 添加服務(wù)
--del 刪除服務(wù)
--list 查看各服務(wù)啟動(dòng)狀態(tài)
比如我們?cè)O(shè)置自啟動(dòng)mysql:
#將mysql啟動(dòng)腳本放入所有腳本運(yùn)行目錄/etc/rc.d/init.d中cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld#改變權(quán)限chown root.root /etc/rc.d/init.d/mysqld#所有用戶都可以執(zhí)行,單只有root可以修改chmod 755 /etc/rc.d/init.d/mysqld#將mysqld 放入linux啟動(dòng)管理體系中chkconfig --add mysqld#查看全部服務(wù)在各運(yùn)行級(jí)狀態(tài)chkconfig --list mysqld#只要運(yùn)行級(jí)別3啟動(dòng),其他都關(guān)閉chkconfig --levels 245 mysqld off
例如:我們把httpd的腳本寫(xiě)好后放進(jìn)/etc/rc.d/init.d/目錄,使用
chkconfig --add httpdchkconfig httpd on
命令即設(shè)置好了開(kāi)機(jī)啟動(dòng)。
3、把啟動(dòng)程序的命令添加到/etc/rc.d/rc.sysinit 文件中
腳本/etc/rc.d/rc.sysinit,完成系統(tǒng)服務(wù)程序啟動(dòng),如系統(tǒng)環(huán)境變量設(shè)置、設(shè)置系統(tǒng)時(shí)鐘、加載字體、檢查加載文件系統(tǒng)、生成系統(tǒng)啟動(dòng)信息日志文件等
比如我們?cè)O(shè)置自啟動(dòng)apache:
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選