zoukankan      html  css  js  c++  java
  • linux命令(001) -- chkconfig

    一、准备知识

    在说明chkconfig命令的用途之前,有必要先了解一下Linux系统中/etc/rc[0-6].d目录的用途。

    众所周知,在Linux系统定义了7种不同的启动级别,这7种启动级别的含义分别如下:

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

    所以,/etc/rc[0-6].d目录中的0-6就代表了上述7种启动级别。接下来我们再看一下/etc/rc[0-6].d目录中到底存放了些什么东西,以/etc/rc5.d为例:

    ...省略...
    lrwxrwxrwx. 1 root root 15 May 17 21:57 K89rdisc -> ../init.d/rdisc
    lrwxrwxrwx. 1 root root 18 May 17 22:12 K92iptables -> ../init.d/iptables
    lrwxrwxrwx. 1 root root 14 May 17 21:58 K99rngd -> ../init.d/rngd
    lrwxrwxrwx. 1 root root 17 May 17 21:58 S01sysstat -> ../init.d/sysstat
    lrwxrwxrwx. 1 root root 22 May 17 21:58 S02lvm2-monitor -> ../init.d/lvm2-monitor
    lrwxrwxrwx. 1 root root 19 May 17 21:57 S08ip6tables -> ../init.d/ip6tables
    ...省略...
    

    从上面的输出中可以看到,/etc/rc5.d中存放的都是一些链接文件,这些链接文件都存放在一个名为/etc/init.d的目录中。好了,准备知识就到此为止!

    二、命令用法

    chkconfig的用途为,查看系统服务的启动信息或更新系统服务的运行级别。我们再来了解一下man page中是如何介绍chkconfig的用途的:“chkconfig提供了一个简单的,用于维护/etc/rc[0-6].d的目录层级的命令行工具,通过使用该工具,极大地减轻了系统管理员在操作这些目录中的符号链接方面的任务。”

    语法:
    chkconfig [--list] [--type type][name]
    chkconfig --add name
    chkconfig --del name
    chkconfig --override name
    chkconfig [--level levels] [--type type] name <on|off|reset|resetpriorities>
    chkconfig [--level levels] [--type type] name
    
    选项:
    --level:指定某个服务的运行级别。例如:--level 35指定的运行级别为3和5;
    --list:列出被chkconfig所管理的所有服务及其在个运行级别下的启动状态;
    --add:增加一个服务,在/etc/rc[0-6].d目录下增加相关符号链接;
    --del:删除一个服务,从/etc/rc[0-6].d目录下删除相关符号连接;
    --override:使用/etc/chkconfig.d目录下的init script的功能覆盖/etc/init.d目录下的同名init script;
    

    如果在服务名后接on、off、reset、resetpriorities其中之一,chkconfig命令将会改变指定服务的启动信息,其中:on/off用于指示启动/停止服务,reset用于根据启动脚本(/etc/init.d目录下与服务名同名文件)中定义重置服务的启动/停止状态,resetpriorities用于根据启动脚本中的定义重置服务的启动/停止优先级。以iptables的init script为例:

    [root@primary-mysql init.d]# vi iptables 
    
    #!/bin/sh
    #
    # iptables      Start iptables firewall
    #
    # chkconfig: 2345 08 92
    # description:  Starts, stops and saves iptables firewall
    #
    ...省略...
    
    # 其中,2345是iptables的默认启动级别,08是默认的启动优先级,92是默认的停止优先级。
    

    在默认情况下,on和off只影响2,3,4,5四种运行级别,reset和resetpriorities影响所有的运行级别。--level选项被用于指定到底将会影响哪(几)种运行级别。

    如果chkconfig使用--list参数或不带参数,命令将显示系统中所有的服务及它们的运行级别。如果chkconfig --list service_name,命令将显示某个指定的服务的运行级别。

    三、示例:配置一个服务并使其开机自启动

    # 确保在/etc/init.d目录下存在服务的init script。
    
    # 将服务加入chkconfig管理
    chkconfig --add service_name
    
    # 配置服务的运行级别及状态
    chkconfig --level 35 service_name on
    
    # 确认配置结果
    chkconfig --list service_name 或 chkconfig --list 或 chkconfig

     

  • 相关阅读:
    封装微信小程序
    请求formdata格式
    基于vue的前端框架
    es6 入门
    测试缓存时间问题console.time
    export 与 export default, 以及import引用
    vue emit 实现非父子之间的值传递
    css3 弹性盒子display:flex
    iview $modal 的封装
    render iview tab select的添加和input的添加
  • 原文地址:https://www.cnblogs.com/sunmengbbm/p/5648531.html
Copyright © 2011-2022 走看看