本篇文章将介绍如何使用systemctl命令管理systemd服务。Systemd是基于Linux的操作系统的系统和服务管理器,用于管理服务。Systemd比旧的Sysvinit更强大,更受欢迎。
大多数基于Linux的操作系统(例如:CentOS/Redhat 7、Fedora 25、Ubuntu 16.04)的更新版本都使用Systemd作为默认的服务管理工具。
在使用以下示例命令之前,需要使用实际的服务名(如httpd、mysql、apache2或ssh)更改。
启动或停止服务:
语法:$ sudo systemctl start .service
$ sudo systemctl stop .service
start: 用于启动已停止的服务。
stop: 用于停止正在运行的服务。
例如:$ sudo systemctl startssh.service
$ sudo systemctl stopssh.service
重启或重新加载服务:$ sudo systemctl reloadssh.service
$ sudo systemctl restartssh.service
$ sudo systemctl reload-or-restartssh.service
Reload:用于重新加载正在运行的服务的配置
Restart: 用于重新启动(Stop/Start)正在运行的服务
reload-or-restart: 用于重新加载服务默认值,但是如果该服务无法重新加载,则会重新启动它
检查服务状态:$ sudo systemctl statusssh.service
Status:用于检查服务的当前状态
启用或禁用服务:$ sudo systemctl enablessh.service
$ sudo systemctl disablessh.service
Enable:用于使服务在系统启动时启动
Disable:用于禁用服务以在系统启动时不启动
检查服务的启用/禁用状态:$ sudo systemctl is-activessh.service
$ sudo systemctl is-enabledssh.service
is-active:用于检查服务当前服务状态
is-enabled:用于检查系统启动时是否已启用服务
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的Linux教程视频栏目!