1. Linux操作系统的系统和服务管理器, 向后兼容SysV init脚本,提供很多功能:启动时并行启动系统服务、按需激活守护进程,基于依赖的服务,替换Upstart默认初始化系统
  2. systemd units概念,以unit配置文件形式列出,封装系统服务信息,监听sockets等等,
  3. /etc/systemd/system.conf作为systemd的配置文件
  4. 主要功能:
  5. Socket-based activation 启动时刻,systemd为满足改激活模式的服务建立sockets, 并当服务启动后进行连接,这样不仅可以以并行模式启动服务,而且当服务中断时不会丢失数据,外部数据仍处于sockets中并以队列方式等待连接。

可用的systemd units类型:

unit type File Extension Description
Service unit .service a system service
target unit .target a group of systemd unit
Socket unit .socket 内部进程通信的socket

systemd units位置:

Path Description
/usr/lib/systemd/system/ 安装rpm包分发的系统units
/run/systemd/system/ 运行时创建的systemd units 文件,优先级比前者高
/etc/systemd/system/ 通过systemctl enable创建的systemd units符号链接文件,优先级比前者高

Systemctl

参考: https://access.redhat.com/documentation/en-us/red-hat-enterprise-linux/8/guide/e561e1ee-2011-4664-a627-eb8fb4063963#_fe843ad6-40ad-472d-91db-55db31d67a5c

systemctl的作用?
systemctl用于管理service, systemctl用于控制着不同的service, 这些service用于启动不同的任务。

相关操作?

  1. 停止服务
    systemctl stop vsftpd
    

    vsftpd可以是别名,使用以下命令查看: systemctl show vstfpd -p Names

  1. 相关命令

    systemctl try-start <name>
    # 当且仅当服务处于running状态重启service
    systemctl reload <name>
    # 重新加载配置文件,并不会中断service执行。
    # system service不支持该选项请使用reload-or-restart或reload-or-try-restart选项
    systemctl status <name>
    systemctl is-active <name>
    # 查询服务是否运行正常, 正常则返回状态为0
    systemctl is-enable <name>
    # 服务是否开机启动, 正常则返回状态为0
    systemctl list-units --type service --all
    # 查看本机所有service的状态, 没有--all会查看所有loaded且状态非in-active的service
    systemctl list-unit-files --type service
    # 查询所有有效service units的状态为enabled/disabled
    systemctl list-dependencies --after | --before <name>
    # 查询service依赖的service项, --after表示在service启动前的依赖service
    systemctl start <name>
    systemctl restart <name>
    systemctl enable <name>
    # 相关操作如下:
    # 1. 读取service unit的Install Section
    # 2. 创建/usr/lib/systemd/system/name.service的符号链接文件到/etc/systemd/system/的对应子目录当中, 当符号链接文件已经存在不会创建
    systemctl reenable <name>
    # disable再enable<name>
    systemctl disable <name>
    # 读取servoce Install Section并移除对应符号链接文件
    systemctl mask <name>
    # 隐藏对应service, 创建/etc/systemd/system/name.service -> /dev/null
    systemctl unmask <name>
    
  2. dependencies

存在positive和negative dependencies两种,positive dependencies表示启动service会开启的其它服务,negative表示启动service会停止其它的服务。
在启动service, systemd会解析service dependencies并控制对应依赖项。