您可以通過點擊 右下角 的按鈕 來對文章內容作出評價, 也可以通過左下方的 關注按鈕 來關注我的博客的最新動態。
如果文章內容對您有幫助, 不要忘記點擊右下角的 推薦按鈕 來支持一下哦
如果您對文章內容有任何疑問, 可以通過評論或發郵件的方式聯系我: 501395377@qq.com / lzp501395377@gmail.com
如果需要轉載,請注明出處,謝謝!!
本篇隨筆將主要講解Linux系統的服務基礎,從本篇隨筆開始,后續的Linux系列隨筆將主要記錄常用的各種服務的配置,包括DNS、WWW、Mail等等各種服務的配置。。。
一、系統服務的基本概念
服務,其實就是運行在操作系統后台的一個或者多個應用程序,為計算機系統或用戶提供某項特定的服務。
在我們的windows操作系統中,其在后台也運行了許許多多的服務。例如我們裝的殺毒軟件,其在后台運行了許多我們看不見的服務程序,通過這些服務來為用戶或者計算機系統來提高特定的功能。
服務通常是不中斷運行的,隨時准備接受請求,從而提供某項服務。例如我們日常使用的網頁服務,其就是由一個運行在所訪問網站的服務器上的httpd服務提供的服務,我們通過在瀏覽器輸入需要訪問網站的域名,服務器端的httpd服務就會隨時的接收我們發送過來的請求,並響應回給我們的用戶。
我們Linux系統絕大多數服務都是網絡服務,例如郵件服務、FTP服務、httpd服務等等,網絡服務可以使為其他用戶、其他計算機提供特定的服務。
二、System V
上面粗略的講解了一些系統服務的概念,自己感覺寫的一般,總的來說,Linux系統通常作為服務器端的操作系統來用的,所以Linux系統提供了許許多的的服務,有些服務需要我們自己來進行配置,這些服務的目的就是為了給我們的計算機、用戶提供某項特定的功能。那么對於各種不同的服務,Linux系統是怎么樣來統一進行管理的呢?
在Linux操作系統中,Linux對於服務的管理體系是沿用了System V的服務管理體系,System V原來是早期AT&T的一個操作系統。
對於Linux系統,System V提供了運行級別的概念,還記得之前一直提到過的Linux的啟動運行級別嗎?沒錯,System V一共提供了7種運行級別
0 關機
1 單用戶模式
2 不帶網絡的多用戶模式
3 帶網絡的多用戶模式,純文本界面
4 未使用
5 帶網絡的多用戶模式,圖形界面
6 重啟
對於我們來說,通常使用的是級別3和級別5,每個級別下都有對應的啟動、不啟動的服務,比如單用戶模式下,所有的服務都是不啟動,這些都是通過System V這個服務管理體系來決定的
System V定義了init為系統啟動的第一個進程,進程PID=1,這個進程的目的就是去查看 /etc/inittab 中的系統啟動級別從而來啟動對應的服務
對於不同的服務,因為其提供該服務的廠家不同,所以這些的服務的啟動、關閉機制通常不同,在Linux系統中,為了方便的管理這些服務,每個服務的啟動、結束、重啟等操作都由一個System V腳本來進行控制,擁有固定的格式。
對於Linux系統上的服務,這些服務的System V腳本文件都是存放在 /etc/rc.d/init.d 這個目錄下
[root@xiaoluo ~]# cd /etc/rc.d/init.d/ [root@xiaoluo init.d]# ls abrt-ccpp firstboot messagebus quota_nld snmptrapd abrtd functions mysqld rdisc spice-vdagentd abrt-oops haldaemon netconsole restorecond sshd acpid halt netfs rngd sssd atd htcacheclean network rpcbind sysstat auditd httpd NetworkManager rpcgssd udev-post autofs ip6tables nfs rpcidmapd vboxadd blk-availability iptables nfslock rpcsvcgssd vboxadd-service bluetooth irqbalance ntpd rsyslog vboxadd-x11 certmonger kdump ntpdate sandbox vncserver cpuspeed killall oddjobd saslauthd wdaemon crond lvm2-lvmetad portreserve single winbind cups lvm2-monitor postfix smartd wpa_supplicant dnsmasq mdmonitor psacct snmpd ypbind
我們看到在這個目錄下,存在了許多純文本文件,這些文件都是系統每一個服務的System V的腳本文件,對於該腳本文件,我們要啟動什么服務,都是通過這些腳本文件來啟動的,我們也可以通過編寫System V腳本文件來手工創建一個我們自己的由System V來控制的服務。
對於Linux的所有的這些服務,我們通過 service 這個命令來進行統一的管理
命令 service 可以調用指定服務的System V腳本,並執行指定的動作
service 服務名 [start | stop | restart | status]
例如我們這里需要啟動 httpd 這個服務,可以使用 service httpd start 這個命令
[root@xiaoluo init.d]# service httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for xiaoluo httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ]
我們也可以通過 service httpd status 來查看當前服務的啟動情況
[root@xiaoluo init.d]# service httpd status httpd (pid 6589) is running.
如果我們要重啟該服務,或者關閉服務可以分別使用 service httpd restart 、service httpd stop命令
[root@xiaoluo init.d]# service httpd restart Stopping httpd: [ OK ] Starting httpd: httpd: apr_sockaddr_info_get() failed for xiaoluo httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ] [root@xiaoluo init.d]# service httpd stop Stopping httpd: [ OK ]
對於Linux系統的這些服務,我們都是通過 service 這個命令去調用該服務對應的System V腳本,並執行其指定的動作
剛才我們也說到了,System V定義了運行級別的概念,每個運行級別對應有啟動、不啟動的服務,在 /etc/rc.d 這個目錄下,除了我們剛才的 init.d 這個目錄,我們還發現還有其它的一些目錄,諸如 rc0.d、rc1.d等
[root@xiaoluo rc.d]# ll total 60 drwxr-xr-x. 2 root root 4096 May 27 22:57 init.d -rwxr-xr-x. 1 root root 2617 Feb 22 19:18 rc drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc0.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc1.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc2.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc3.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc4.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc5.d drwxr-xr-x. 2 root root 4096 Jun 1 14:32 rc6.d -rwxr-xr-x. 1 root root 220 Feb 22 19:18 rc.local -rwxr-xr-x. 1 root root 19472 Feb 22 19:18 rc.sysinit
這些 rc0.d ,rc3.d這些目錄就分別對應了系統的7中啟動級別,每個目錄里面都存放了許多的文件,每個文件對應着一個特定的服務,並標志有是否開機啟動以及啟動順序,例如我們進入到 rc5.d 這個目錄
[root@xiaoluo rc.d]# cd rc5.d/ [root@xiaoluo rc5.d]# ls -l total 0 lrwxrwxrwx. 1 root root 16 May 14 01:26 K01smartd -> ../init.d/smartd lrwxrwxrwx. 1 root root 17 May 14 01:21 K02oddjobd -> ../init.d/oddjobd lrwxrwxrwx. 1 root root 17 May 14 01:28 K05wdaemon -> ../init.d/wdaemon lrwxrwxrwx. 1 root root 16 May 14 01:26 K10psacct -> ../init.d/psacct lrwxrwxrwx. 1 root root 19 May 14 01:21 K10saslauthd -> ../init.d/saslauthd lrwxrwxrwx. 1 root root 22 May 14 01:21 K15htcacheclean -> ../init.d/htcacheclean lrwxrwxrwx. 1 root root 15 Jun 1 14:32 K15httpd -> ../init.d/httpd lrwxrwxrwx. 1 root root 19 May 27 22:57 K35vncserver -> ../init.d/vncserver lrwxrwxrwx. 1 root root 17 May 14 01:21 K50dnsmasq -> ../init.d/dnsmasq lrwxrwxrwx. 1 root root 20 May 14 01:19 K50netconsole -> ../init.d/netconsole lrwxrwxrwx. 1 root root 15 May 14 01:21 K50snmpd -> ../init.d/snmpd lrwxrwxrwx. 1 root root 19 May 14 01:21 K50snmptrapd -> ../init.d/snmptrapd lrwxrwxrwx. 1 root root 13 May 14 01:19 K60nfs -> ../init.d/nfs lrwxrwxrwx. 1 root root 20 May 14 01:19 K69rpcsvcgssd -> ../init.d/rpcsvcgssd lrwxrwxrwx. 1 root root 17 May 14 01:30 K73winbind -> ../init.d/winbind lrwxrwxrwx. 1 root root 14 May 14 01:35 K74ntpd -> ../init.d/ntpd lrwxrwxrwx. 1 root root 17 May 14 01:21 K75ntpdate -> ../init.d/ntpdate lrwxrwxrwx. 1 root root 19 May 14 01:26 K75quota_nld -> ../init.d/quota_nld lrwxrwxrwx. 1 root root 16 May 14 01:30 K76ypbind -> ../init.d/ypbind lrwxrwxrwx. 1 root root 15 May 14 01:35 K80kdump -> ../init.d/kdump lrwxrwxrwx. 1 root root 24 Jun 1 14:32 K84wpa_supplicant -> ../init.d/wpa_supplicant lrwxrwxrwx. 1 root root 21 May 14 01:19 K87restorecond -> ../init.d/restorecond lrwxrwxrwx. 1 root root 14 Jun 1 14:32 K88sssd -> ../init.d/sssd lrwxrwxrwx. 1 root root 15 May 14 01:19 K89rdisc -> ../init.d/rdisc lrwxrwxrwx. 1 root root 19 May 14 01:35 K95firstboot -> ../init.d/firstboot lrwxrwxrwx. 1 root root 14 May 14 01:26 K99rngd -> ../init.d/rngd lrwxrwxrwx. 1 root root 17 May 14 01:24 S01sysstat -> ../init.d/sysstat lrwxrwxrwx. 1 root root 22 May 14 01:25 S02lvm2-monitor -> ../init.d/lvm2-monitor lrwxrwxrwx. 1 root root 19 May 14 01:22 S08ip6tables -> ../init.d/ip6tables lrwxrwxrwx. 1 root root 18 May 14 01:19 S08iptables -> ../init.d/iptables lrwxrwxrwx. 1 root root 17 May 14 01:19 S10network -> ../init.d/network lrwxrwxrwx. 1 root root 16 May 31 11:27 S11auditd -> ../init.d/auditd lrwxrwxrwx. 1 root root 21 May 14 01:13 S11portreserve -> ../init.d/portreserve lrwxrwxrwx. 1 root root 17 May 14 01:21 S12rsyslog -> ../init.d/rsyslog lrwxrwxrwx. 1 root root 18 May 14 01:26 S13cpuspeed -> ../init.d/cpuspeed lrwxrwxrwx. 1 root root 20 May 14 01:26 S13irqbalance -> ../init.d/irqbalance lrwxrwxrwx. 1 root root 17 May 14 01:14 S13rpcbind -> ../init.d/rpcbind lrwxrwxrwx. 1 root root 19 May 14 01:19 S15mdmonitor -> ../init.d/mdmonitor lrwxrwxrwx. 1 root root 20 May 14 01:12 S22messagebus -> ../init.d/messagebus lrwxrwxrwx. 1 root root 24 May 26 14:01 S23NetworkManager -> ../init.d/NetworkManager lrwxrwxrwx. 1 root root 17 Jun 1 14:32 S24nfslock -> ../init.d/nfslock lrwxrwxrwx. 1 root root 17 Jun 1 14:32 S24rpcgssd -> ../init.d/rpcgssd lrwxrwxrwx. 1 root root 19 Jun 1 14:32 S24rpcidmapd -> ../init.d/rpcidmapd lrwxrwxrwx. 1 root root 26 May 14 01:25 S25blk-availability -> ../init.d/blk-availability lrwxrwxrwx. 1 root root 14 May 14 01:19 S25cups -> ../init.d/cups lrwxrwxrwx. 1 root root 15 May 14 01:19 S25netfs -> ../init.d/netfs lrwxrwxrwx. 1 root root 15 May 14 01:26 S26acpid -> ../init.d/acpid lrwxrwxrwx. 1 root root 19 May 14 01:20 S26haldaemon -> ../init.d/haldaemon lrwxrwxrwx. 1 root root 19 May 14 01:19 S26udev-post -> ../init.d/udev-post lrwxrwxrwx. 1 root root 16 May 14 01:22 S28autofs -> ../init.d/autofs lrwxrwxrwx. 1 root root 17 May 14 02:15 S30vboxadd -> ../init.d/vboxadd lrwxrwxrwx. 1 root root 21 May 14 02:16 S30vboxadd-x11 -> ../init.d/vboxadd-x11 lrwxrwxrwx. 1 root root 25 May 14 02:16 S35vboxadd-service -> ../init.d/vboxadd-service lrwxrwxrwx. 1 root root 19 May 14 01:22 S50bluetooth -> ../init.d/bluetooth lrwxrwxrwx. 1 root root 14 May 14 01:26 S55sshd -> ../init.d/sshd lrwxrwxrwx. 1 root root 16 May 14 14:29 S64mysqld -> ../init.d/mysqld lrwxrwxrwx. 1 root root 24 May 14 01:26 S70spice-vdagentd -> ../init.d/spice-vdagentd lrwxrwxrwx. 1 root root 17 May 14 01:21 S80postfix -> ../init.d/postfix lrwxrwxrwx. 1 root root 19 May 14 01:16 S82abrt-ccpp -> ../init.d/abrt-ccpp lrwxrwxrwx. 1 root root 15 May 14 01:16 S82abrtd -> ../init.d/abrtd lrwxrwxrwx. 1 root root 15 May 14 01:22 S90crond -> ../init.d/crond lrwxrwxrwx. 1 root root 13 May 14 01:14 S95atd -> ../init.d/atd lrwxrwxrwx. 1 root root 20 May 14 01:21 S99certmonger -> ../init.d/certmonger lrwxrwxrwx. 1 root root 11 May 14 01:19 S99local -> ../rc.local
我們發現,在這些目錄里面,存放的都是鏈接文件,不過這每一個鏈接文件的名字都有着嚴格的規定。每一個鏈接文件都由3部分組成
K15httpd -> ../init.d/httpd S55sshd -> ../init.d/sshd
①第一個部分是第一個字母K或者S,表示該服務是不是是不是開機自動啟動,K表示開機不啟動,S表示開機就啟動
②第二個部分是一個數字,這個數字代表的是該服務的啟動順序,服務啟動的順序非常的重要,例如我們的網絡服務需要在郵件服務之前啟動
③第三個部分就是對應服務的名字,該鏈接文件其實都是指向的是 init.d 這個目錄下的System V腳本文件
我們如果希望某服務開機就啟動,可以通過修改 rc5.d 目錄下的鏈接文件,不過這樣做很麻煩,Linux系統提供了一個 chkconfig 命令可以來設置服務是否開機啟動
例如我們通過 chkconfig --list 命令來查看所有服務的開機啟動情況
[root@xiaoluo rc5.d]# chkconfig --list NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off bluetooth 0:off 1:off 2:off 3:on 4:on 5:on 6:off certmonger 0:off 1:off 2:off 3:on 4:on 5:on 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off dnsmasq 0:off 1:off 2:off 3:off 4:off 5:off 6:off firstboot 0:off 1:off 2:off 3:off 4:off 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off kdump 0:off 1:off 2:off 3:off 4:off 5:off 6:off lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off oddjobd 0:off 1:off 2:off 3:off 4:off 5:off 6:off portreserve 0:off 1:off 2:on 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off quota_nld 0:off 1:off 2:off 3:off 4:off 5:off 6:off rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off rngd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcsvcgssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off smartd 0:off 1:off 2:off 3:off 4:off 5:off 6:off snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off spice-vdagentd 0:off 1:off 2:off 3:off 4:off 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off vboxadd 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxadd-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxadd-x11 0:off 1:off 2:off 3:on 4:off 5:on 6:off vncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off wdaemon 0:off 1:off 2:off 3:off 4:off 5:off 6:off winbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off wpa_supplicant 0:off 1:off 2:off 3:off 4:off 5:off 6:off ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off
比如我們需要設置 httpd 服務開啟自動啟動,可以使用 chkconfig httpd on 命令即可
[root@xiaoluo rc5.d]# chkconfig httpd on [root@xiaoluo rc5.d]# chkconfig --list | grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果需要設置成開機不啟動,則使用 chkconfig httpd off 命令即可
[root@xiaoluo rc5.d]# chkconfig httpd off [root@xiaoluo rc5.d]# chkconfig --list | grep httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
三、xinetd
其實對於上面通過 System V來管理的一些服務都屬於Linux系統的常駐運行的服務,其實在Linux系統中還有許多不常駐的一些服務,例如 telnet、rsync服務,這些服務則是通過 xinetd 這個服務來進行管理的。
xinetd 控制的就是那些不常駐的服務,功能較為簡單的服務
xinetd其實自己本身就是作為一個系統的常駐的服務運行在后台,而xinetd所控制的服務在沒有連接請求的時候是不運行的,所有xinetd控制的服務的連接請求都會提交給xinetd來進行代理
xinetd在收到一個請求后,會根據請求的協議及服務啟動相應的服務進程,進程處理完后請求就會結束
xinetd本身就是一個系統服務,通過 System V來對其進行管理,在CentOS6/RHEL6中,xinetd服務默認是沒有安裝的,我們若要使用該服務,首先需要安裝它
[root@xiaoluo ~]# yum install xinetd Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirror01.idc.hinet.net * extras: mirror01.idc.hinet.net * updates: mirror01.idc.hinet.net base | 3.7 kB 00:00 extras | 3.5 kB 00:00 updates | 3.4 kB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package xinetd.x86_64 2:2.3.14-38.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: xinetd x86_64 2:2.3.14-38.el6 base 121 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 121 k Installed size: 259 k Is this ok [y/N]: y Downloading Packages: xinetd-2.3.14-38.el6.x86_64.rpm | 121 kB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 2:xinetd-2.3.14-38.el6.x86_64 1/1 Verifying : 2:xinetd-2.3.14-38.el6.x86_64 1/1 Installed: xinetd.x86_64 2:2.3.14-38.el6 Complete!
在我們安裝好我們的xinetd服務以后,我們這時再通過 chkconfig --list 命令來查看所有的服務啟動設置
[root@xiaoluo ~]# chkconfig --list NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off bluetooth 0:off 1:off 2:off 3:on 4:on 5:on 6:off certmonger 0:off 1:off 2:off 3:on 4:on 5:on 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off dnsmasq 0:off 1:off 2:off 3:off 4:off 5:off 6:off firstboot 0:off 1:off 2:off 3:off 4:off 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off kdump 0:off 1:off 2:off 3:off 4:off 5:off 6:off lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off oddjobd 0:off 1:off 2:off 3:off 4:off 5:off 6:off portreserve 0:off 1:off 2:on 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off quota_nld 0:off 1:off 2:off 3:off 4:off 5:off 6:off rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off rngd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcsvcgssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off smartd 0:off 1:off 2:off 3:off 4:off 5:off 6:off snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off spice-vdagentd 0:off 1:off 2:off 3:off 4:off 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sssd 0:off 1:off 2:off 3:off 4:off 5:off 6:off sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off vboxadd 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxadd-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxadd-x11 0:off 1:off 2:off 3:on 4:off 5:on 6:off vncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off wdaemon 0:off 1:off 2:off 3:off 4:off 5:off 6:off winbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off wpa_supplicant 0:off 1:off 2:off 3:off 4:off 5:off 6:off xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off xinetd based services: chargen-dgram: off chargen-stream: off daytime-dgram: off daytime-stream: off discard-dgram: off discard-stream: off echo-dgram: off echo-stream: off rsync: off tcpmux-server: off time-dgram: off time-stream: off
我們看到,在安裝了xinetd服務以后,其下面出現了一些其他的服務選項,例如rsync,chargen-dgram等這些服務,這些服務都是系統的一些不常駐服務,都是通過xinetd這個服務來對其進行管理的
xinetd服務的配置文件是 /etc/xinetd.conf
[root@xiaoluo ~]# cat /etc/xinetd.conf # # This is the master xinetd configuration file. Settings in the # default section will be inherited by all service configurations # unless explicitly overridden in the service configuration. See # xinetd.conf in the man pages for a more detailed explanation of # these attributes. defaults { # The next two items are intended to be a quick access place to # temporarily enable or disable services. # # enabled = # disabled = # Define general logging characteristics. log_type = SYSLOG daemon info log_on_failure = HOST log_on_success = PID HOST DURATION EXIT # Define access restriction defaults # # no_access = # only_from = # max_load = 0 cps = 50 10 instances = 50 per_source = 10 # Address and networking defaults # # bind = # mdns = yes v6only = no # setup environmental attributes # # passenv = groups = yes umask = 002 # Generally, banners are not used. This sets up their global defaults # # banner = # banner_fail = # banner_success = } includedir /etc/xinetd.d
對於由xinetd控制的那些不常駐服務,它們的配置文件是存放在 /etc/xinetd.d/ 這個目錄下與該服務名字相同的文件
[root@xiaoluo ~]# cd /etc/xinetd.d/ [root@xiaoluo xinetd.d]# ll total 48 -rw-------. 1 root root 1157 Feb 22 11:03 chargen-dgram -rw-------. 1 root root 1159 Feb 22 11:03 chargen-stream -rw-------. 1 root root 1157 Feb 22 11:03 daytime-dgram -rw-------. 1 root root 1159 Feb 22 11:03 daytime-stream -rw-------. 1 root root 1157 Feb 22 11:03 discard-dgram -rw-------. 1 root root 1159 Feb 22 11:03 discard-stream -rw-------. 1 root root 1148 Feb 22 11:03 echo-dgram -rw-------. 1 root root 1150 Feb 22 11:03 echo-stream -rw-r--r--. 1 root root 332 Apr 3 2012 rsync -rw-------. 1 root root 1212 Feb 22 11:03 tcpmux-server -rw-------. 1 root root 1149 Feb 22 11:03 time-dgram -rw-------. 1 root root 1150 Feb 22 11:03 time-stream
同樣這些配置文件的配置也有固定的格式,例如rsync這個服務的配置文件信息為:
[root@xiaoluo xinetd.d]# cat rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = yes flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
本篇隨筆主要講解了Linux系統服務的基礎知識、System V與Xinetd的概念,以及通過 servcie 命令來啟動某一服務,通過 chkconfig 命令來設置服務是否開機啟動