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)
kangkang
上一篇 2015-02-28 17:47
下一篇 2015-03-02 14:03

相关推荐

  • 马哥教育网络班21期+第12周课程练习 ​

    1、请描述一次完整的http请求处理过程;   1)客户端和服务器端建立连接。服务器接收或者拒绝请求。   2)服务器端接收客户端请求。接收来自于网络的请求报文中对某资源的一次请求。对请求的处理响应,可分为单进程(启动一个进程处理请求,一次只处理一个)和多进程(并行启动多个进程,每个进程处理一个请求)。  &…

    Linux干货 2016-10-09
  • 8月2日作业

            1、在/data/testdir里创建的新文件自动属于g1组,组g2的成员如:alice能对这些新文件有读写权限,组g3的成员如:tom只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹。 [root@localhost test…

    Linux干货 2016-08-05
  • 磁盘管理

    1、拿到一块硬盘,通常来讲,第一步是分区,然后是文件系统的创建,管理文件系统,第三步是挂载设备。 2、linux(准确的说是UNIX)哲学,whindows一切皆窗口,一切皆图形。 3、磁盘是一个硬件设备,存放在/dev/目录下,会有相应的文件来对应的表示这些设备文件,在这个目录下存放的全是设备。 4、在/dev目录下和设备相关的有两种,一种是c开头为字符,…

    Linux干货 2017-04-22
  • 第四周

    博客具体内容请移步博客园:http://www.cnblogs.com/ITOps/p/6227780.html

    Linux干货 2016-12-27
  • ansible运维自动化工具

      ansible简介 运维工具分类:         agent:基于专用的agent程序完成管理功能,puppet, func, zabbix, …        agent…

    Linux干货 2016-11-11
  • shell编程及小命令

    1. ping 10.1.252.25d2 -c1 -w1 &> /dev/null && echo "The host is up" || echo "The host is down" 2. 在vim命令中, p或则P可以实现复制。     p: 复制到下一行 &n…

    Linux干货 2016-08-12