码迷,mamicode.com
首页 > 系统相关 > 详细

Linux服务的控制和管理原理

时间:2016-11-14 16:11:17      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:linux服务的控制和管理原理

系统服务管理——独立服务,临时服务

一、独立服务

1.独立服务特点:系统相应时间快,持续占用系统资源

2.独立服务由/etc/rc.d/init.d/* 各种服务脚本控制。

3.独立服务控制基本方法:一是通过脚本控制:/etc/init.d/服务名称 +控制参数  初学者不太好记。二是通过service管理工具 :service +服务+控制参数  

4、控制参数主要有:status 查看状态,start 启动 ,stop关闭 ,reload重新加载 ,restart重启 等

以下是演示例子:


[root@dragon ~]# ls /etc/rc.d/init.d/              ----------查看/etc/rc.d/init.d/下有哪些服务

abrt-ccpp                   cpuspeed      iptables      NetworkManager  quota_nld    saslauthd       wdaemon

abrtd                       crond         irqbalance    nfs             rawdevices   single          winbind

abrt-oops                   cups          kdump         nfslock         rdisc        smartd          wpa_supplicant

acpid                       dnsmasq       killall       nmb             restorecond  smb             xinetd

apacheds-2.0.0_M23-default  firstboot     lvm2-lvmetad  ntpd            rngd         snmpd           ypbind

atd                         functions     lvm2-monitor  ntpdate         rpcbind      snmptrapd

auditd                      haldaemon     mdmonitor     oddjobd         rpcgssd      spice-vdagentd

autofs                      halt          messagebus    portreserve     rpcidmapd    sshd

blk-availability            htcacheclean  netconsole    postfix         rpcsvcgssd   sssd

bluetooth                   httpd         netfs         pppoe-server    rsyslog      sysstat

certmonger                  ip6tables     network       psacct          sandbox      udev-post

[root@dragon ~]# ls /etc/rc.d/init.d/ |wc -l          -----------------总共有多少条服务。

71 

[root@dragon ~]# /etc/init.d/iptables status   ----------------查看防火墙的启动状态

iptables: Firewall is not running.

[root@dragon ~]# service iptables reload    ------重新加载服务

[root@dragon ~]# 

[root@dragon ~]# service iptables start  ------将防火墙打开

iptables: Applying firewall rules:                         [确定]

[root@dragon ~]# service httpd stop   ------------关闭http服务

停止 httpd:                                               [确定]

[root@dragon ~]# service httpd restart   ------重启http 服务

停止 httpd:                                               [确定]

启动 httpd:                                               [确定]

二、临时服务

1 临时服务响应时间慢,但比较节约系统资源,只有需要时开启。

2.临时服务需要一个超级管理器Xinet服务进行管理,xinet用于监听各种临时服务的端口号,只有需要时才将响应端口号进行打开。有一点像理发店的理发店经理,用于管理那些理发师,只有他安排哪个理发师这个理发师才去给顾客剪发。因此在管理临时服务之前需要安装xinet,一般用yum安装比较便捷。当然用rpm安装也是可以的。

3.临时服务是由/etc/xinet.d/*脚本进行管理的。

4.临时服务控制工具:chkconfig 

5.chkconfig工具用法(1)chkconfig  --list 用于列举当前的所有服务(包括独立服务和临时服务

                                     (2)chkconfig  +服务 +on| off  临时服务开启和关闭

以下是演示例子

[root@dragon ~]# chkconfig --list          ------ 用于列举当前的所有服务

NetworkManager  0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

abrt-ccpp       0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

abrtd           0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

acpid           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

atd             0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

auditd          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

autofs          0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

blk-availability        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

bluetooth       0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:关闭  6:关闭

certmonger      0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

cpuspeed        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

crond           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

基于 xinetd 的服务:

        chargen-dgram:  关闭

        chargen-stream: 关闭

        daytime-dgram:  关闭

        daytime-stream: 关闭

        discard-dgram:  关闭

        discard-stream: 关闭

        echo-dgram:     关闭

        echo-stream:    关闭

        rsync:          关闭

        tcpmux-server:  关闭

        time-dgram:     关闭

        time-stream:    关闭

[root@dragon ~]# chkconfig rsync on   -----开启rsync 服务

[root@dragon ~]# chkconfig rsync on   --关闭rsync服务

三、服务的自启动控制方法

1.chkconfig +服务+on|off    ----机器重启才生效,而且只能是当下运行级别生效。

可以查看当下的运行级别 :runlevel命令。

2.chkconfig  --level  运行级别号(0-6)on |off 可以指定哪些运行级别生效。

3.有时我们要同时控制多个服务的启动和控制怎么办,不可能一个一个服务去启动。因此我们Linux有个很好的工具:ntsysv管理工具--图形化管理工具,可以同时管理多个服务,按空格进行选择开启和关闭。用tab键进行切换选项。

以下是演示事例:

[root@dragon ~]# chkconfig --list   ---通过该命令查看crond各个运行级别下的开启情况

NetworkManager  0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

abrt-ccpp       0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

abrtd           0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

acpid           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

atd             0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

auditd          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

autofs          0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

blk-availability        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

bluetooth       0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:关闭  6:关闭

certmonger      0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

cpuspeed        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

crond           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭  --2345都是开启的

现在我们把234运行级别进行关闭,然后再查看

        time-stream:    关闭

[root@dragon ~]# chkconfig --level 234 crond off   --------关闭234这几个运行级别

[root@dragon ~]# chkconfig --list

NetworkManager  0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

abrt-ccpp       0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

abrtd           0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

acpid           0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

atd             0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

auditd          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

autofs          0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

blk-availability        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

bluetooth       0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:关闭  6:关闭

certmonger      0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

cpuspeed        0:关闭  1:启用  2:启用  3:启用  4:启用  5:启用  6:关闭

crond           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:启用  6:关闭   ---发现的确被关闭了

如果我们现在管理多个服务 那直接敲ntsysv命令

[root@dragon ~]# ntsysv


 Hat, Inc. 

                                              ┌────────────┤ 服务 ├────────────┐

                                              │                                │ 

                                              │ 您想自动启动哪些服务?         │ 

                                              │                                │ 

                                              │    [*] NetworkManager    ↑     │ 

                                              │    [*] abrt-ccpp             │ 

                                              │    [*] abrtd                 │ 

                                              │    [*] acpid                 │ 

                                              │    [*] atd                   │ 

                                              │    [*] auditd                 │ 

                                              │    [*] autofs                 │ 

                                              │    [*] blk-availability  ↓     │ 

                                              │                                │ 

                                              │    ┌──────┐       ┌──────┐     │ 

                                              │    │ 确定 │       │ 取消 │     │ 

                                              │    └──────┘       └──────┘     │ 

                                              │                                │ 

                                              │                                │ 

                                              └────────────────────────────────┘ 

                                                                                 

按 <F1> 可获取关于某项服务的详情。


最后以上就是服务控制的基本管理,如果这当中有些不足之处,希望各位博主能够给我指出来。大家一起进步。

本文出自 “Linux运维” 博客,请务必保留此出处http://dragon007.blog.51cto.com/7740555/1872590

Linux服务的控制和管理原理

标签:linux服务的控制和管理原理

原文地址:http://dragon007.blog.51cto.com/7740555/1872590

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!