系统学习----Systemd

CentOS7之Systemd特性

特性:
系统引导实现服务运行并启动
按需激活集成
系统服务状态快照
基于依赖关系定义服务控制逻辑

核心概念:Unit

配置文件中会进行标识和配置,文件中主要包含系统服务/监听socket/保存的系统快照以及其他与Init相关的配置信息都会保存至:
a) /usr/lib/systemd/system/
b) /run/systemd/system/
c) /etc/systemd/system/

Unit类型:

1. service unit: 文件扩展名为service;用于定义系统服务
[root@test ~]# cat /usr/lib/systemd/system/chronyd.service 

2. Target unit: 文件扩展名为target;用于模拟实现"运行级别"
[root@test ~]# cat /usr/lib/systemd/system/sockets.target

3. Device unit: 文件扩展名为device;用于定义内核标识的设备
4. Mount unit: 文件扩展名为mount; 用于定义文件系统挂载点
5. socket unit:文件扩展名为socket;用于标识进程间通信的socket文件
6. Snapshot unit: 文件扩展名为snapshot;用于管理系统快照
7. Swap unit: 文件扩展名为swap;用于标识swap设备
8. automount unit: 文件扩展名为automount;管理自动挂载的文件系统
9. Path unit: 文件扩展名为path; 用于定义文件系统中的一个文件或目录 

关键特性:

基于socket的激活机制: socket与服务程序分离
基于device的激活机制: ....
基于path的激活机制
基于bus的激活机制
系统快照,保存各init的当前状态信息于持久化存储设备中
向后兼容 sysv init 脚本

运行级别:0-6
0: 关机
6:重启
1:单机用户
2:多用户,无网络连接
3:无图形化,多用户,网络连接
5:图形化,多用户,网络连接

systemctl命令:用于管理系统服务

[root@test ~]# systemctl --help
systemctl [OPTIONS...] {COMMAND} ...

启动服务: systemctl start name.service
重启服务: systemctl restart name.service
停止服务: systemctl stop name.service
开机自启: systemctl enable name.service
开机不自启: systemctl disable name.service
重载或者重启服务: systemctl reload-or-restart name.service
查看服务状态: systemctl status name.service

查看某个服务当前激活与否状态: systemctl is-active chronyd.service
查看某个服务是否开机启动: systemctl is-enabled chronyd.service
查看所有已经激活的服务: systemctl list-units --type service
查看所有服务:systemctl list-units --type service --all

chkconfig命令的对应关系:

设定某个服务自启动: chkconfig name on 
禁止: chkconfig name off 
查看所有服务的开机启动状态: chkconfig --list 

运行级别相关操作:

查看运行级别: runlevel == systemctl list-units --type target
切换运行级别: init N == sytemctl isolate name.target
获取默认运行级别: systemctl get-default
设置默认运行级别: systemctl set-default TARGET.target
切换紧急救援模式: systemctl rescue
切换救援模式: systemctl emergency

其他常用命令:

关机: systemctl halt | systemctl poweroff 
重启: sytemctl reboot
挂起: systemctl suspend 
快照: systemctl hibernate 
快照并挂起: systemctl hybride-sleep 
发布了49 篇原创文章 · 获赞 6 · 访问量 3687

猜你喜欢

转载自blog.csdn.net/weixin_46097280/article/details/104381972