Systemd服务

POST –> Boot Sequence –> Bootloader –> kernel + initramfs(initrd) –> rootfs –> /sbin/init
init:
CentOS 5: SysV init
CentOS 6: Upstart
CentOS 7: Systemd
Systemd新特性:
系统引导时实现服务并行启动;
按需激活进程;
系统状态快照;
基于依赖关系定义服务控制逻辑;
核心概念:unit
配置文件进行标识和配置;文件中主要包含了系统服务、监听socket、保存的系统快照以及其它与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无法与之通信
管理系统服务:
CentOS 7: service unit
注意:能兼容早期的服务脚本
命令:systemctl COMMAND name.service
启动:service name start ==> systemctl start name.service
停止:service name stop ==> systemctl stop name.service
重启:service name restart ==> systemctl restart name.service
状态:service name status ==> systemctl status name.service
条件式重启:service name condrestart ==> systemctl try-restart name.service
重载或重启服务:systemctl reload-or-restart name.service
重载或条件式重启服务:systemctl reload-or-try-restart name.service
禁止设定为开机自启:systemctl mask name.service
取消禁止设定为开机自启:systemctl unmask name.service
查看某服务当前激活与否的状态:systemctl is-active name.service
查看所有已经激活的服务:
systemctl list-units –type service 
查看所有服务:
systemctl list-units –type service –all
chkconfig命令的对应关系:
设定某服务开机自启:chkconfig name on ==> systemctl enable name.service
禁止:chkconfig name off ==> systemctl disable name.service
查看所有服务的开机自启状态:
chkconfig –list ==> systemctl list-unit-files –type service 
查看服务是否开机自启:systemctl is-enabled name.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.target
3  ==> runlevel3.target, multi-user.target
4  ==> runlevel4.target, multi-user.target
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 name.target
切换至紧急救援模式:
systemctl rescue
切换至emergency模式:
systemctl emergency
其它常用命令:
关机:systemctl halt、systemctl poweroff
重启:systemctl reboot
挂起:systemctl suspend
快照:systemctl hibernate
快照并挂起:systemctl hybrid-sleep

原创文章,作者:kang,如若转载,请注明出处:http://www.178linux.com/77624

(0)
上一篇 2015-02-28 17:47
下一篇 2015-03-02 14:03

相关推荐

  • 关于大型网站技术演进的思考(九)–网站静态化处理–总述(1)

    原文出处: 夏天的森林    在存储瓶颈的开篇我提到像hao123这样的导航网站只要它部署的web服务器数量足够,它可以承载超大规模的并发访问量,如果是一个动态的网站,特别是使用到了数据库的网站是很难做到通过增加web服务器数量的方式来有效的增加网站并发访问能力的。但是现实情况是像淘宝、京东这样的大型动态网站在承担高并发的情况下…

    Linux干货 2015-03-11
  • N22-第八章作业

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。       网桥:网桥是工作在数据链路层的设备。用于将两个LAN连接在一起并按照Mac地址转发数据。网桥保存着所有与它相连的主机的Mac地址表和端口号并具有学习功能。当网桥收到某个数据包后,能根据目的主机的Mac地址再选择从哪个端…

    Linux干货 2016-10-24
  • 第九周作业

    第九周作业

    Linux干货 2017-11-13
  • httpd

      httpd http服务器程序:   httpd (apache) nginx lighttpd httpd的特性:   高度模块化: core + modules DSO:dynamic shared object(模块的动态加载) MPM:Multipath processing Modules (多路处理模块) &nb…

    Linux干货 2017-06-04
  • 第二周作业

    一Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 which命令:显示(shell)命令全部的路径 which [option] programmame […] –skip-alias:忽略别名   whereis命令:搜索二进制程序,源码,和帮助手册页的命令 whereis [option] na…

    Linux干货 2017-02-18
  • FHS文件系统各目录功能

    前言:     文件系统是一种存储和组织计算机数据的方法,它使得对其访问和查找变得容易。linux的哲学是一切皆文件,linux系统中的一切包括设备文件,我们都能在linux的倒置树状文件系统中找到相对应的文件。所以清楚的明白根目录下的每个子目录包含什么样的文件是很有必要的。我们将以Filesystem Hierarchy Standar…

    Linux干货 2016-10-17