CentOS 7启用或禁用启动项

检查服务是否启动

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.

在以上的示例中,kdumpphp-fpm启动失败,如果出现这种情况,需要检查一下服务的启动脚本和它所依赖的服务。

参考链接

CentOS 7 开放端口和关闭防火墙

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值