系统引导时实现服务并行启动
按需激活进程
系统状态快照
基于依赖关系定义服务控制逻辑
核心概念:unit
配置文件进行标志和配置:文件中主要包含了系统服务、监听socket、保存的系统快照以及其他与init相关的init相关的信息
保存至:
/usr/lib/systemd/system
/run/systemd/system
/etc/systemd/system
unit类型
Service unit:文件扩展名为.service用于定义系统服务;
Target unit 文件扩展名为.target用于模拟实现“运行级别”;
Device unit .device 用于定义内核识别的设备
Mount unit .mount 用于定义文件系统挂载点
Socket unit .socket 用于标识进程间通信用的socket文件
Snapshot unit .snapshot 管理系统快照
Swap unit .swap 标识swap 设备
Automount unit .automount 文件系统的自动挂载点
Path unit .path 定义文件系统中的一个文件或目录
关键特性:
基于socket的激活机制:socket与服务程序分离;
基于bus的激活机制:
基于device的激活机制:
基于path的激活机制:
系统快照:保存各unit的当前状态信息于持久存储设备中
向后兼容sysv init脚本
不兼容
systemctl 命令固定不变
非由systemd启动的服务 systemctl无法与之通信
条件式重启
service name condrestart ==> systemctl try-restart name,service
chkconfig --list name ==> systemctl is-active name.service
重启或重载服务
systemctl reload-or-restart name.service
重载或条件式重启服务
systemctl reload-or-try-restart name.service
禁止设定为开机自启
systemctl mask name.service 取消为unmask
查看激活的服务
systemctl list-units --type service
查看所有服务
systemctl list-units --type service --all
chkconfig命令的对应关系:
设定某服务开机自启:chkconfig name on ==> systemctl enable
关闭自启 chkconfig name off ==> systemctl disable name
查看开机自启状态
chkconfig --list ==> systmectl list-unit-files --type service
查看服务依赖关系
systemctl list-dependencies name.service
target units:
unit配置文件 .target
运行级别
0 ==> runlevel0.target,poweroff.target 关机
1 ==》runlevel1.target,rescue.target 单用户级别
2 ==》runlevel2.target,multi-user.taeget 多用户
3 ==>runlevel3.target,multi-user.target
4=2=3
5==> runlevel5.target;graphical.target 图形
6 ==> runlevel6.target;reboot.target
级别切换:
init N ==> systemctl isolate name.target
查询级别 runlevel == systemctl list-units --type target
获取默认运行级别
/etc/inittab ==> systemctl get-default
修改默认级别
/etc/inittab ==> systemctl set-default graphical.target
切换急救模式
systemctl rescue
切换紧急模式
systemctl emergency
其他常用命令
关机:systemctl halt、systemctl poweroff
重启:systemctl reboot
挂起:systemctl suspend
快照systemctl hibernate
快照并挂起 systemctl hybrid-sleep