|NO.Z.00001|——————————|ManageMent|——|Linux&系统管理.V01|
一、系统运行级别
### --- 运行级别
~~~ Linux 默认有 7 个运行级别
运行级别 | 含义 |
0 | 关机 |
1 | 单用户模式,可以想象为windows的安全模式,主要用于系统修复 |
2 | 不完全的命令行模式,不含NFS服务 |
3 | 完全的命令行模式,就是标准字符界面 |
4 | 系统保留 |
5 | 图形模式 |
6 | 重启系统 |
### --- 在 Linux 系统中可以使用 runlevel 命令来查看系统的运行级别,命令如下:
~~~ N 代表进入这个级别前,上一个是哪个级别。3 代表当前级别
~~~ 在这个命令的结果中,“N 3”中的 N 代表进入这个级别前,
~~~ 上一个级别是什么,3 代表当前级别。
~~~ “N”就是 None 的意思,也就是说系统是开机直接进入的 3 运行级别,没有上一个运行级别。
~~~ 那如果是从图形界面切换到字符界面的话,再查看运行级别,就应该是这样的:
[root@server11 ~]# runlevel
N 3 // N表示空的,表示在进入当前级别之前,上一个级别是什么;3表示当前级别
### --- 代表是由 5 级别进入的 3 级别
~~~ 那么可以手工改变当前的运行级别吗?当然可以了,只要使用 init 命令(注意着不是 init 进程)即可,命令如下:
[root@server11 ~]# init 5
[root@server11 ~]# runlevel
3 5
[root@server11 ~]# init 5
~~~ 关机
~~~ 进入图形界面,当然要已经安装了图形界面才可以
[root@server11 ~]# init 0
### --- 重启动
~~~ 不过要注意使用 init 命令关机和重启动,并不是太安全,容易造成数据丢失。
~~~ 所以推荐大家还是使用 shutdown 命令进行关机和重启吧!
[root@server11 ~]# init 6
二、系统默认运行级别
### --- 系统默认运行级别
~~~ 知道了运行级别的作用,我们回到系统启动过程中来。
~~~ /etc/init/rcS.conf 配置文件调用/etc/inittab 配置文件的目的就是为了确定系统的默认运行级别,
~~~ 也就是系统一开机后会进入那个运行级别。这个文件的内容如下:
[root@server11 ~]# vim /etc/inittab
# Default runlevel. The runlevels used are:
# 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或者6
id:3:initdefault:
~~~ 系统会先调用/etc/init/rcS.conf
Individual runlevels are started by /etc/init/rc.conf
~~~ 再调用/etc/init/rc.conf,在不同的运行级别启动不同的服务
Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
~~~ 通过这个配置文件判断 Ctrl+Alt+Delete 热启动键是否可用
Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
with configuration in /etc/sysconfig/init.
~~~ 判断系统可以启动的本地终端数量,及终端的基本设置(如颜色)
For information on how to write upstart event handlers, or how
upstart works, see init(5), init(8), and initctl(8).
Default runlevel. The runlevels used are:
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-6 的运行级别的说明
id:3:initdefault:
~~~ 这就是系统的默认运行级别,也就是系统开机后直接进入哪个运行级别
~~~ 注意这里的默认运行级别只能写 3 或 5,其他的级别要不就是关机重启,
~~~ 要不就是保留或单用户,都不能作为系统默认运行级别的。
三、 /etc/rc.d/rc.local 文件
### --- /etc/rc.d/rc.local 文件
~~~ 这个配置文件会在用户登陆之前读取,这个文件中写入什么命令,
~~~ 在每次系统启动时都会执行一次。
~~~ 也就是说,我如果有任何需要在系统启动就运行的工作,
~~~ 只需要写入/etc/rc.d/rc.local 这个配置文件即可。这个文件内容如下:
[root@server21 ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Feb 4 07:44 /etc/rc.local -> rc.d/rc.local
~~~ 有个链接文件,两个文件修改哪一个都可以
[root@server21 ~]# vi /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local // 每次开机都touch一下这个文件,
~~~ 默认会 touch 这个文件,每次系统启动时 touch 这个文件,
~~~ 这个文件的修改时间就是系统的启动时间了。
~~~ 如果写入 RPM 包安装的 apache 的启动命令,apache 服务就会开机时自动启动了。
[root@server21 ~]# /etc/rc.d/init.d/httpd start
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
分类:
cdv006-system
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」