Linux系统服务基础

时间:2022-01-09 16:06:05

一、系统服务的基本概念

服务,其实就是运行在操作系统后台的一个或者多个应用程序,为计算机系统或用户提供某项特定的服务。

在我们的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 这个目录下

Linux系统服务基础
[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
Linux系统服务基础

我们看到在这个目录下,存在了许多纯文本文件,这些文件都是系统每一个服务的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命令

Linux系统服务基础
[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系统服务基础

对于Linux系统的这些服务,我们都是通过 service 这个命令去调用该服务对应的System V脚本,并执行其指定的动作

刚才我们也说到了,System V定义了运行级别的概念,每个运行级别对应有启动、不启动的服务,在 /etc/rc.d 这个目录下,除了我们刚才的 init.d 这个目录,我们还发现还有其它的一些目录,诸如 rc0.d、rc1.d等

Linux系统服务基础
[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
Linux系统服务基础

这些 rc0.d ,rc3.d这些目录就分别对应了系统的7中启动级别,每个目录里面都存放了许多的文件,每个文件对应着一个特定的服务,并标志有是否开机启动以及启动顺序,例如我们进入到 rc5.d 这个目录

Linux系统服务基础
[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
Linux系统服务基础

我们发现,在这些目录里面,存放的都是链接文件,不过这每一个链接文件的名字都有着严格的规定。每一个链接文件都由3部分组成

K15httpd -> ../init.d/httpd    S55sshd -> ../init.d/sshd
①第一个部分是第一个字母K或者S,表示该服务是不是是不是开机自动启动,K表示开机不启动,S表示开机就启动
②第二个部分是一个数字,这个数字代表的是该服务的启动顺序,服务启动的顺序非常的重要,例如我们的网络服务需要在邮件服务之前启动
③第三个部分就是对应服务的名字,该链接文件其实都是指向的是 init.d 这个目录下的System V脚本文件

我们如果希望某服务开机就启动,可以通过修改 rc5.d 目录下的链接文件,不过这样做很麻烦,Linux系统提供了一个chkconfig 命令可以来设置服务是否开机启动

例如我们通过 chkconfig --list 命令来查看所有服务的开机启动情况

Linux系统服务基础
[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
Linux系统服务基础

比如我们需要设置 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服务默认是没有安装的,我们若要使用该服务,首先需要安装它

Linux系统服务基础
[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
!
Linux系统服务基础

在我们安装好我们的xinetd服务以后,我们这时再通过 chkconfig --list 命令来查看所有的服务启动设置

Linux系统服务基础
[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
Linux系统服务基础

我们看到,在安装了xinetd服务以后,其下面出现了一些其他的服务选项,例如rsync,chargen-dgram等这些服务,这些服务都是系统的一些不常驻服务,都是通过xinetd这个服务来对其进行管理的

xinetd服务的配置文件是 /etc/xinetd.conf

Linux系统服务基础
[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
Linux系统服务基础

对于由xinetd控制的那些不常驻服务,它们的配置文件是存放在/etc/xinetd.d/ 这个目录下与该服务名字相同的文件

Linux系统服务基础
[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
Linux系统服务基础

同样这些配置文件的配置也有固定的格式,例如rsync这个服务的配置文件信息为:

Linux系统服务基础
[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系统服务基础

本篇随笔主要讲解了Linux系统服务的基础知识、System V与Xinetd的概念,以及通过 servcie 命令来启动某一服务,通过 chkconfig 命令来设置服务是否开机启动.