zoukankan      html  css  js  c++  java
  • Linux服务开机自启动设置

    Linux中也有类似于Window中的开机自启动服务,主要是通过chkconfig命令来设置。它主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。

    参数说明:

    [root@DB-Server rc2.d]# chkconfig --help
    chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
    This may be freely redistributed under the terms of the GNU Public License.
     
    usage:   chkconfig --list [name]
             chkconfig --add <name>
             chkconfig --del <name>
             chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
    [root@DB-Server rc2.d]# chkconfig
    chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
    This may be freely redistributed under the terms of the GNU Public License.
     
    usage:   chkconfig --list [name]
             chkconfig --add <name>
             chkconfig --del <name>
             chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

    --list 显示开机可以自动启动的服务

    --add 新增所指定的开机自启动系统服务

    --del 删除所指定的系统服务

    --level 指定该系统服务要在那个执行等级中开启或关闭。

    on/off/reset 在指定的执行登记,开启/关闭/重置该系统服务

     

    使用案例:

    chkconfig --list      #显示开机可以自动启动的服务
     
    chkconfig --add ***   #增加开机自动启动的***服务
     
    chkconfig --del ***   #删除开机自动启动的***服务
     
    chkconfig --level mysql 2345 on #设置mysql在运行级别为2、3、4、5的情况下都是on(开启)的状态

     

    [root@DB-Server ~]# chkconfig --list | grep mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@DB-Server ~]# 

    --level<等级代号> 指定系统服务要在哪一个执行等级中开启或关闭

    等级0表示:表示关机

    等级1表示:单用户模式

    等级2表示:无网络连接的多用户命令行模式

    等级3表示:有网络连接的多用户命令行模式

    等级4表示:未定义

    等级5表示:带图形界面的多用户模式

    等级6表示:重新启动

     

    [root@DB-Server ~]# chkconfig --list mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@DB-Server ~]# chkconfig --del mysql
    [root@DB-Server ~]# chkconfig --list | grep mysql
    [root@DB-Server ~]# chkconfig --add mysql
    You have new mail in /var/spool/mail/root
    [root@DB-Server ~]# chkconfig --list | grep mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@DB-Server ~]# 

    clip_image001

    如果我们要在运行级别3上开机自启动mysql服务,在其它运行级别关闭,可以通过下面命令来设置。

    [root@DB-Server ~]# chkconfig --list | grep mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@DB-Server ~]#  chkconfig --level 3 mysql on
    [root@DB-Server ~]# chkconfig --list | grep mysql
    mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
    [root@DB-Server ~]#  chkconfig --level 2 mysql off
    [root@DB-Server ~]#  chkconfig --level 4 mysql off
    [root@DB-Server ~]# chkconfig --list | grep mysql
    mysql           0:off   1:off   2:off   3:on    4:off   5:on    6:off
    [root@DB-Server ~]# 

    clip_image002

    当然也可以用下面命令来开启,关闭服务的开启自启动.

    chkconfig service_name on
    chkconfig service_name on --level runlevels
    chkconfig service_name off --level runlevels

    [root@DB-Server ~]# chkconfig mysql on --level 3
    [root@DB-Server ~]# chkconfig mysql off --level 45
    [root@DB-Server ~]# 

    新增开机自启动MySQL服务,我们会在/etc/rc.d/rcn.d下看到生成了一个对应的文件,例如/etc/rc.d/rc3.d

    clip_image003

    我们删除开机自动启动的mysql服务,就会看到对应的文件也被删除。

    [root@DB-Server rc3.d]# chkconfig --del mysql
     
    [root@DB-Server rc3.d]# ls *mysql*
     
    ls: *mysql*: No such file or directory
     
    [root@DB-Server rc3.d]# 

    clip_image004

    chkcofig后的三个参数: 第一个参数,它告诉chkconf这个服务以什么样的运行级别开始。第二个参数,它指定的了启动的优先等级。最后一个参数,它指定了停止服务时,它拥有的优先级别。上面的这个实例中,它表示这个服务以2、3、4和5的级别开始,它的启动优先级为64,它的停止优先级是36。

    [root@DB-Server rc3.d]# chkconfig --add mysql

    clip_image005

     

    参考资料:

    http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html

    http://network810.blog.51cto.com/2212549/1137972

     

  • 相关阅读:
    3月30日
    3月29日
    3月26日
    3月24
    3月22日
    3月20日
    博弈论基础
    $burnside$引理与$pacute olya$定理
    min-max容斥
    模板
  • 原文地址:https://www.cnblogs.com/kerrycode/p/5478399.html
Copyright © 2011-2022 走看看