Linux启动级别 以及 chkconfig详解

2024-02-12 19:58

本文主要是介绍Linux启动级别 以及 chkconfig详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、启动级别

 

1、查看linux 系统默认启动级别

cat /etc/inittab 

id:3:initdefault: ##可以看出默认为三

 

2、查看某一服务在各个启动级别上是否启动

[root@localhost ~]# chkconfig --list  nfs

nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off

 

3、在Linux中有7种启动级别

分别为: 

#   0 - halt (Do NOT set initdefault to this) 

#   1 - Single user mode 

#   2 - Multiuser, without NFS (The same as 3, if you do not have networking) 

#   3 - Full multiuser mode 

#   4 - unused 

#   5 - X11 

#   6 - reboot (Do NOT set initdefault to this) 

各个运行级的详细解释: 

0 为停机,机器关闭。 

1 为单用户模式,就像Win9x下的安全模式类似。 

2 为多用户模式,但是没有NFS支持。 

3 为完整的多用户模式,是标准的运行级。 

4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本电脑的电池用尽时,可以切换到这个模式来做一些设置。 

5 就是X11,进到X Window系统了。 

6 为重启,运行init 6机器就会重启。 

 

0和6一般不用; 

 

 

二、 chkconfig

 

说明 :linux 的所有服务都在 /etc/init.d/  下, 但是 /etc/init.d  是 链接的 /etc/rc.d/init.d

       同样 /etc/rc[0-6].d 都是连接的相应的 /etc/rc.d/rc[0-6].d ,不同启动级别的 rc[0-6].d 中的服务都是 链接的 /etc/init.d 下的相应服务

 

 

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

  语法:

    chkconfig --list [name]

    chkconfig --add name

    chkconfig --del name

    chkconfig [--level levels] name <on|off|reset>

    chkconfig [--level levels] name

 

    chkconfig 没有参数运行时,显示用法。如果加上服务名,那么就检查这个服务是否在当前运行级启动。如果是,返回true,否则返回false。如果在服务名后面指定了on,off或者reset,那么chkconfi 会改变指定服务的启动信息。on和off分别指服务被启动和停止,reset指重置服务的启动信息,无论有问题的初始化脚本指定了什么。on和off开关,系统默认只对运行级2,3,4,5有效,但是reset可以对所有运行级有效。

    --level选项可以指定要查看的运行级而不一定是当前运行级。

    需要说明的是,对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。

 

2、 chkconfig --list :显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。

 

    chkconfig --add name:增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立。

 

    chkconfig --del name:删除服务,并把相关符号连接从/etc/rc[0-6].d删除。

 

    chkconfig [--level levels] name <on|off|reset>:设置某一服务在指定的运行级是被启动,停止还是重置。例如,要在3,4,5运行级停止nfs服务,则命令如下:

    chkconfig --level 345 nfs off

 

3、举例sendmail:

 

1)cat /etc/inittab

id:3:initdefault: 

 

2)chkconfig --list  sendmail

sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off

查看连接 :

ll /etc/rc0.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 K30sendmail -> ../init.d/sendmail

ll /etc/rc1.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 K30sendmail -> ../init.d/sendmail

ll  /etc/rc2.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 S80sendmail -> ../init.d/sendmail

ll /etc/rc3.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 S80sendmail -> ../init.d/sendmail 

ll /etc/rc4.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 S80sendmail -> ../init.d/sendmail

ll /etc/rc5.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 S80sendmail -> ../init.d/sendmail

 ll /etc/rc6.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov  5 23:43 K30sendmail -> ../init.d/sendmail

 

3)chkconfig --del  sendmail

   [root@localhost init.d]# chkconfig --list  sendmail

service sendmail supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add sendmail')

查看连接

[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail

[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail

[root@localhost init.d]#  ---》 全为空

 

4)

[root@localhost init.d]# chkconfig --add  sendmail

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

查看连接:

[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail  ----》 相应的服务连接又回来了 

 

5)chkconfig   sendmail  off  --》on和off分别指服务被启动和停止,reset指重置服务的启动信息,无论有问题的初始化脚本指定了什么。on和off开关,系统                                  默认只对运行级3,4,5有效,但是reset可以对所有运行级有效

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off

 

查看连接:

[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail  ---》全是 "K"

 

6)chkconfig   sendmail  on 

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

查看连接:

[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail

[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail

lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail  --》2,3,4,5 为“S” 其他为 K

 

7)

chkconfig   sendmail  off 

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@localhost init.d]# chkconfig --level 3  sendmail  on

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:off   3:on    4:off   5:off   6:off

[root@localhost init.d]# chkconfig --level 0  sendmail  on

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:on    1:off   2:off   3:on    4:off   5:off   6:off  --》 看来 得用level on 参数控制 0级别

 

[root@localhost init.d]# chkconfig   sendmail  off 

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:on    1:off   2:off   3:off   4:off   5:off   6:off  --》 但是这样3 级别关了 0 级别没关掉

 

[root@localhost init.d]# chkconfig --level 0  sendmail  off

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off  --》 0 级别关掉了 (经验证1,6级别 也是这样的和0级别一样 得用level控制) 

 

8)

[root@localhost init.d]# chkconfig   sendmail  off 

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@localhost init.d]# chkconfig   sendmail  reset

[root@localhost init.d]# chkconfig --list  sendmail

sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off --》 reset指重置服务的启动信息 可以对所有运行级有效 (没太懂这个东西reset)


这篇关于Linux启动级别 以及 chkconfig详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/703464

相关文章

一文详解SpringBoot中控制器的动态注册与卸载

《一文详解SpringBoot中控制器的动态注册与卸载》在项目开发中,通过动态注册和卸载控制器功能,可以根据业务场景和项目需要实现功能的动态增加、删除,提高系统的灵活性和可扩展性,下面我们就来看看Sp... 目录项目结构1. 创建 Spring Boot 启动类2. 创建一个测试控制器3. 创建动态控制器注

C#读写文本文件的多种方式详解

《C#读写文本文件的多种方式详解》这篇文章主要为大家详细介绍了C#中各种常用的文件读写方式,包括文本文件,二进制文件、CSV文件、JSON文件等,有需要的小伙伴可以参考一下... 目录一、文本文件读写1. 使用 File 类的静态方法2. 使用 StreamReader 和 StreamWriter二、二进

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

java中反射Reflection的4个作用详解

《java中反射Reflection的4个作用详解》反射Reflection是Java等编程语言中的一个重要特性,它允许程序在运行时进行自我检查和对内部成员(如字段、方法、类等)的操作,本文将详细介绍... 目录作用1、在运行时判断任意一个对象所属的类作用2、在运行时构造任意一个类的对象作用3、在运行时判断

linux hostname设置全过程

《linuxhostname设置全过程》:本文主要介绍linuxhostname设置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录查询hostname设置步骤其它相关点hostid/etc/hostsEDChina编程A工具license破解注意事项总结以RHE

MySQL 中的 CAST 函数详解及常见用法

《MySQL中的CAST函数详解及常见用法》CAST函数是MySQL中用于数据类型转换的重要函数,它允许你将一个值从一种数据类型转换为另一种数据类型,本文给大家介绍MySQL中的CAST... 目录mysql 中的 CAST 函数详解一、基本语法二、支持的数据类型三、常见用法示例1. 字符串转数字2. 数字

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

MyBatis-Plus 中 nested() 与 and() 方法详解(最佳实践场景)

《MyBatis-Plus中nested()与and()方法详解(最佳实践场景)》在MyBatis-Plus的条件构造器中,nested()和and()都是用于构建复杂查询条件的关键方法,但... 目录MyBATis-Plus 中nested()与and()方法详解一、核心区别对比二、方法详解1.and()