【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
检查服务是否启动
在RHEL/CentOS 7
上,通过使用systemctl
命令检查,可以运行systemctl status
命令检查服务的运行状态:
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
...
最后一个单词enabled
或者disabled
会告诉我们服务的状态,在以上的示例中,Apache2 Web
服务器的httpd
服务是启用的。
禁用/移除服务
如果要禁用服务,可以使用systemctl disable
命令:
$ systemctl disable httpd
rm '/etc/systemd/system/multi-user.target.wants/httpd.service'
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
...
运行systemctl
命令将从/etc/systemd/system/*
移除服务符号链接,之后服务就不会起作用了。
启用服务
如果要启用服务,可以使用systemctl enable
命令:
$ systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
$ systemctl status httpd
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
...
如果执行了systemctl disable
命令移除了服务,之后再运行systemctl enable
命令会重新创建这个服务。
检查服务是否启动成功
使用systemctl --failed
可以查看启动失败的服务:
$ systemctl --failed
UNIT LOAD ACTIVE SUB DESCRIPTION
kdump.service loaded failed failed Crash recovery kernel arming
php-fpm.service loaded failed failed The PHP FastCGI Process Manager
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
在以上的示例中,kdump
和php-fpm
启动失败,如果出现这种情况,需要检查一下服务的启动脚本和它所依赖的服务。
参考链接
来源:oschina
链接:https://my.oschina.net/u/2325629/blog/550070