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 文件管理命令

    cp 复制文件或者路径 单源复制: cp [OPTION]…[-T] SOUTCE DEST 如果DEST不存在:则事先创建此文件,并复制源文件的数据流到DEST中 如果DEST存在:   如果DEST是非目录文件:则覆盖目标文件; 如果DEST是目录,就在这个目录中创建一个同名的文件,把源数据复制到这个文件中。 多源复制: cp [O…

    Linux干货 2017-08-28
  • linux初步

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 文件管理命令 文件管理有哪些命令:ls, cd, pwd, mkdir, rmdir, cp, rm, mv, touch, cat, more, less, head, tail等,下面我们就来详细的说一下(只说常用的,不是命令全部) (1). ls 命令 1 2 3 4 5 6…

    Linux干货 2017-01-22
  • awk

    awk是一种编程语言,用于在linux/unix下对文本和数据进行处理。数据可以来自标准输入(stdin)、一个或多个文件,或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是linux/unix下的一个强大编程工具。它在命令行中使用,但更多是作为脚本来使用。awk有很多内建的功能,比如数组、函数等,这是它和C语言的相同之处,灵活性是awk最大的优势。

    Linux干货 2018-01-02
  • rsyslog将日志记录于MySQL中,并用loganalyzer进行分析日志

    1、首先来安装lamp环境的支持,与其相关的软件包      # yum -y install rsyslog-mysql mariadb-server php php-mysql php-gd httpd       说明:rsyslog-mysql在数据库中生成一个库文件,但这个文件需…

    Linux干货 2016-10-23
  • linux端口聚合

    一、bonding简介 bonding是一个linux kernel的driver,加载了它以后,linux支持将多个物理网卡捆绑成一个虚拟的bond网卡。     我们在很多地方会使用到物理网卡端口汇聚的功能,比如我们想提升网络速率,比如我们想提供热备份,比如我们想把我们的主机配置成一个网桥,然而最重要的还…

    Linux干货 2016-09-23
  • 第八周

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥(Bridge)是早期的两端口二层网络设备,用来连接不同网段。网桥的两个端口分别有一条独立的交换信道,不是共享一条背板总线,可隔离冲突域。网桥比集线器(Hub)性能更好,集线器上各端口都是共享同一条背板总线的。后来,网桥被具有更多端口、同时也可隔离冲突域的交换机(Switch…

    Linux干货 2016-09-19