使用 systemctl 管理 Linux 服务
使用 systemctl 管理 Linux 服务 Systemd 是大多数现代 Linux 发行版的默认初始化系统。systemctl 命令是管理服务的主要工具。本文介绍最常用的操作。 1. 查看服务状态 查看某个服务是否正在运行: systemctl status nginx 输出中包含活动状态、主进程 PID、内存占用和最近的日志条目。绿色的 active running 表示服务运行正常。 列出所有正在运行的服务: systemctl list-units --type=service --state=running 2. 启动和停止服务 立即启动服务: systemctl start nginx 停止正在运行的服务: systemctl stop nginx 重启服务: systemctl restart nginx 在不完全重启的情况下重新加载配置: systemctl reload nginx 3. 启用和禁用服务 启用服务使其在开机时自动启动: systemctl enable nginx 禁用服务使其不在开机时启动: systemctl disable nginx 一条命令同时启用并启动: systemctl enable --now nginx 4. 使用 journalctl 查看日志 Systemd 通过 journald 收集日志。查看特定服务的日志: ...