Linux 中的 Systemctl 命令:重启、重新加载和停止服务
Systemctl 命令:在 Linux 中重启、重新加载和停止服务
在使用 systemd 作为 init system 的现代 Linux distributions 中,管理服务通常使用 systemctl command。无论你是维护 web server 的 administrator,还是测试 application changes 的 developer,了解如何重启、重新加载和停止服务都至关重要。
本文通过实际示例拆解最常见的 systemctl commands。
什么是 systemctl?
systemctl 是用于控制 systemd system and service manager 的 command-line utility。它允许你在系统上启动、停止、重启、重新加载、启用、禁用和监控 services。
1. 重启服务
当你想要 完全停止然后再次启动 一个 service 时使用此命令。在修改 configuration changes 后,或当 service 变得无响应时,它很有用。
语法:
sudo systemctl restart <service-name>示例:
sudo systemctl restart nginx2. 重新加载服务
reload 会告诉 service 在不重启整个 process 的情况下重新加载其 configuration。并非所有 services 都支持此功能。
语法:
提示:
你可以检查某个 service 是否支持 reload:
结论
掌握像 systemctl 这样的命令,以及 restart、reload 和 stop,是高效管理 Linux 中 services 的关键。它们让你能够应用 updates、修复 issues,并精确控制 system behavior。
始终记得使用以下命令验证更改:


