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

相关推荐

  • Linux 用户、用户组及权限管理

    一、Linux用户及用户组的基本概念 用户:用户是实现能够将有限的资源在多个使用者之间进行分配;、 用户组:用户组是指多个用户的集合,方便对一类需要同样权限的用户授权 Linux是多用户、多任务的操作系统。     多用户指:多人同时使用系统资源;多任务:同时运行多个进程 二、用户及用户组类别 1、用户:名称解析库 /…

    Linux干货 2016-03-20
  • Centos7 编译安装 zabbix3.0

    服务安装配置: 系统版本:CentOS Linux release 7.2.1511 (Core)   zabbix 安装 关闭firewall:   systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机…

    Linux干货 2016-06-23
  • rsyslog日志记录服务器

    rsyslog日志记录服务器 部分思路总结摘自网络http://xuding.blog.51cto.com/4890434/1737947 一、syslog系统 1.syslog:系统日志服务,统一日志管理 支持C/S架构:可通过UDP或TCP协议提供日志记录服务;实现集中收集日志功能 (1)日志、事件 历史事件日志,保存系统上过去一段时间的发生的事件 事件…

    Linux干货 2016-11-07
  • 位置变量在Shell脚本编程中的作用

    位置变量:         如果要向一个shell脚本传递信息,可以使用位置参数完成此功能;参数相关数目传入脚本,此数目可以任意多,但只有前9个可以被访问,使用shift命令可以改变这个限制;参数从第一个开始,在第九个结束;每个访问参数前要加$符号;第一个参数为0,表示预留保存实…

    Linux干货 2016-08-15
  • 马哥教育网络班20期+第三周课程练习

    1. 列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [oracle@ocp ~]$ who root     pts/1        2016-06-26 …

    Linux干货 2016-06-26
  • 2016-11-4作业

    1、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项  mkfs.ext4 -b 2048  -L "TEST" -m 1 /dev/sdb6 2、写一个脚本,完成如下功能: (1) 列出当前系统识别到…

    Linux干货 2016-11-06