Linux啟動流程和腳本服務-6
授課筆記:
-----------------------------------
linux系統啟動流程:
一.初始化階段:
1.grub引導界面
2.識別硬件
3.初始化驅動
二.加載/etc/rc.d/rc.sysinit系統初始化腳本
4.進入歡迎頁面
5.設置時鐘
6.設置主機名
7.掛載文件系統
8.掛載光驅
9.進入3級別
10.啟動虛擬內存
11.設置磁盤陣列
三.加載/etc/rc.d/rc進程管理腳本
12.設置防火墻
13.檢測硬件變化
14.啟動網絡服務
15.啟動3級別下允許啟動的進程(比如sshd)
四.加載/etc/rc.d/rc.local自定義腳本
五.進入登錄界面
如何設置服務腳本在某個級別下開啟或關閉:
1.查看sshd服務在所有級別下的開啟關閉狀態
chkconfig --list sshd
2.sshd服務在35級別下開啟
chkconfig --level 3 sshd on
3.sshd服務在35級別下關閉
chkconfig --level 3 sshd off
4.快速設置sshd服務在2345級別下開啟
chkconfig sshd on
5.快速設置sshd服務在2345級別下關閉
chkconfig sshd off
實例:安裝apache應用程序,然後讓apache服務腳本在3級別可以開機啟動?
1.yum -y install httpd
2.chkconfig httpd on
源代碼安裝三步曲:
1.生成配置文件
./configure --prefix=/usr/local/apache
2.編譯
make
3.安裝
make install
源代碼程序:
1.服務腳本
/usr/local/apache/bin/apachectl
2.如何開啟或關閉
/usr/local/apache/bin/apachectl start
/usr/local/apache/bin/apachectl restart
/usr/local/apache/bin/apachectl stop
3.如何開機啟動
vi /etc/rc.d/rc.local
/usr/local/apache/bin/apachectl start
自定義服務腳本:
#!/bin/bash
#mytest
case $1 in
start)
echo ‘mytest starting!!!‘
sleep 1
;;
stop)
echo ‘mytest stoping!!!‘
sleep 1
;;
restart)
echo ‘mytest restarting!!!‘
sleep 1
;;
*)
echo ‘please input start|stop|restart!!!!‘
;;
esac
把服務腳本改選成標準rpm腳本:
# chkconfig: 2345 90 20
# description: Mytest server daemon
通過service把自定義腳本進行開啟和關閉:
service mytest start|stop|restart
通過chkconfig把自定義腳本設置開機啟動:
chkconfig mytest on
chkconfig mytest off
Linux啟動流程和腳本服務-6