在使用 RockyLinux(一个与 RHEL 完全兼容的开源 Linux 发行版)时,你经常会遇到需要启动、停止或查看系统服务的情况。这时,systemctl 命令就是你的得力助手!本文将带你从零开始,详细讲解 RockyLinux systemctl命令 的基本用法,帮助你轻松掌握 RockyLinux服务管理 的核心技能。
systemctl 是 systemd 系统和服务管理器的主要命令行工具。它用于控制系统服务(如 Apache、MySQL、SSH 等)的启动、停止、重启、启用/禁用等操作。自 CentOS 7 和 RockyLinux 8 起,systemd 已成为默认的初始化系统,取代了旧的 SysV init。
要查看某个服务当前是否正在运行,可以使用:
$ sudo systemctl status httpd 输出会显示服务是否 active(活跃)、运行时间、进程 ID、日志片段等信息。
以下是控制服务运行状态的基本命令:
# 启动服务$ sudo systemctl start httpd# 停止服务$ sudo systemctl stop httpd# 重启服务(先停止再启动)$ sudo systemctl restart httpd# 重新加载配置文件(不中断服务)$ sudo systemctl reload httpd
如果你希望某个服务在系统启动时自动运行(例如 Web 服务器),可以使用:
# 启用开机自启$ sudo systemctl enable httpd# 禁用开机自启$ sudo systemctl disable httpd
注意:enable 和 disable 不会立即启动或停止服务,只影响下次系统启动时的行为。
查看系统中所有已加载的服务:
$ systemctl list-units --type=service --all 你可以结合 grep 来过滤特定服务,例如:
$ systemctl list-units --type=service | grep running sudo。httpd、sshd、firewalld,可通过 ls /usr/lib/systemd/system/ 查看所有可用服务单元文件。journalctl -u 服务名 查看详细日志。通过本教程,你应该已经掌握了 systemctl使用教程 中的核心命令,并能熟练进行 Linux系统服务控制。无论是日常运维还是故障排查,systemctl 都是你不可或缺的工具。建议多在测试环境中练习,加深理解。
提示:本文适用于 RockyLinux 8/9 及其他基于 systemd 的 Linux 发行版(如 CentOS Stream、AlmaLinux 等)。
本文由主机测评网于2025-12-12发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025126466.html