1. 開機啟動設定檔
一般來說Linux會用不同的level開機,可以用
[plain] view plaincopyprint?
- #runlevel
#runlevel
來查看啟動並執行level。而關於level的配置,可以在 /etc/inittab中找到,如下:
[plain] view plaincopyprint?
- # Default runlevel. The runlevels used by RHS are:
- # 0 - halt (Do NOT set initdefault to this)
- # 1 - Single user mode
- # 2 - Multiuser, without NFS (The same as 3, if you do not have networking )
- # 3 - Full multiuser mode
- # 4 - unused
- # 5 - X11
- # 6 - reboot (Do NOT set initdefault to this)
- #
- id:5:initdefault:
# Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking ) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:5:initdefault:
從注釋的部分可以看到Linux系統啟動分為0~6一共7個層級,而此處預設啟動在第5個層級上,X11即為圖形案頭方式啟動
[plain] view plaincopyprint?
- [root@emma_test_server etc]# cd rc
- rc rc1.d/ rc3.d/ rc5.d/ rc.d/ rc.sysinit
- rc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local
[root@emma_test_server etc]# cd rcrc rc1.d/ rc3.d/ rc5.d/ rc.d/ rc.sysinitrc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local
在系統/etc目錄下,我們可以找到rc0.d ~ rc6.d 開機檔案夾,其中儲存的即為Linux在相應層級啟動時所調用的開機檔案,開啟rc5.d我們可以看到:
[plain] view plaincopyprint?
- [root@emma_test_server rc5.d]# ls -l
- total 296
- lrwxrwxrwx 1 root root 17 Aug 26 2011 K01dnsmasq -> ../init.d/dnsmasq
- lrwxrwxrwx 1 root root 24 Aug 26 2011 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
- lrwxrwxrwx 1 root root 24 Aug 26 2011 K02NetworkManager -> ../init.d/NetworkManager
- lrwxrwxrwx 1 root root 16 Aug 26 2011 K05conman -> ../init.d/conman
- lrwxrwxrwx 1 root root 19 Aug 26 2011 K05saslauthd -> ../init.d/saslauthd
- lrwxrwxrwx 1 root root 17 Aug 26 2011 K05wdaemon -> ../init.d/wdaemon
- lrwxrwxrwx 1 root root 19 Aug 26 2011 K10dc_server -> ../init.d/dc_server
- lrwxrwxrwx 1 root root 16 Aug 26 2011 K10psacct -> ../init.d/psacct
- lrwxrwxrwx 1 root root 19 Aug 26 2011 K12dc_client -> ../init.d/dc_client
- lrwxrwxrwx 1 root root 15 Aug 26 2011 K15httpd -> ../init.d/httpd
- lrwxrwxrwx 1 root root 14 Aug 26 2011 K24irda -> ../init.d/irda
- lrwxrwxrwx 1 root root 15 Aug 26 2011 K25squid -> ../init.d/squid
- lrwxrwxrwx 1 root root 19 Aug 26 2011 K35vncserver -> ../init.d/vncserver
- lrwxrwxrwx 1 root root 17 Aug 26 2011 K35winbind -> ../init.d/winbind
- lrwxrwxrwx 1 root root 20 Aug 26 2011 K50netconsole -> ../init.d/netconsole
- ..........
[root@emma_test_server rc5.d]# ls -ltotal 296lrwxrwxrwx 1 root root 17 Aug 26 2011 K01dnsmasq -> ../init.d/dnsmasqlrwxrwxrwx 1 root root 24 Aug 26 2011 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfdlrwxrwxrwx 1 root root 24 Aug 26 2011 K02NetworkManager -> ../init.d/NetworkManagerlrwxrwxrwx 1 root root 16 Aug 26 2011 K05conman -> ../init.d/conmanlrwxrwxrwx 1 root root 19 Aug 26 2011 K05saslauthd -> ../init.d/saslauthdlrwxrwxrwx 1 root root 17 Aug 26 2011 K05wdaemon -> ../init.d/wdaemonlrwxrwxrwx 1 root root 19 Aug 26 2011 K10dc_server -> ../init.d/dc_serverlrwxrwxrwx 1 root root 16 Aug 26 2011 K10psacct -> ../init.d/psacctlrwxrwxrwx 1 root root 19 Aug 26 2011 K12dc_client -> ../init.d/dc_clientlrwxrwxrwx 1 root root 15 Aug 26 2011 K15httpd -> ../init.d/httpdlrwxrwxrwx 1 root root 14 Aug 26 2011 K24irda -> ../init.d/irdalrwxrwxrwx 1 root root 15 Aug 26 2011 K25squid -> ../init.d/squidlrwxrwxrwx 1 root root 19 Aug 26 2011 K35vncserver -> ../init.d/vncserverlrwxrwxrwx 1 root root 17 Aug 26 2011 K35winbind -> ../init.d/winbindlrwxrwxrwx 1 root root 20 Aug 26 2011 K50netconsole -> ../init.d/netconsole..........
其中包含了大量的連結檔案,都是連結到/etc/init.d目錄下的開機檔案,這些檔案負責啟動相應的應用程式或者服務。
2. 使用者登入啟動:
(1)/etc/profile:此檔案為系統的每個使用者佈建環境資訊,當使用者第一次登入時,該檔案被執行. 並從/etc/profile.d目錄的設定檔中搜集shell的設定。
(2)/etc/bashrc: 為每一個運行bash shell的使用者執行此檔案.當bash shell被開啟時,該檔案被讀取。
(3) ~/.bash_profile: 每個使用者都可使用該檔案輸入專用於自己使用的shell資訊,當使用者登入時,該檔案僅僅執行一次!預設情況下,他設定一些環境變數,執行使用者的.bashrc檔案。
(4) ~/.bashrc: 該檔案包含專用於你的bash shell的bash資訊,當登入時以及每次開啟新的shell時,該該檔案被讀取。
(5)
~/.bash_logout:當每次退出系統(退出bash shell)時,執行該檔案.
另外,/etc/profile中設定的變數(全域)的可以作用於任何使用者,而~/.bashrc等中設定的變數(局部)只能繼承
/etc/profile中的變數,他們是"父子"關係。
(6)~/.bash_profile 是互動式、login 方式進入 bash 啟動並執行~/.bashrc 是互動式 non-login 方式進入 bash 啟動並執行通常二者設定大致相同,所以通常前者會調用後者。
轉自http://blog.csdn.net/lrenjundk/article/details/8187610