CentOS7开机流程

Linux运行级别
什么是运行级别?运行级别就是操作系统当前正在运行的功能级别,CentOS7开机时会读取软链接文件/etc/systemd/system/default.target指向的运行级别。
# 查看系统中的运行级别
[root@wqh06 ~]# systemctl get-default
multi-user.target
# 设置系统运行级别
[root@wqh06 ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@wqh06 ~]# systemctl get-default
graphical.target
[root@wqh06 ~]# systemctl set-default runlevel3.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@wqh06 ~]# systemctl get-default
multi-user.target
| System 运行级别 | Systemd目标名称 | 作用 | 
| 0 | runlevel0.target,poweroff.target | 关机 | 
| 1 | runlevel1.target,rescue.target | 单用户模式 | 
| 2 | runlevel2.target,multi-user.target | 多用户模式(无法使用NFS) | 
| 3 | runlevel3.target,multi-user.target | 多用户模式 | 
| 4 | runlevel4.target,multi-user.target | 多用户模式(Unused) | 
| 5 | runlevel5.target,graphical.target | 图形界面或桌面模式 | 
| 6 | runlevel6.target,reboot.target | 重启 | 
systemd进程管理
systemd的优势
1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...)
2.CentOS7 支持开机并行启动服务,显著提高开机启动效率。
3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。
4.CentOS7服务的启动与停止不在使用脚本进行管理,也就是/etc/init.d下不在有脚本。
5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。
systemd相关文件
| 相关文件 | CentOS6 | CentOS7 | 
| 服务启动脚本存放路径 | /etc/init.d | /usr/lib/systemd/system | 
| 开机自启服务存放路径 | /etc/rcN.d | /etc/systemd/system/*.target.wants | 
| 默认运行级别 | /etc/inittab | /etc/systemd/system/default.target | 
systemd启动相关命令
| system V init CentOS6 | systemd CentOS7 | 作用 | 
| /etc/init.d/nginx start | systemctl start nginx | 启动nginx服务 | 
| /etc/init.d/nginx stop | systemctl stop nginx | 停止nginx服务 | 
| /etc/init.d/nginx status | systemctl status nginx | 查看服务的启动状态 | 
| /etc/init.d/nginx restart | systemctl restart nginx | 重启服务 | 
| /etc/init.d/nginx reload | systemctl reload nginx | 不停止服务,重新加载nginx配置文件 | 
|  | systemctl is-acvite nginx | 判断nginx服务是否存活 | 
|  | systemctl mask nginx | 禁止服务运行 | 
|  | systemctl unmask nginx | 取消禁止 | 
systemd开机自启动相关命令
| system V init CentOS6 | systemd CentOS7 | 作用 | 
| chkconfig --list | systemctl list-unit-files | 查看开机自启的服务 | 
| chkconfig nginx on | systemctl enable nginx | 加入开机自启动 | 
| chkconfig nginx off | systemctl disable nginx | 关闭开机自启动 | 
| chkconfig --list nginx | systemctl is-enabled nginx | 查看指定服务是否被开机自启 | 
| chkconfig --add nginx | systemctl daemon-reload | 当我们手写脚本时让系统认识 | 
systemd服务状态
| 服务状态 | 状态说明 | 
| loaded | 服务单元的配置文件已经被处理 | 
| active(running) | 服务的一个或多个进程在运行中 | 
| active(exited) | 一次性运行的服务成功被执行并退出(服务运行后完成任务,相关进程会自动退出) | 
| active(waiting) | 服务已经运行但在等待某个事件 | 
| inactive | 服务没有在运行 | 
| enable | 服务设定为开机运行 | 
| disabled | 服务设定为开机不运行 | 
| static | 服务不能被设定开机启动,但可以由其他服务启动该服务 |