linux总结-systemctl
介绍
systemctl 是 Linux 系统中用于管理 systemd 系统和服务管理器的核心命令,用于控制系统服务的启动、停止、重启、状态查询等操作。systemd 是大多数现代 Linux 发行版(如 Ubuntu 16.04+、CentOS 7+、Debian 8+)的默认初始化系统,替代了传统的 SysV init。
常用命令
列出所有服务
systemctl list-units --type=service # 显示所有已加载的服务
systemctl list-unit-files # 显示所有服务的启用状态
启动/停止/重启服务
sudo systemctl start <服务名> # 启动服务
sudo systemctl stop <服务名> # 停止服务
sudo systemctl restart <服务名> # 重启服务
sudo systemctl reload <服务名> # 重新加载配置(不重启)
启用/禁用开机自启
sudo systemctl enable <服务名> # 启用开机自启
sudo systemctl disable <服务名> # 禁用开机自启
检查服务状态
systemctl status <服务名> # 查看服务状态(运行中/失败/日志)
systemctl is-active <服务名> # 检查服务是否正在运行
其他说明
bash: systemctl: command not found
这是因为你的系统 没有使用 systemd 作为初始化系统(init system),或者 systemctl 可执行文件未正确安装或不在 PATH 环境变量中。
systemctl 是 systemd 的配套工具,而你的系统 没有运行 systemd(PID 1 是 sh),因此自然没有 systemctl 命令。
检查初始化系统:
ps -p 1 -o comm=
如果输出是 systemd,但 systemctl 仍不可用,可能是安装损坏(见下文)。
如果输出是 init、runit、sh 或其他,说明系统未使用 systemd。
如果输出的是sh,说明系统直接启动 Shell

浙公网安备 33010602011771号