【systemd】

systemd

2022-8-1

简介

系统启动和服务器守护进程管理器,负责在系统启动或运行时,激活系统资源,服务器进程和其它进程。
新特性systemd 是 linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度。systemd 和 ubuntu 的 upstart 是竞争对手,但是时至今日 ubuntu 也采用了 systemd,所以 systemd 在竞争中胜出,大有一统天下的趋势。其实,systemd 的很多概念都来源于苹果 Mac OS 操作系统上的 launchd。
systemd 的优点是功能强大,使用方便,缺点是体系庞大,非常复杂。
在这里插入图片描述

systmed的配置文件

/usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/init.d/
/run/systemd/system:系统执行过程中所产生的服务脚本,比上面目录优先运行
/etc/systemd/system:管理员建立的执行脚本,类似于/etc/rcN.d/Sxx的功能,比上面目录优先运行

systemd的Unit类型

systemctl -t help:查看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,用于定义文件系统中的一个文件或目录使用,常用于当文件系统变化时,延迟激活服务,如:spool 目录

systemd的管理服务

语法: systemctl COMMAND name.service

管理服务

启动

systemctl start name.service,相当于Centos6的service name.service start

停止

sysytemctl stop name.service,相当于Centos6的service name.service stop

重启

systemctl restart name.service,相当于Centos6的service name.service restart

状态

systemctl status name.service,相当于Centos6的service name.service status

条件式重启:已启动才重启,否则不做操作

sysytmectl try-restart name.service,相当于Centos6的service name condrestart

重载或重启服务:先加载,再启动

systmenctl reload-or-restart name.service

重载或条件式重启服务:

sysytemctl reload-or-try-restart name.service

禁止自启动和手动启动

systemctl mask name.service

取消禁止自启动和手动启动

systmectl unmask name.service

查看某服务当前激活与否的状态

sytemctl is-active name.service

查看所有已经激活的服务

systemctl list-units -type service
systemctl list-units -t service

查看所有服务

systemctl list-units -t service -a or -all

设置服务开机状态

设定某服务开机自启动

systemctl enable name.service,相当于Centos6的chkconfig name on

设定某服务开机禁止自启动

systemctl disable name.service,相当于Centos6的chkconfig name off

查看所有服务的开机自启状态

systemctl list-unit-files,相当于Centos6的 chkconfig --list

用来列出该服务在哪些运行级别下启用和禁用

ls /etc/systemd/system/*wants/sshd.service,相当于Centos6的 chkconfig sshd --list

实验:设置服务自启和禁止自启

[root@Centos8 ~]#systemctl list-unit-files | grep httpd
httpd.service                                             disabled

#查看httpd服务原来状态是禁止自启

[root@Centos8 ~]#systemctl enable httpd

感谢阅读,祝君成功!
-by aiziyou

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jack.Jia

感谢打赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值