• 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

  • 相关阅读:
    c4d渲染动画可以暂停吗?c4d云渲染动画怎么暂停
    网页加载有哪些事件
    SpringMVC的常用注解,参数传递以及页面跳转的使用
    2023国赛 C题论文 蔬菜类商品自动定价与补货策略
    医疗制药行业数字化创新实践
    Java框架总结三
    【链接装载与库】动态链接(上)
    组合电路、触发器、时序电路
    Mybatis与Spring集成、Aop整合pagehelper插件
    加密算法笔记
  • 原文地址:https://blog.csdn.net/qq_27094347/article/details/127108592