linu学习之路:chkconfig命令

chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

1、命令格式

  chkconfig 【选项】 服务

2、命令参数

  --list  显示所有运行级系统服务的运行状态信息(on或off)

  --add  增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立
    --del 删除服务,并把相关符号连接从/etc/rc[0-6].d删除

      --level 设置某一服务在指定的运行级是被启动,停止还是重置

等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动 

3、命令功能

  更新(启动或停止)和查询系统服务的运行级信息

4、使用范例

   实例一:显示所有运行级系统服务的运行状态信息

   命令:chkconfig --list

[root@CenOS6 /]# 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:on    3:on    4:on    5:on    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
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
nfs-rdma           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
pppoe-server       0:off    1:off    2:off    3:off    4:off    5:off    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
rdma               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
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
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
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

   实例二:设置sshd在运行级别为2、4的情况下都是on(开启)的状态
   命令:chkconfig --level 24 sshd on

[root@CenOS6 /]# chkconfig --list|grep sshd
sshd               0:off    1:off    2:off    3:on    4:off    5:on    6:off
[root@CenOS6 /]# chkconfig --level 24 sshd on
[root@CenOS6 /]# chkconfig --list|grep sshd
sshd               0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@CenOS6 /]# 

   实例三:查看在runlevel3下自动启动的services
   命令:chkconfig --list | grep 3:on

[root@CenOS6 /]# chkconfig --list | grep 3:on
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
haldaemon          0:off    1:off    2:off    3:on    4:on    5:on    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:on    3:on    4:on    5:on    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
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
nfslock            0:off    1:off    2:off    3:on    4:on    5:on    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
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
rsyslog            0:off    1:off    2:on    3:on    4:on    5:on    6:off
sshd               0:off    1:off    2:on    3:on    4:on    5:on    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

5、如何增加一个服务

1. 服务脚本必须存放在/etc/ini.d/目录下;
2. chkconfig --add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3. chkconfig --level 35 mysqld on
修改服务的默认启动等级。

6、chkconfig 与 rc*.d目录下的脚本 (*表示runlevel1-6)

当你使用chkconfig来增加或删除某个service的自动启动选项的设置的时候,其实是在rc*.d目录下做下列的事情:
当chkconfig --add命令执行的时候,其实是在对应的rc*.d目录下创建相应用来启动和停止service的service的symbollink文件;
当chkconfig --del命令执行的时候,其实是在对应的rc*.d目录下删除相应用来启动和停止service的service的symbollink文件;

rc*.d目录下与某个service关联的2个symbollink文件中,以K(kill)开始的表示此文件用来停止service,以S(start)开始的表示此文件用来启动service。

例如service sshd没有设置自动启动选项的时候,我们在/rc*.d下看不到用来启动和停止service的symbollink文件

[root@CenOS6 /]# ls -ltr /etc/rc.d/rc3.d|grep sshd
[root@CenOS6 /]# ls -ltr /etc/rc.d/rc5.d|grep sshd
[root@CenOS6 /]# chkconfig --add sshd
[root@CenOS6 /]# ls -ltr /etc/rc.d/rc3.d|grep sshd
lrwxrwxrwx. 1 root root 14 Dec 10 05:42 S55sshd -> ../init.d/sshd
[root@CenOS6 /]# ls -ltr /etc/rc.d/rc5.d|grep sshd
lrwxrwxrwx. 1 root root 14 Dec 10 05:42 S55sshd -> ../init.d/sshd

 

posted @ 2015-12-10 11:41  大白虾  阅读(439)  评论(0)    收藏  举报