歡迎訪問我的個(gè)人博客網(wǎng)站:http://www.yanmin99.com/
一、開機(jī)啟動(dòng)介紹
- 在CentOS或者RedHat其他系統(tǒng)下焦影,如果是后面安裝的服務(wù)鳞绕,如httpd饥努、mysqld氧急、postfix等颗胡,安裝后系統(tǒng)默認(rèn)不會(huì)自動(dòng)啟動(dòng)的。就算手動(dòng)執(zhí)行 /etc/init.d/mysqld start 啟動(dòng)了服務(wù)吩坝,只要服務(wù)器重啟后毒姨,系統(tǒng)仍然不會(huì)自動(dòng)啟動(dòng)服務(wù)。
二钉寝、CentOS設(shè)置自動(dòng)啟動(dòng)方式
1弧呐、CentOS7之前
- A、利用 chkconfig 來配置啟動(dòng)級(jí)別
-
chkconfig介紹
chkconfig –-add xxx //把服務(wù)添加到chkconfig列表 chkconfig --del xxx //把服務(wù)從chkconfig列表中刪除 chkconfig xxx on //開啟開機(jī)自動(dòng)啟動(dòng) chkconfig xxx off //關(guān)閉開機(jī)自動(dòng)啟動(dòng) chkconfig --list //查看所有chklist中服務(wù) chkconfig --list xxx 查看指定服務(wù)
-
chkconfig實(shí)例
//把nginx添加到chkconfig中 chkconfig --add nginx //查看nginx是否在chkconfig中(添加進(jìn)去默認(rèn)設(shè)置自動(dòng)啟動(dòng)) chkconfig --list nginx //2~5都是on嵌纲,就表明會(huì)自動(dòng)啟動(dòng)了 nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off //開啟開機(jī)啟動(dòng) chkconfig nginx on //關(guān)閉開機(jī)啟動(dòng) chkconfig nginx off chkconfig --del nginx
-
- B泉懦、修改 /etc/rc.d/rc.local
/etc/rc.d/init.d/nginx start
CentOS7
-
方案一
- 賦予腳本可執(zhí)行權(quán)限(/opt/script/autostart.sh是你的腳本路徑)
chmod +x /opt/script/autostart.sh
- 打開/etc/rc.d/rc/local文件,在末尾增加如下內(nèi)容
/opt/script/autostart.sh
- 在centos7中疹瘦,/etc/rc.d/rc.local的權(quán)限被降低了,所以需要執(zhí)行如下命令賦予其可執(zhí)行權(quán)限
chmod +x /etc/rc.d/rc.local
- 賦予腳本可執(zhí)行權(quán)限(/opt/script/autostart.sh是你的腳本路徑)
-
方案二
- 將腳本移動(dòng)到/etc/rc.d/init.d目錄下
mv /opt/script/autostart.sh /etc/rc.d/init.d
- 增加腳本的可執(zhí)行權(quán)限
chmod +x /etc/rc.d/init.d/autostart.sh
- 添加腳本到開機(jī)自動(dòng)啟動(dòng)項(xiàng)目中
cd /etc/rc.d/init.d chkconfig --add autostart.sh chkconfig autostart.sh on
- 將腳本移動(dòng)到/etc/rc.d/init.d目錄下