systemctl命令手册
提示
systemctl 是用于管理 systemd 系统和服务的命令行工具。systemd 是 Linux 系统中的初始化系统和服务管理器,systemctl 提供了与 systemd 交互的接口,用于启动、停止、重启服务以及查看服务状态等操作。
原理
systemctl 基于 systemd,通过与 systemd 通信来控制系统服务的运行状态。它可以管理单个服务单元,也可以对系统进行管理,如重启、关机等操作。
使用场景
- 启动、停止、重启系统服务
- 查看服务状态、日志和依赖关系
- 启用或禁用服务的自动启动
- 管理系统运行级别
常用 systemctl 命令及示例
以下是一些常用的 systemctl
命令及示例,帮助您管理系统服务:
- 启动服务:
sudo systemctl start service_name
- 停止服务:
sudo systemctl stop service_name
- 重启服务:
sudo systemctl restart service_name
- 查看服务状态:
systemctl status service_name
- 启用服务自动启动:
sudo systemctl enable service_name
- 禁用服务自动启动:
sudo systemctl disable service_name
另外,以下是更多 systemctl
的常用示例:
- 查看所有正在运行的服务:
systemctl list-units --type=service --state=running
- 查看所有已启用的服务:
systemctl list-unit-files --type=service --state=enabled
- 查看服务日志:
journalctl -u service_name
- 重载 systemd 配置:
systemctl daemon-reload
- 查看系统默认 target:
systemctl get-default
- 设置系统默认 target:
systemctl set-default target_name