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已不再只是一款自由操作系统,它还承载了许多企业的核心应用。在对比流行的Linux发行版时,不仅要考虑有吸引力的功能集,还要关注系统的支持与服务。 服务器管理员担心操作系统的维护和支持周期。维护生命周期指的是Linux发行版持续提供产品补丁和更新的时间。支持方面…

    Linux干货 2016-10-31
  • 密码保护:测试信息, 顺便贴上以前年少轻狂的内容.(未整理)

    无法提供摘要。这是一篇受保护的文章。

    Linux干货 2017-07-11
  • HAProxy 入门及基础负载应用

    A、首介 。。。         HAProxy——开放源代码软件,是一款代理服务器和伪4层的负载均衡软件解决方案。基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持高并发链接,它的工作模式可以将其简单而安全地整合到当前的服务架构中,同时可以保护你的WEB服务器不暴露到…

    Linux干货 2017-05-17
  • shell脚本编程之数组

       数组就是相同数据类型的元素按一定顺序排列的集合,就是把有限个类型相同的变量用一个名字命名,然后用编号区分他们的变量的集合,这个名字称为数组名,编号称为下标。组成数组的各个变量称为数组的元素。数组是在程序设计中,为了处理方便, 把具有相同类型的若干变量按有序的形式组织起来的一种形式。 一、数组的表示方式   1、下标数组 &…

    Linux干货 2016-01-05
  • grep与正则表达式

    一、grep        grep常用于文本搜索。通过自定义的模式(pattern),筛选出使用者需要的文本内容。除了有grep,还有egrep和fgrep。其中egrep = grep  –E,而fgrep则是不支持正则表达式。     &nbs…

    2017-07-29
  • LVS入门

    随着互联网进入寻常百姓家,网络流量愈来愈大,大规模的网路访问如果都使用一个服务器提供服务,那么网络通讯注定会拥堵不堪。为了解决这些问题,达到使网络流量均衡地分散到各个服务器上的目的,一些技术大牛发明了LVS负载均衡技术。   LVS简介   LVS(Linux Virtual Server)即为Linux虚拟服务器,使由章文嵩博士主导开发…

    Linux干货 2017-05-09