CentOS7,8系统启动流程:
1)BIOS加电自检
2)把MBR加载到内存
3)加载grub引导程序
4)Kernel自身初始化
5)启动第一个程序systemd
在RHEL/CentOS 7,8中,Runlevels的概念已经被systemd target替代,而/etc/rc.d/init.d/目录下的初始文件也已经被service units所替代。
systemd target是一种systemd unit,用以描述系统的一个状态或一个同步点(快照)。一个systemd target拥有一个以.target为后缀的unit配置文件,位于/usr/lib/systemd/system/路径下。一个systemd target往往只是一组相关的systemd units的集合,用以将Linux系统设置为某个状态,类似于CentOS 6的Runlevel。
CentOS 6的Runlevels与CentOS 7的targets之间的对应关系如下:
6)检查默认运行级别(默认是3,即“multi-user.target”)
Linux系统启动时,各个target之间的依赖关系如下图所示:
7)启动相应运行级别下的所有程序服务 (用户可管理)
8)加载/etc/rc.d/rc.local脚本
用户可将自定义开机启动脚本放rc.local文件内,并修改rc.local为执行权限
9)systemd执行multi-user.target下的getty.target及登录服务
10)systemd执行graphical需要的服务(如果不使用图形界面,这步省略)
Linux运行级别:
服务运行级别配置:
1)查看默认级别
systemctl get-default
2)查看当前运行级别
runlevel
3)设置默认级别
systemctl set-default multi-user.target
4)切换运行级别
方法1:init命令
init 0|1|3|5|6
方法2:systemctl命令
systemctl isolate multi-user.target
systemctl isolate graphical.target
5)列出所有的target
systemctl list-units --type=target --all
6)查看系统中所有服务的启动状态
systemctl list-unit-files
7)查看某个服务状态
systemctl status sshd.service
systemctl is-active sshd.service
systemctl is-enabled sshd.service
systemctl list-unit-files | grep sshd.service