系统开启的服务
观察系统启动的服务
范例一:找出目前系统开启的『网络服务』有哪些?
[root@www ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 www.vbird.tsai:2208 *:* LISTEN 4575/hpiod
tcp 0 0 *:737 *:* LISTEN 4371/rpc.statd
tcp 0 0 *:sunrpc *:* LISTEN 4336/portmap
tcp 0 0 www.vbird.tsai:ipp *:* LISTEN 4606/cupsd
tcp 0 0 www.vbird.tsai:smtp *:* LISTEN 4638/sendmail: acce
tcp 0 0 *:ssh *:* LISTEN 4595/sshd
udp 0 0 *:filenet-tms *:* 4755/avahi-daemon:
....(底下省略)....
# 看一下上头, Local Address 的地方会出现主机名与服务名称的,要记得的是,
# 可以加上 -n 来显示 port number ,而服务名称与 port 对应则在 /etc/services
范例二:找出所有的有监听网络的服务 (包含 socket 状态):
[root@www ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 4575/hpiod
....(中间省略)....
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
....(中间省略)....
unix 2 [ ACC ] STREAM LISTENING 10624 4701/xfs /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 12824 5015/Xorg /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 12770 4932/gdm-binary /tmp/.gdm_socket
....(以下省略)....
# 仔细的瞧一瞧啊,除了原有的网络监听 port 之外,还会有 socket 显示在上面,
# 我们可以清楚的知道有哪些服务被启动呢!
范例三:观察所有的服务状态
[root@www ~]# service --status-all
# 这个命令有趣喔!本章之前有谈过这命令,自行查询啰!
配置启动后立即启动服务的方法: chkconfig, ntsysv
Linux 主机是怎么启动的:
- 打开计算机电源,开始读取 BIOS 并进行主机的自我测试;
- 透过 BIOS 取得第一个可启动装置,读取主要启动区 (MBR) 取得启动管理程序;
- 透过启动管理程序的配置,取得 kernel 并加载内存且侦测系统硬件;
- 核心主动呼叫 init 程序;
- init 程序开始运行系统初始化 (/etc/rc.d/rc.sysinit)
- 依据 init 的配置进行 daemon start (/etc/rc.d/rc[0-6].d/*)
- 加载本机配置 (/etc/rc.d/rc.local)
chkconfig: 管理系统服务默认启动启动与否
[root@www ~]# chkconfig --list [服务名称]
[root@www ~]# chkconfig [--level [0123456]] [服务名称] [on|off]
选项与参数:
--list :仅将目前的各项服务状态栏出来
--level:配置某个服务在该 level 下启动 (on) 或关闭 (off)
范例一:列出目前系统上面所有被 chkconfig 管理的服务
[root@www ~]# chkconfig --list |more
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
....(中间省略)....
yum-updatesd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
xinetd based services: <==底下为 super daemon 所管理的服务
chargen-dgram: off
chargen-stream: off
....(底下省略)....
# 你可以发现上面的表格有分为两个区块,一个具有 1, 2, 3 等数字,一个则被 xinetd
# 管理。没错!从这里我们就能够发现服务有 stand alone 与 super daemon 之分。
范例二:显示出目前在 run level 3 为启动的服务
[root@www ~]# chkconfig --list | grep '3:on'
范例三:让 atd 这个服务在 run level 为 3, 4, 5 时启动:
[root@www ~]# chkconfig --level 345 atd on
范例五:查阅 rsync 是否启动,若要将其关闭该如何处理?
[root@www ~]# /etc/init.d/rsync status
-bash: /etc/init.d/rsync: No such file or directory
# rsync 是 super daemon 管理的,所以当然不可以使用 stand alone 的启动方式来观察
[root@www ~]# netstat -tlup | grep rsync
tcp 0 0 192.168.201.110:rsync *:* LISTEN 4618/xinetd
tcp 0 0 www.vbird.tsai:rsync *:* LISTEN 4618/xinetd
[root@www ~]# chkconfig --list rsync
rsync on <==默认启动呢!将它处理成默认不启动吧
[root@www ~]# chkconfig rsync off; chkconfig --list rsync
rsync off <==看吧!关闭了喔!现在来处理一下 super daemon 的东东!
[root@www ~]# /etc/init.d/xinetd restart; netstat -tlup | grep rsync