zoukankan      html  css  js  c++  java
  • 原 Debian设置开机自动启动与关闭

     

    发表于1年前(2013-01-08 13:01)   阅读(2380) | 评论(0) 2人收藏此文章, 我要收藏
    0

            熟悉debian系统的应该经常会用到update-rc.d这个命令,它与redhat里的chkconfig 是相似的管理服务的工具,首先来看下这个命令的使用方法:

    1
    2
    3
    4
    5
    6
    root@10.1.1.200:etc# update-rc.d --help
    usage: update-rc.d [-n] [-f] <basename> remove
           update-rc.d [-n] <basename> defaults [NN | SS KK]
           update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
            -n: not really
            -f: force
              虽然debian的update-rc.d与RH的chkconfig工具相类似。不同的是chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。这些工具有不同的命令行选项,但是却执行类似的功能。下表列出了update-rc.d的一些用法。

    命令                                                                    功能
    update-rc.d -f <service> remove                        从所有的运行级别配置目录中是删除指定的服务
    update-rc.d <service> start <order> <runlevels>   配置服务在运行级别列表中按指定的顺序启动
    update-rc.d <service> stop <order> <runlevels>    配置服务在运行级别列表中指定的顺序停止

            例如,下面的命令序列与命令chkconfig --level 345 apache2 on的作用相同:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    root@10.1.1.200:etc# update-rc.d -f apache2 remove
     Removing any system startup links for /etc/init.d/apache2 ...
       /etc/rc0.d/K09apache2
       /etc/rc1.d/K09apache2
       /etc/rc2.d/S91apache2
       /etc/rc3.d/S91apache2
       /etc/rc4.d/S91apache2
       /etc/rc5.d/S91apache2
       /etc/rc6.d/K09apache2
    root@10.1.1.200:etc# update-rc.d  apache2  start 20 3 4 5 . stop 20 0 1 2 6 .
     Adding system startup for /etc/init.d/apache2 ...
       /etc/rc0.d/K20apache2 -> ../init.d/apache2
       /etc/rc1.d/K20apache2 -> ../init.d/apache2
       /etc/rc2.d/K20apache2 -> ../init.d/apache2
       /etc/rc6.d/K20apache2 -> ../init.d/apache2
       /etc/rc3.d/S20apache2 -> ../init.d/apache2
       /etc/rc4.d/S20apache2 -> ../init.d/apache2
       /etc/rc5.d/S20apache2 -> ../init.d/apache2
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    root@10.1.1.200:etc# ls -l /etc/rc3.d/
    total 4
    lrwxrwxrwx 1 root root  16 2012-08-13 21:29 K20vsftpd -> ../init.d/vsftpd
    -rw-r--r-- 1 root root 556 2008-08-12 22:09 README
    lrwxrwxrwx 1 root root  17 2012-08-06 00:11 S10rsyslog -> ../init.d/rsyslog
    lrwxrwxrwx 1 root root  15 2012-08-06 00:12 S12acpid -> ../init.d/acpid
    lrwxrwxrwx 1 root root  14 2012-08-06 00:30 S12dbus -> ../init.d/dbus
    lrwxrwxrwx 1 root root  13 2012-08-06 00:24 S16ssh -> ../init.d/ssh
    lrwxrwxrwx 1 root root  23 2012-08-06 00:26 S17mysql-ndb-mgm -> ../init.d/mysql-ndb-mgm
    lrwxrwxrwx 1 root root  19 2012-08-06 00:26 S18mysql-ndb -> ../init.d/mysql-ndb
    lrwxrwxrwx 1 root root  15 2012-08-06 00:26 S19mysql -> ../init.d/mysql
    lrwxrwxrwx 1 root root  17 2013-01-08 00:21 S20apache2 -> ../init.d/apache2
                第一个命令移除了所有的指向/etc/init.d/apache2服务脚本的运行级别链接,-f标志将会使得update-rc.d即使在apache2脚本本身已经存在的情况仍然进行相应的处理。第二个命令在每一个运行级别创建了一个服务级别为20的启动/停止脚本。这些脚本的连接位于/etc/rcX.d/LnName,对应脚本位于/etc/init.d/Script-name。对于已经存的启动脚本链接, 如再次执行第二个命令会发现 System startup links for /etc/init.d/apache2 already exist,必须将其remove掉,再进行相关的操作。 

             start 20  3 4 5 . : 表示在3,4,5这三个运行级别中,按先后顺序,由小到大,第20个开始运行这个脚本。
             stop 20 0 1 2 6 . :表示在0,1,2,6这四个运行级别中,按照先后顺序,由小到大,第20个停止这个脚本的运行。

             有个问题就是想要知道某服务处于什么开机启动级别,man update-rc.d也没发现有该选项。只能从/etc/rcX.d去查看。

             其实熟悉RH 的chkconfig,在debian中也提供类似的工具,sysv-rc-conf同样是查看所有服务的启动状态.

             下面安装sysv-rc-conf

    1
    root@10.1.1.200:etc# apt-get install sysv-rc-conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    root@10.1.1.200:etc# sysv-rc-conf --list
    acpid        1:off  2:on    3:on    4:on    5:on
    apache2      0:off  1:off   2:off   3:on    4:on    5:on    6:off
    atd          0:off  1:off   2:on    3:on    4:on    5:on    6:off
    bootlogd     S:on
    cron         1:off  2:on    3:on    4:on    5:on
    dbus         1:off  2:on    3:on    4:on    5:on
    exim4        0:off  1:off   2:on    3:on    4:on    5:on    6:off
    fam          0:off  1:off   2:on    3:on    4:on    5:on    6:off
    是不是很熟悉..
    1
    2
    3
    root@10.1.1.200:etc# sysv-rc-conf --level 234 apache2 off
    root@10.1.1.200:etc# sysv-rc-conf --list apache2
    apache2      0:off  1:off   2:off   3:off   4:off   5:on    6:off
  • 相关阅读:
    【465】词干提取与词形还原
    【464】文本转字符向量bag of words
    【462】淘宝个人简介
    Docker 图形化页面管理工具使用
    Docker 简介与shell操作使用
    Spring Boot 入门案例与配置说明
    项目管理工具Maven的安装与使用
    Git(五)IDEA应用Git
    Git(四)Git的分支管理
    Git(三)Git的远程仓库
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/3850019.html
Copyright © 2011-2022 走看看