CentOS 7 上systemctl 的用法

我们对service和chkconfig两个命令都不陌生,systemctl 是管制服务的主要工具, 它整合了chkconfig 与 service功能于一体。

  1. systemctl is-enabled iptables.service
  2. systemctl is-enabled servicename.service #查询服务是否开机启动
  3. systemctl enable *.service #开机运行服务
  4. systemctl disable *.service #取消开机运行
  5. systemctl start *.service #启动服务
  6. systemctl stop *.service #停止服务
  7. systemctl restart *.service #重启服务
  8. systemctl reload *.service #重新加载服务配置文件
  9. systemctl status *.service #查询服务运行状态
  10. systemctl --failed #显示启动失败的服务

注:*代表某个服务的名字,如http的服务名为httpd

例如在CentOS 7 上安装http

  1. [root@CentOS7 ~]# yum -y install httpd
  2. 启动服务(等同于service httpd start
  3. systemctl start httpd.service
  4. 停止服务(等同于service httpd stop
  5. systemctl stop httpd.service
  6. 重启服务(等同于service httpd restart
  7. systemctl restart httpd.service
  8. 查看服务是否运行(等同于service httpd status
  9. systemctl status httpd.service
  10. 开机自启动服务(等同于chkconfig httpd on
  11. systemctl enable httpd.service
  12. 开机时禁用服务(等同于chkconfig httpd on
  13. systemctl disable httpd.service