一、systemd 与 systemctl 概述
1.1 从 SysVinit 到 systemd
Linux 系统的初始化系统经历了从传统的 SysVinit 到 Upstart,再到如今广泛使用的 systemd 的演进。systemd 由 Lennart Poettering 开发,采用并行启动、依赖管理和单元(Unit)抽象,显著提升了系统启动速度和管理灵活性。
systemctl 是 systemd 的主命令行工具,用于控制 systemd 系统和服务管理器。它提供了对系统状态、服务生命周期、电源管理和日志的统一操作接口。
1.2 核心概念:Unit(单元)
systemd 将系统需要管理的所有对象抽象为 Unit(单元)。每个单元由配置文件定义,存放在 /usr/lib/systemd/system/、/etc/systemd/system/ 等目录中。
#mermaid-svg-vxujBM7JsR9jC3zk{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-vxujBM7JsR9jC3zk .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-vxujBM7JsR9jC3zk .error-icon{fill:#552222;}#mermaid-svg-vxujBM7JsR9jC3zk .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-vxujBM7JsR9jC3zk .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-vxujBM7JsR9jC3zk .marker{fill:#333333;stroke:#333333;}#mermaid-svg-vxujBM7JsR9jC3zk .marker.cross{stroke:#333333;}#mermaid-svg-vxujBM7JsR9jC3zk svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-vxujBM7JsR9jC3zk p{margin:0;}#mermaid-svg-vxujBM7JsR9jC3zk .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-vxujBM7JsR9jC3zk .cluster-label text{fill:#333;}#mermaid-svg-vxujBM7JsR9jC3zk .cluster-label span{color:#333;}#mermaid-svg-vxujBM7JsR9jC3zk .cluster-label span p{background-color:transparent;}#mermaid-svg-vxujBM7JsR9jC3zk .label text,#mermaid-svg-vxujBM7JsR9jC3zk span{fill:#333;color:#333;}#mermaid-svg-vxujBM7JsR9jC3zk .node rect,#mermaid-svg-vxujBM7JsR9jC3zk .node circle,#mermaid-svg-vxujBM7JsR9jC3zk .node ellipse,#mermaid-svg-vxujBM7JsR9jC3zk .node polygon,#mermaid-svg-vxujBM7JsR9jC3zk .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-vxujBM7JsR9jC3zk .rough-node .label text,#mermaid-svg-vxujBM7JsR9jC3zk .node .label text,#mermaid-svg-vxujBM7JsR9jC3zk .image-shape .label,#mermaid-svg-vxujBM7JsR9jC3zk .icon-shape .label{text-anchor:middle;}#mermaid-svg-vxujBM7JsR9jC3zk .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-vxujBM7JsR9jC3zk .rough-node .label,#mermaid-svg-vxujBM7JsR9jC3zk .node .label,#mermaid-svg-vxujBM7JsR9jC3zk .image-shape .label,#mermaid-svg-vxujBM7JsR9jC3zk .icon-shape .label{text-align:center;}#mermaid-svg-vxujBM7JsR9jC3zk .node.clickable{cursor:pointer;}#mermaid-svg-vxujBM7JsR9jC3zk .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-vxujBM7JsR9jC3zk .arrowheadPath{fill:#333333;}#mermaid-svg-vxujBM7JsR9jC3zk .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-vxujBM7JsR9jC3zk .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-vxujBM7JsR9jC3zk .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-vxujBM7JsR9jC3zk .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-vxujBM7JsR9jC3zk .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-vxujBM7JsR9jC3zk .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-vxujBM7JsR9jC3zk .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-vxujBM7JsR9jC3zk .cluster text{fill:#333;}#mermaid-svg-vxujBM7JsR9jC3zk .cluster span{color:#333;}#mermaid-svg-vxujBM7JsR9jC3zk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-vxujBM7JsR9jC3zk .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-vxujBM7JsR9jC3zk rect.text{fill:none;stroke-width:0;}#mermaid-svg-vxujBM7JsR9jC3zk .icon-shape,#mermaid-svg-vxujBM7JsR9jC3zk .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-vxujBM7JsR9jC3zk .icon-shape p,#mermaid-svg-vxujBM7JsR9jC3zk .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-vxujBM7JsR9jC3zk .icon-shape .label rect,#mermaid-svg-vxujBM7JsR9jC3zk .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-vxujBM7JsR9jC3zk .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-vxujBM7JsR9jC3zk .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-vxujBM7JsR9jC3zk :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
systemd Unit 类型
.service
.timer
.socket
.target
.mount
.path
.slice
.scope
后台守护进程sshd / nginx / mysql
定时触发器替代传统 cron
套接字激活按需启动服务
运行目标替代 runlevel
文件系统挂载
路径监控文件变化触发
Cgroup 资源组
外部进程组
二、systemctl 基础命令体系
2.1 服务生命周期管理
这是 systemctl 最常用的功能,控制服务的启动、停止和重启。
#mermaid-svg-kNzIII2gLlP2DABT{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-kNzIII2gLlP2DABT .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-kNzIII2gLlP2DABT .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-kNzIII2gLlP2DABT .error-icon{fill:#552222;}#mermaid-svg-kNzIII2gLlP2DABT .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-kNzIII2gLlP2DABT .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-kNzIII2gLlP2DABT .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-kNzIII2gLlP2DABT .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-kNzIII2gLlP2DABT .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-kNzIII2gLlP2DABT .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-kNzIII2gLlP2DABT .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-kNzIII2gLlP2DABT .marker{fill:#333333;stroke:#333333;}#mermaid-svg-kNzIII2gLlP2DABT .marker.cross{stroke:#333333;}#mermaid-svg-kNzIII2gLlP2DABT svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-kNzIII2gLlP2DABT p{margin:0;}#mermaid-svg-kNzIII2gLlP2DABT .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-kNzIII2gLlP2DABT .cluster-label text{fill:#333;}#mermaid-svg-kNzIII2gLlP2DABT .cluster-label span{color:#333;}#mermaid-svg-kNzIII2gLlP2DABT .cluster-label span p{background-color:transparent;}#mermaid-svg-kNzIII2gLlP2DABT .label text,#mermaid-svg-kNzIII2gLlP2DABT span{fill:#333;color:#333;}#mermaid-svg-kNzIII2gLlP2DABT .node rect,#mermaid-svg-kNzIII2gLlP2DABT .node circle,#mermaid-svg-kNzIII2gLlP2DABT .node ellipse,#mermaid-svg-kNzIII2gLlP2DABT .node polygon,#mermaid-svg-kNzIII2gLlP2DABT .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-kNzIII2gLlP2DABT .rough-node .label text,#mermaid-svg-kNzIII2gLlP2DABT .node .label text,#mermaid-svg-kNzIII2gLlP2DABT .image-shape .label,#mermaid-svg-kNzIII2gLlP2DABT .icon-shape .label{text-anchor:middle;}#mermaid-svg-kNzIII2gLlP2DABT .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-kNzIII2gLlP2DABT .rough-node .label,#mermaid-svg-kNzIII2gLlP2DABT .node .label,#mermaid-svg-kNzIII2gLlP2DABT .image-shape .label,#mermaid-svg-kNzIII2gLlP2DABT .icon-shape .label{text-align:center;}#mermaid-svg-kNzIII2gLlP2DABT .node.clickable{cursor:pointer;}#mermaid-svg-kNzIII2gLlP2DABT .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-kNzIII2gLlP2DABT .arrowheadPath{fill:#333333;}#mermaid-svg-kNzIII2gLlP2DABT .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-kNzIII2gLlP2DABT .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-kNzIII2gLlP2DABT .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-kNzIII2gLlP2DABT .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-kNzIII2gLlP2DABT .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-kNzIII2gLlP2DABT .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-kNzIII2gLlP2DABT .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-kNzIII2gLlP2DABT .cluster text{fill:#333;}#mermaid-svg-kNzIII2gLlP2DABT .cluster span{color:#333;}#mermaid-svg-kNzIII2gLlP2DABT div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-kNzIII2gLlP2DABT .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-kNzIII2gLlP2DABT rect.text{fill:none;stroke-width:0;}#mermaid-svg-kNzIII2gLlP2DABT .icon-shape,#mermaid-svg-kNzIII2gLlP2DABT .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-kNzIII2gLlP2DABT .icon-shape p,#mermaid-svg-kNzIII2gLlP2DABT .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-kNzIII2gLlP2DABT .icon-shape .label rect,#mermaid-svg-kNzIII2gLlP2DABT .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-kNzIII2gLlP2DABT .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-kNzIII2gLlP2DABT .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-kNzIII2gLlP2DABT :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
系统响应
作用对象
动作指令
命令输入
systemctl
start
stop
restart
reload
enable
disable
status
服务单元.service
调用 systemd守护进程
执行单元配置ExecStart/ExecStop
更新系统状态写入 PID / 日志
常用生命周期命令:
| systemctl start <unit> | 启动单元 | ✅ | ❌ |
| systemctl stop <unit> | 停止单元 | ✅ | ❌ |
| systemctl restart <unit> | 重启单元 | ✅ | ❌ |
| systemctl reload <unit> | 平滑重载配置 | ✅ | ❌ |
| systemctl enable <unit> | 开机自启 | ❌ | ✅ |
| systemctl disable <unit> | 取消开机自启 | ❌ | ✅ |
| systemctl is-active <unit> | 检查是否运行 | – | – |
| systemctl is-enabled <unit> | 检查是否自启 | – | – |
2.2 服务状态转换模型
systemd 中每个服务单元都有明确的状态机。
#mermaid-svg-NKNc0DewcHR0onq0{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-NKNc0DewcHR0onq0 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-NKNc0DewcHR0onq0 .error-icon{fill:#552222;}#mermaid-svg-NKNc0DewcHR0onq0 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-NKNc0DewcHR0onq0 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-NKNc0DewcHR0onq0 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 .marker.cross{stroke:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-NKNc0DewcHR0onq0 p{margin:0;}#mermaid-svg-NKNc0DewcHR0onq0 defs #statediagram-barbEnd{fill:#333333;stroke:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 g.stateGroup text{fill:#9370DB;stroke:none;font-size:10px;}#mermaid-svg-NKNc0DewcHR0onq0 g.stateGroup text{fill:#333;stroke:none;font-size:10px;}#mermaid-svg-NKNc0DewcHR0onq0 g.stateGroup .state-title{font-weight:bolder;fill:#131300;}#mermaid-svg-NKNc0DewcHR0onq0 g.stateGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-NKNc0DewcHR0onq0 g.stateGroup line{stroke:#333333;stroke-width:1;}#mermaid-svg-NKNc0DewcHR0onq0 .transition{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-NKNc0DewcHR0onq0 .stateGroup .composit{fill:white;border-bottom:1px;}#mermaid-svg-NKNc0DewcHR0onq0 .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px;}#mermaid-svg-NKNc0DewcHR0onq0 .state-note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-NKNc0DewcHR0onq0 .state-note text{fill:black;stroke:none;font-size:10px;}#mermaid-svg-NKNc0DewcHR0onq0 .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-NKNc0DewcHR0onq0 .edgeLabel .label rect{fill:#ECECFF;opacity:0.5;}#mermaid-svg-NKNc0DewcHR0onq0 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-NKNc0DewcHR0onq0 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-NKNc0DewcHR0onq0 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-NKNc0DewcHR0onq0 .edgeLabel .label text{fill:#333;}#mermaid-svg-NKNc0DewcHR0onq0 .label div .edgeLabel{color:#333;}#mermaid-svg-NKNc0DewcHR0onq0 .stateLabel text{fill:#131300;font-size:10px;font-weight:bold;}#mermaid-svg-NKNc0DewcHR0onq0 .node circle.state-start{fill:#333333;stroke:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 .node .fork-join{fill:#333333;stroke:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 .node circle.state-end{fill:#9370DB;stroke:white;stroke-width:1.5;}#mermaid-svg-NKNc0DewcHR0onq0 .end-state-inner{fill:white;stroke-width:1.5;}#mermaid-svg-NKNc0DewcHR0onq0 .node rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-NKNc0DewcHR0onq0 .node polygon{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-NKNc0DewcHR0onq0 #statediagram-barbEnd{fill:#333333;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-cluster rect{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-NKNc0DewcHR0onq0 .cluster-label,#mermaid-svg-NKNc0DewcHR0onq0 .nodeLabel{color:#131300;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-cluster rect.outer{rx:5px;ry:5px;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-state .divider{stroke:#9370DB;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-state .title-state{rx:5px;ry:5px;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-cluster.statediagram-cluster .inner{fill:white;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-cluster.statediagram-cluster-alt .inner{fill:#f0f0f0;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-cluster .inner{rx:0;ry:0;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-state rect.basic{rx:5px;ry:5px;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#f0f0f0;}#mermaid-svg-NKNc0DewcHR0onq0 .note-edge{stroke-dasharray:5;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-note rect{fill:#fff5ad;stroke:#aaaa33;stroke-width:1px;rx:0;ry:0;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-note text{fill:black;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram-note .nodeLabel{color:black;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagram .edgeLabel{color:red;}#mermaid-svg-NKNc0DewcHR0onq0 #dependencyStart,#mermaid-svg-NKNc0DewcHR0onq0 #dependencyEnd{fill:#333333;stroke:#333333;stroke-width:1;}#mermaid-svg-NKNc0DewcHR0onq0 .statediagramTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-NKNc0DewcHR0onq0 :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
系统启动/单元创建
systemctl start
ExecStart 成功
ExecStart 失败 / 超时
systemctl stop
systemctl reload
ExecReload 成功
ExecStop 完成
ExecStop 失败
systemctl reset-failed
systemctl restart
inactive
activating
active
failed
deactivating
reloading
运行中状态进程 PID 已分配资源已加载
失败状态需查看日志排查journalctl -u unit
状态查看示例:
# 查看单个服务详细状态
systemctl status sshd.service
# 输出示例解析:
● sshd.service – OpenSSH server
Loaded: loaded (/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-01-15 09:23:17 CST; 2 weeks ago
Docs: man:sshd(8), man:sshd_config(5)
Main PID: 1234 (sshd)
Tasks: 1 (limit: 4915)
Memory: 5.2M
CGroup: /system.slice/sshd.service
└─1234 /usr/sbin/sshd -D
三、Unit 配置文件解析
3.1 服务单元文件结构
以 .service 为例,配置文件通常包含三个段落:[Unit]、[Service]、[Install]。
#mermaid-svg-a8gRF55KDpcsakLa{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-a8gRF55KDpcsakLa .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-a8gRF55KDpcsakLa .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-a8gRF55KDpcsakLa .error-icon{fill:#552222;}#mermaid-svg-a8gRF55KDpcsakLa .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-a8gRF55KDpcsakLa .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-a8gRF55KDpcsakLa .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-a8gRF55KDpcsakLa .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-a8gRF55KDpcsakLa .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-a8gRF55KDpcsakLa .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-a8gRF55KDpcsakLa .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-a8gRF55KDpcsakLa .marker{fill:#333333;stroke:#333333;}#mermaid-svg-a8gRF55KDpcsakLa .marker.cross{stroke:#333333;}#mermaid-svg-a8gRF55KDpcsakLa svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-a8gRF55KDpcsakLa p{margin:0;}#mermaid-svg-a8gRF55KDpcsakLa .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-a8gRF55KDpcsakLa .cluster-label text{fill:#333;}#mermaid-svg-a8gRF55KDpcsakLa .cluster-label span{color:#333;}#mermaid-svg-a8gRF55KDpcsakLa .cluster-label span p{background-color:transparent;}#mermaid-svg-a8gRF55KDpcsakLa .label text,#mermaid-svg-a8gRF55KDpcsakLa span{fill:#333;color:#333;}#mermaid-svg-a8gRF55KDpcsakLa .node rect,#mermaid-svg-a8gRF55KDpcsakLa .node circle,#mermaid-svg-a8gRF55KDpcsakLa .node ellipse,#mermaid-svg-a8gRF55KDpcsakLa .node polygon,#mermaid-svg-a8gRF55KDpcsakLa .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-a8gRF55KDpcsakLa .rough-node .label text,#mermaid-svg-a8gRF55KDpcsakLa .node .label text,#mermaid-svg-a8gRF55KDpcsakLa .image-shape .label,#mermaid-svg-a8gRF55KDpcsakLa .icon-shape .label{text-anchor:middle;}#mermaid-svg-a8gRF55KDpcsakLa .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-a8gRF55KDpcsakLa .rough-node .label,#mermaid-svg-a8gRF55KDpcsakLa .node .label,#mermaid-svg-a8gRF55KDpcsakLa .image-shape .label,#mermaid-svg-a8gRF55KDpcsakLa .icon-shape .label{text-align:center;}#mermaid-svg-a8gRF55KDpcsakLa .node.clickable{cursor:pointer;}#mermaid-svg-a8gRF55KDpcsakLa .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-a8gRF55KDpcsakLa .arrowheadPath{fill:#333333;}#mermaid-svg-a8gRF55KDpcsakLa .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-a8gRF55KDpcsakLa .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-a8gRF55KDpcsakLa .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-a8gRF55KDpcsakLa .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-a8gRF55KDpcsakLa .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-a8gRF55KDpcsakLa .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-a8gRF55KDpcsakLa .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-a8gRF55KDpcsakLa .cluster text{fill:#333;}#mermaid-svg-a8gRF55KDpcsakLa .cluster span{color:#333;}#mermaid-svg-a8gRF55KDpcsakLa div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-a8gRF55KDpcsakLa .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-a8gRF55KDpcsakLa rect.text{fill:none;stroke-width:0;}#mermaid-svg-a8gRF55KDpcsakLa .icon-shape,#mermaid-svg-a8gRF55KDpcsakLa .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-a8gRF55KDpcsakLa .icon-shape p,#mermaid-svg-a8gRF55KDpcsakLa .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-a8gRF55KDpcsakLa .icon-shape .label rect,#mermaid-svg-a8gRF55KDpcsakLa .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-a8gRF55KDpcsakLa .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-a8gRF55KDpcsakLa .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-a8gRF55KDpcsakLa :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
服务单元配置文件
Unit
DescriptionDocumentationAfter / Before / WantsRequires / Conflicts
Service
TypeExecStart / ExecStopRestartUser / GroupEnvironment
Install
WantedByRequiredBy
依赖与元数据
进程行为定义
开机挂载点
典型服务配置示例:
# /etc/systemd/system/myapp.service
[Unit]
Description=My Application Server
Documentation=https://example.com/docs
After=network.target postgresql.service
Requires=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/myapp –config /etc/myapp.conf
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID
Restart=on-failure
RestartSec=5s
User=appuser
Group=appgroup
Environment="APP_ENV=production"
EnvironmentFile=/etc/myapp/env
[Install]
WantedBy=multi-user.target
3.2 Service Type 详解
Type= 决定了 systemd 如何判断服务启动完成。
#mermaid-svg-DlNrLc164dqKw7pB{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-DlNrLc164dqKw7pB .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-DlNrLc164dqKw7pB .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-DlNrLc164dqKw7pB .error-icon{fill:#552222;}#mermaid-svg-DlNrLc164dqKw7pB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-DlNrLc164dqKw7pB .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-DlNrLc164dqKw7pB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-DlNrLc164dqKw7pB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-DlNrLc164dqKw7pB .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-DlNrLc164dqKw7pB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-DlNrLc164dqKw7pB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-DlNrLc164dqKw7pB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-DlNrLc164dqKw7pB .marker.cross{stroke:#333333;}#mermaid-svg-DlNrLc164dqKw7pB svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-DlNrLc164dqKw7pB p{margin:0;}#mermaid-svg-DlNrLc164dqKw7pB .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-DlNrLc164dqKw7pB .cluster-label text{fill:#333;}#mermaid-svg-DlNrLc164dqKw7pB .cluster-label span{color:#333;}#mermaid-svg-DlNrLc164dqKw7pB .cluster-label span p{background-color:transparent;}#mermaid-svg-DlNrLc164dqKw7pB .label text,#mermaid-svg-DlNrLc164dqKw7pB span{fill:#333;color:#333;}#mermaid-svg-DlNrLc164dqKw7pB .node rect,#mermaid-svg-DlNrLc164dqKw7pB .node circle,#mermaid-svg-DlNrLc164dqKw7pB .node ellipse,#mermaid-svg-DlNrLc164dqKw7pB .node polygon,#mermaid-svg-DlNrLc164dqKw7pB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-DlNrLc164dqKw7pB .rough-node .label text,#mermaid-svg-DlNrLc164dqKw7pB .node .label text,#mermaid-svg-DlNrLc164dqKw7pB .image-shape .label,#mermaid-svg-DlNrLc164dqKw7pB .icon-shape .label{text-anchor:middle;}#mermaid-svg-DlNrLc164dqKw7pB .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-DlNrLc164dqKw7pB .rough-node .label,#mermaid-svg-DlNrLc164dqKw7pB .node .label,#mermaid-svg-DlNrLc164dqKw7pB .image-shape .label,#mermaid-svg-DlNrLc164dqKw7pB .icon-shape .label{text-align:center;}#mermaid-svg-DlNrLc164dqKw7pB .node.clickable{cursor:pointer;}#mermaid-svg-DlNrLc164dqKw7pB .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-DlNrLc164dqKw7pB .arrowheadPath{fill:#333333;}#mermaid-svg-DlNrLc164dqKw7pB .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-DlNrLc164dqKw7pB .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-DlNrLc164dqKw7pB .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-DlNrLc164dqKw7pB .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-DlNrLc164dqKw7pB .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-DlNrLc164dqKw7pB .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-DlNrLc164dqKw7pB .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-DlNrLc164dqKw7pB .cluster text{fill:#333;}#mermaid-svg-DlNrLc164dqKw7pB .cluster span{color:#333;}#mermaid-svg-DlNrLc164dqKw7pB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-DlNrLc164dqKw7pB .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-DlNrLc164dqKw7pB rect.text{fill:none;stroke-width:0;}#mermaid-svg-DlNrLc164dqKw7pB .icon-shape,#mermaid-svg-DlNrLc164dqKw7pB .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-DlNrLc164dqKw7pB .icon-shape p,#mermaid-svg-DlNrLc164dqKw7pB .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-DlNrLc164dqKw7pB .icon-shape .label rect,#mermaid-svg-DlNrLc164dqKw7pB .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-DlNrLc164dqKw7pB .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-DlNrLc164dqKw7pB .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-DlNrLc164dqKw7pB :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
Service Type
simple
exec
forking
oneshot
dbus
notify
idle
ExecStart 主进程systemd 认为立即启动完成最常用
ExecStart 调用后execve 成功即算启动完成比 simple 更精确
经典守护进程模式父进程 fork 后退出需配 PIDFile
执行一次即退出常用于初始化脚本RemainAfterExit=yes
等待 D-Bus 名称出现服务注册 bus 后才算就绪
等待 sd_notify 信号服务主动通知就绪最精确但需代码支持
延迟到系统空闲时启动减少启动竞争
四、系统状态与电源管理
4.1 Target(目标):运行级别的新抽象
systemd 用 Target 替代了传统的 SysVinit runlevel(0-6)。
#mermaid-svg-YEGWAaLaGfDgKJPB{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-YEGWAaLaGfDgKJPB .error-icon{fill:#552222;}#mermaid-svg-YEGWAaLaGfDgKJPB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-YEGWAaLaGfDgKJPB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-YEGWAaLaGfDgKJPB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-YEGWAaLaGfDgKJPB .marker.cross{stroke:#333333;}#mermaid-svg-YEGWAaLaGfDgKJPB svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-YEGWAaLaGfDgKJPB p{margin:0;}#mermaid-svg-YEGWAaLaGfDgKJPB .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster-label text{fill:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster-label span{color:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster-label span p{background-color:transparent;}#mermaid-svg-YEGWAaLaGfDgKJPB .label text,#mermaid-svg-YEGWAaLaGfDgKJPB span{fill:#333;color:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB .node rect,#mermaid-svg-YEGWAaLaGfDgKJPB .node circle,#mermaid-svg-YEGWAaLaGfDgKJPB .node ellipse,#mermaid-svg-YEGWAaLaGfDgKJPB .node polygon,#mermaid-svg-YEGWAaLaGfDgKJPB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-YEGWAaLaGfDgKJPB .rough-node .label text,#mermaid-svg-YEGWAaLaGfDgKJPB .node .label text,#mermaid-svg-YEGWAaLaGfDgKJPB .image-shape .label,#mermaid-svg-YEGWAaLaGfDgKJPB .icon-shape .label{text-anchor:middle;}#mermaid-svg-YEGWAaLaGfDgKJPB .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-YEGWAaLaGfDgKJPB .rough-node .label,#mermaid-svg-YEGWAaLaGfDgKJPB .node .label,#mermaid-svg-YEGWAaLaGfDgKJPB .image-shape .label,#mermaid-svg-YEGWAaLaGfDgKJPB .icon-shape .label{text-align:center;}#mermaid-svg-YEGWAaLaGfDgKJPB .node.clickable{cursor:pointer;}#mermaid-svg-YEGWAaLaGfDgKJPB .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-YEGWAaLaGfDgKJPB .arrowheadPath{fill:#333333;}#mermaid-svg-YEGWAaLaGfDgKJPB .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-YEGWAaLaGfDgKJPB .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-YEGWAaLaGfDgKJPB .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-YEGWAaLaGfDgKJPB .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-YEGWAaLaGfDgKJPB .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-YEGWAaLaGfDgKJPB .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster text{fill:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB .cluster span{color:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-YEGWAaLaGfDgKJPB .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-YEGWAaLaGfDgKJPB rect.text{fill:none;stroke-width:0;}#mermaid-svg-YEGWAaLaGfDgKJPB .icon-shape,#mermaid-svg-YEGWAaLaGfDgKJPB .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-YEGWAaLaGfDgKJPB .icon-shape p,#mermaid-svg-YEGWAaLaGfDgKJPB .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-YEGWAaLaGfDgKJPB .icon-shape .label rect,#mermaid-svg-YEGWAaLaGfDgKJPB .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-YEGWAaLaGfDgKJPB .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-YEGWAaLaGfDgKJPB .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-YEGWAaLaGfDgKJPB :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
graphical.target图形界面
multi-user.target多用户命令行
basic.target基本系统初始化
sysinit.target系统初始化
local-fs.target本地文件系统就绪
rescue.target救援模式
emergency.target紧急模式
reboot.target重启
shutdown.target
poweroff.target关机
Target 切换命令:
systemctl isolate multi-user.target # 切换到命令行模式
systemctl isolate graphical.target # 切换到图形界面
systemctl rescue # 进入救援模式
systemctl emergency # 进入紧急模式
systemctl reboot # 重启系统
systemctl poweroff # 关机
4.2 查看默认 Target
systemctl get-default
# 输出: graphical.target 或 multi-user.target
systemctl set-default multi-user.target # 设置默认启动到命令行
五、依赖管理与启动顺序
5.1 依赖关系类型
systemd 通过多种指令定义单元间的依赖关系。
#mermaid-svg-GHOEjX15nBqnIPuJ{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-GHOEjX15nBqnIPuJ .error-icon{fill:#552222;}#mermaid-svg-GHOEjX15nBqnIPuJ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-GHOEjX15nBqnIPuJ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-GHOEjX15nBqnIPuJ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-GHOEjX15nBqnIPuJ .marker.cross{stroke:#333333;}#mermaid-svg-GHOEjX15nBqnIPuJ svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-GHOEjX15nBqnIPuJ p{margin:0;}#mermaid-svg-GHOEjX15nBqnIPuJ .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster-label text{fill:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster-label span{color:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster-label span p{background-color:transparent;}#mermaid-svg-GHOEjX15nBqnIPuJ .label text,#mermaid-svg-GHOEjX15nBqnIPuJ span{fill:#333;color:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ .node rect,#mermaid-svg-GHOEjX15nBqnIPuJ .node circle,#mermaid-svg-GHOEjX15nBqnIPuJ .node ellipse,#mermaid-svg-GHOEjX15nBqnIPuJ .node polygon,#mermaid-svg-GHOEjX15nBqnIPuJ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-GHOEjX15nBqnIPuJ .rough-node .label text,#mermaid-svg-GHOEjX15nBqnIPuJ .node .label text,#mermaid-svg-GHOEjX15nBqnIPuJ .image-shape .label,#mermaid-svg-GHOEjX15nBqnIPuJ .icon-shape .label{text-anchor:middle;}#mermaid-svg-GHOEjX15nBqnIPuJ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-GHOEjX15nBqnIPuJ .rough-node .label,#mermaid-svg-GHOEjX15nBqnIPuJ .node .label,#mermaid-svg-GHOEjX15nBqnIPuJ .image-shape .label,#mermaid-svg-GHOEjX15nBqnIPuJ .icon-shape .label{text-align:center;}#mermaid-svg-GHOEjX15nBqnIPuJ .node.clickable{cursor:pointer;}#mermaid-svg-GHOEjX15nBqnIPuJ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-GHOEjX15nBqnIPuJ .arrowheadPath{fill:#333333;}#mermaid-svg-GHOEjX15nBqnIPuJ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-GHOEjX15nBqnIPuJ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-GHOEjX15nBqnIPuJ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GHOEjX15nBqnIPuJ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-GHOEjX15nBqnIPuJ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GHOEjX15nBqnIPuJ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster text{fill:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ .cluster span{color:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-GHOEjX15nBqnIPuJ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-GHOEjX15nBqnIPuJ rect.text{fill:none;stroke-width:0;}#mermaid-svg-GHOEjX15nBqnIPuJ .icon-shape,#mermaid-svg-GHOEjX15nBqnIPuJ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GHOEjX15nBqnIPuJ .icon-shape p,#mermaid-svg-GHOEjX15nBqnIPuJ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-GHOEjX15nBqnIPuJ .icon-shape .label rect,#mermaid-svg-GHOEjX15nBqnIPuJ .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GHOEjX15nBqnIPuJ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-GHOEjX15nBqnIPuJ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-GHOEjX15nBqnIPuJ :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
Requires
Wants
After
Before
Conflicts
httpd.service
network.target
remote-fs.target
postgresql.service
nginx.service
firewalld.service
ufw.service
| Requires= | 强依赖 | 是(本单元失败) | 不控制顺序 |
| Wants= | 弱依赖 | 否 | 不控制顺序 |
| Requisite= | 存在性检查 | 是 | 启动前检查 |
| BindsTo= | 绑定依赖 | 是 | 依赖停止则本单元停止 |
| PartOf= | 部分依赖 | 是 | 仅控制 stop/restart |
| After= | 顺序在后 | – | 仅顺序,不建立依赖 |
| Before= | 顺序在前 | – | 仅顺序,不建立依赖 |
| Conflicts= | 互斥 | – | 启动时停止对方 |
5.2 依赖解析实例
# 查看服务的依赖树
systemctl list-dependencies sshd.service
# 反向依赖:谁依赖我
systemctl list-dependencies sshd.service –reverse
六、定时任务:Timer 单元
systemd Timer 是现代 Linux 替代 cron 的定时机制,具备更好的日志集成和依赖管理。
#mermaid-svg-a2RmBtnDbXU2N3bp{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-a2RmBtnDbXU2N3bp .error-icon{fill:#552222;}#mermaid-svg-a2RmBtnDbXU2N3bp .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-a2RmBtnDbXU2N3bp .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-a2RmBtnDbXU2N3bp .marker{fill:#333333;stroke:#333333;}#mermaid-svg-a2RmBtnDbXU2N3bp .marker.cross{stroke:#333333;}#mermaid-svg-a2RmBtnDbXU2N3bp svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-a2RmBtnDbXU2N3bp p{margin:0;}#mermaid-svg-a2RmBtnDbXU2N3bp .mermaid-main-font{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#mermaid-svg-a2RmBtnDbXU2N3bp .exclude-range{fill:#eeeeee;}#mermaid-svg-a2RmBtnDbXU2N3bp .section{stroke:none;opacity:0.2;}#mermaid-svg-a2RmBtnDbXU2N3bp .section0{fill:rgba(102, 102, 255, 0.49);}#mermaid-svg-a2RmBtnDbXU2N3bp .section2{fill:#fff400;}#mermaid-svg-a2RmBtnDbXU2N3bp .section1,#mermaid-svg-a2RmBtnDbXU2N3bp .section3{fill:white;opacity:0.2;}#mermaid-svg-a2RmBtnDbXU2N3bp .sectionTitle0{fill:#333;}#mermaid-svg-a2RmBtnDbXU2N3bp .sectionTitle1{fill:#333;}#mermaid-svg-a2RmBtnDbXU2N3bp .sectionTitle2{fill:#333;}#mermaid-svg-a2RmBtnDbXU2N3bp .sectionTitle3{fill:#333;}#mermaid-svg-a2RmBtnDbXU2N3bp .sectionTitle{text-anchor:start;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#mermaid-svg-a2RmBtnDbXU2N3bp .grid .tick{stroke:lightgrey;opacity:0.8;shape-rendering:crispEdges;}#mermaid-svg-a2RmBtnDbXU2N3bp .grid .tick text{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;fill:#333;}#mermaid-svg-a2RmBtnDbXU2N3bp .grid path{stroke-width:0;}#mermaid-svg-a2RmBtnDbXU2N3bp .today{fill:none;stroke:red;stroke-width:2px;}#mermaid-svg-a2RmBtnDbXU2N3bp .task{stroke-width:2;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskText{text-anchor:middle;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutsideRight{fill:black;text-anchor:start;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutsideLeft{fill:black;text-anchor:end;}#mermaid-svg-a2RmBtnDbXU2N3bp .task.clickable{cursor:pointer;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskText.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskText0,#mermaid-svg-a2RmBtnDbXU2N3bp .taskText1,#mermaid-svg-a2RmBtnDbXU2N3bp .taskText2,#mermaid-svg-a2RmBtnDbXU2N3bp .taskText3{fill:white;}#mermaid-svg-a2RmBtnDbXU2N3bp .task0,#mermaid-svg-a2RmBtnDbXU2N3bp .task1,#mermaid-svg-a2RmBtnDbXU2N3bp .task2,#mermaid-svg-a2RmBtnDbXU2N3bp .task3{fill:#8a90dd;stroke:#534fbc;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutside0,#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutside2{fill:black;}#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutside1,#mermaid-svg-a2RmBtnDbXU2N3bp .taskTextOutside3{fill:black;}#mermaid-svg-a2RmBtnDbXU2N3bp .active0,#mermaid-svg-a2RmBtnDbXU2N3bp .active1,#mermaid-svg-a2RmBtnDbXU2N3bp .active2,#mermaid-svg-a2RmBtnDbXU2N3bp .active3{fill:#bfc7ff;stroke:#534fbc;}#mermaid-svg-a2RmBtnDbXU2N3bp .activeText0,#mermaid-svg-a2RmBtnDbXU2N3bp .activeText1,#mermaid-svg-a2RmBtnDbXU2N3bp .activeText2,#mermaid-svg-a2RmBtnDbXU2N3bp .activeText3{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .done0,#mermaid-svg-a2RmBtnDbXU2N3bp .done1,#mermaid-svg-a2RmBtnDbXU2N3bp .done2,#mermaid-svg-a2RmBtnDbXU2N3bp .done3{stroke:grey;fill:lightgrey;stroke-width:2;}#mermaid-svg-a2RmBtnDbXU2N3bp .doneText0,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText1,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText2,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText3{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .doneText0.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText0.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText1.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText1.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText2.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText2.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText3.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneText3.taskTextOutsideRight{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .crit0,#mermaid-svg-a2RmBtnDbXU2N3bp .crit1,#mermaid-svg-a2RmBtnDbXU2N3bp .crit2,#mermaid-svg-a2RmBtnDbXU2N3bp .crit3{stroke:#ff8888;fill:red;stroke-width:2;}#mermaid-svg-a2RmBtnDbXU2N3bp .activeCrit0,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCrit1,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCrit2,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCrit3{stroke:#ff8888;fill:#bfc7ff;stroke-width:2;}#mermaid-svg-a2RmBtnDbXU2N3bp .doneCrit0,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCrit1,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCrit2,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCrit3{stroke:#ff8888;fill:lightgrey;stroke-width:2;cursor:pointer;shape-rendering:crispEdges;}#mermaid-svg-a2RmBtnDbXU2N3bp .milestone{transform:rotate(45deg) scale(0.8,0.8);}#mermaid-svg-a2RmBtnDbXU2N3bp .milestoneText{font-style:italic;}#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText0,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText1,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText2,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText3{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText0.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText0.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText1.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText1.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText2.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText2.taskTextOutsideRight,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText3.taskTextOutsideLeft,#mermaid-svg-a2RmBtnDbXU2N3bp .doneCritText3.taskTextOutsideRight{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .vert{stroke:navy;}#mermaid-svg-a2RmBtnDbXU2N3bp .vertText{font-size:15px;text-anchor:middle;fill:navy!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .activeCritText0,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCritText1,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCritText2,#mermaid-svg-a2RmBtnDbXU2N3bp .activeCritText3{fill:black!important;}#mermaid-svg-a2RmBtnDbXU2N3bp .titleText{text-anchor:middle;font-size:18px;fill:#333;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}#mermaid-svg-a2RmBtnDbXU2N3bp :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}00000111112日历触发 系统启动后 固定时间点执行 单元激活后 定时器激活后 RealtimeTimerMonotonicTimerTimer 触发模式对比
Timer 配置示例:
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily Backup Timer
[Timer]
OnCalendar=daily # 每天执行
OnCalendar=*-*-* 02:00:00 # 每天凌晨2点
Persistent=true # 如果错过,开机后补执行
Unit=backup.service
[Install]
WantedBy=timers.target
# 查看所有定时器
systemctl list-timers –all
# 输出列说明:
# NEXT LEFT LAST PASSED UNIT ACTIVATES
# Tue 09:00 3h 20min Mon 09:00 20h ago backup.timer backup.service
七、日志管理:journalctl
systemd 集成了日志系统 journald,通过 journalctl 查询。
渲染错误: Mermaid 渲染失败: Lexical error on line 3. Unrecognized text.
…log/journal内存日志] B –> D[/var/l
———————–^
常用 journalctl 命令:
journalctl -u nginx.service # 查看 nginx 服务日志
journalctl -u nginx -f # 实时跟踪
journalctl –since "1 hour ago" # 最近1小时
journalctl –since today –until now # 今天至今
journalctl -p err # 仅错误级别
journalctl –vacuum-time=7d # 清理7天前日志
journalctl –disk-usage # 查看日志占用空间
八、高级用法与故障排查
8.1 环境变量与参数传递
# 查看服务的环境变量
systemctl show sshd.service -p Environment
# 查看服务执行命令
systemctl show sshd.service -p ExecStart
# 查看服务运行用户
systemctl show sshd.service -p User -p Group
8.2 故障排查流程
#mermaid-svg-84WkFQ75fV5mcrMH{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-84WkFQ75fV5mcrMH .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-84WkFQ75fV5mcrMH .error-icon{fill:#552222;}#mermaid-svg-84WkFQ75fV5mcrMH .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-84WkFQ75fV5mcrMH .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-84WkFQ75fV5mcrMH .marker{fill:#333333;stroke:#333333;}#mermaid-svg-84WkFQ75fV5mcrMH .marker.cross{stroke:#333333;}#mermaid-svg-84WkFQ75fV5mcrMH svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-84WkFQ75fV5mcrMH p{margin:0;}#mermaid-svg-84WkFQ75fV5mcrMH .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-84WkFQ75fV5mcrMH .cluster-label text{fill:#333;}#mermaid-svg-84WkFQ75fV5mcrMH .cluster-label span{color:#333;}#mermaid-svg-84WkFQ75fV5mcrMH .cluster-label span p{background-color:transparent;}#mermaid-svg-84WkFQ75fV5mcrMH .label text,#mermaid-svg-84WkFQ75fV5mcrMH span{fill:#333;color:#333;}#mermaid-svg-84WkFQ75fV5mcrMH .node rect,#mermaid-svg-84WkFQ75fV5mcrMH .node circle,#mermaid-svg-84WkFQ75fV5mcrMH .node ellipse,#mermaid-svg-84WkFQ75fV5mcrMH .node polygon,#mermaid-svg-84WkFQ75fV5mcrMH .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-84WkFQ75fV5mcrMH .rough-node .label text,#mermaid-svg-84WkFQ75fV5mcrMH .node .label text,#mermaid-svg-84WkFQ75fV5mcrMH .image-shape .label,#mermaid-svg-84WkFQ75fV5mcrMH .icon-shape .label{text-anchor:middle;}#mermaid-svg-84WkFQ75fV5mcrMH .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-84WkFQ75fV5mcrMH .rough-node .label,#mermaid-svg-84WkFQ75fV5mcrMH .node .label,#mermaid-svg-84WkFQ75fV5mcrMH .image-shape .label,#mermaid-svg-84WkFQ75fV5mcrMH .icon-shape .label{text-align:center;}#mermaid-svg-84WkFQ75fV5mcrMH .node.clickable{cursor:pointer;}#mermaid-svg-84WkFQ75fV5mcrMH .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-84WkFQ75fV5mcrMH .arrowheadPath{fill:#333333;}#mermaid-svg-84WkFQ75fV5mcrMH .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-84WkFQ75fV5mcrMH .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-84WkFQ75fV5mcrMH .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-84WkFQ75fV5mcrMH .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-84WkFQ75fV5mcrMH .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-84WkFQ75fV5mcrMH .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-84WkFQ75fV5mcrMH .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-84WkFQ75fV5mcrMH .cluster text{fill:#333;}#mermaid-svg-84WkFQ75fV5mcrMH .cluster span{color:#333;}#mermaid-svg-84WkFQ75fV5mcrMH div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-84WkFQ75fV5mcrMH .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-84WkFQ75fV5mcrMH rect.text{fill:none;stroke-width:0;}#mermaid-svg-84WkFQ75fV5mcrMH .icon-shape,#mermaid-svg-84WkFQ75fV5mcrMH .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-84WkFQ75fV5mcrMH .icon-shape p,#mermaid-svg-84WkFQ75fV5mcrMH .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-84WkFQ75fV5mcrMH .icon-shape .label rect,#mermaid-svg-84WkFQ75fV5mcrMH .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-84WkFQ75fV5mcrMH .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-84WkFQ75fV5mcrMH .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-84WkFQ75fV5mcrMH :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
systemctl status unit
是
否
权限拒绝
找不到文件
端口占用
是
否
服务启动失败
查看状态
分析错误信息
Active: failed?
journalctl -u unit
检查依赖
日志提示?
检查 User/Group文件权限
检查 ExecStart 路径
检查 Conflicts网络绑定
systemctl list-dependencies
依赖失败?
递归排查上游单元
检查 After/Before 死锁
8.3 常用诊断命令速查
# 1. 查看失败单元
systemctl –failed
# 2. 重置失败状态
systemctl reset-failed
# 3. 查看单元加载问题
systemctl list-unit-files –state=enabled
# 4. 验证配置语法
systemd-analyze verify /etc/systemd/system/myunit.service
# 5. 分析启动耗时
systemd-analyze blame # 各服务耗时排名
systemd-analyze critical-chain # 关键路径
# 6. 编辑单元配置
systemctl edit –full nginx.service # 完整覆盖
systemctl edit nginx.service # 创建 drop-in 覆盖
# 7. 守护进程重载
systemctl daemon-reload # 修改配置后必须执行
九、完整命令索引
#mermaid-svg-Vs7x80YZPGpQeI0t{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Vs7x80YZPGpQeI0t .error-icon{fill:#552222;}#mermaid-svg-Vs7x80YZPGpQeI0t .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Vs7x80YZPGpQeI0t .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Vs7x80YZPGpQeI0t .marker.cross{stroke:#333333;}#mermaid-svg-Vs7x80YZPGpQeI0t svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Vs7x80YZPGpQeI0t p{margin:0;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge{stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 text{fill:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon–1{font-size:40px;color:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge–1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth–1{stroke-width:17;}#mermaid-svg-Vs7x80YZPGpQeI0t .section–1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-0{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-0{stroke-width:14;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-1{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-1{stroke-width:11;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 text{fill:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-2{stroke-width:8;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-3{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-3{stroke-width:5;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-4{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-4{stroke-width:2;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-5{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-5{stroke-width:-1;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-6{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-6{stroke-width:-4;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-7{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-7{stroke-width:-7;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-8{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-8{stroke-width:-10;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-9{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-9{stroke-width:-13;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 polygon,#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 text{fill:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .node-icon-10{font-size:40px;color:black;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .edge-depth-10{stroke-width:-16;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled circle,#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:lightgray;}#mermaid-svg-Vs7x80YZPGpQeI0t .disabled text{fill:#efefef;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-root rect,#mermaid-svg-Vs7x80YZPGpQeI0t .section-root path,#mermaid-svg-Vs7x80YZPGpQeI0t .section-root circle,#mermaid-svg-Vs7x80YZPGpQeI0t .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-Vs7x80YZPGpQeI0t .section-root text{fill:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-root span{color:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .section-2 span{color:#ffffff;}#mermaid-svg-Vs7x80YZPGpQeI0t .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-Vs7x80YZPGpQeI0t .edge{fill:none;}#mermaid-svg-Vs7x80YZPGpQeI0t .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-Vs7x80YZPGpQeI0t :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}
systemctl
服务控制
start
stop
restart
reload
kill
开机管理
enable
disable
is-enabled
reenable
状态查询
status
is-active
is-failed
show
list-units
list-unit-files
依赖管理
list-dependencies
add-wants
add-requires
电源管理
reboot
poweroff
suspend
hibernate
系统控制
daemon-reload
daemon-reexec
set-default
get-default
isolate
十、总结
systemctl 是现代 Linux 系统管理的核心工具,它将服务生命周期、依赖解析、定时任务、日志查询和电源管理统一在一致的命令接口下。掌握 systemctl 意味着:
对于系统管理员和运维工程师,熟练运用 systemctl 是保障服务高可用性和系统稳定性的基础技能。



