CentOS 7.4 添加 Apache 开机启动

本文介绍在 CentOS 7.4 系统中,将 Apache 服务添加到开机启动项中。

设置开机启动 Apache 服务,执行命令:

  1. systemctl enable httpd.service

出现错误:

  1. [root@123si ~]# systemctl enable httpd.service
  2. httpd.service is not a native service, redirecting to /sbin/chkconfig.
  3. Executing /sbin/chkconfig httpd on
  4. service httpd does not support chkconfig

解决办法:

使用vi命令,编辑vi /etc/rc.d/init.d/httpd文件,在#!/bin/sh下面添加,如下。

  1. #chkconfig: 2345 10 90
  2. #description: Activates/Deactivates Apache Web Server

加上上面这两行就可以,必须带井号(#)。

其中:2345 是设为要启动的运行级别,10 是启动优先级,90 是结束进程的优先级,谁优先谁先挂的意思。

最终效果:

  1. [root@123si ~]# cat /etc/rc.d/init.d/httpd
  2. #!/bin/sh
  3. #chkconfig: 2345 10 90
  4. #description: Activates/Deactivates Apache Web Server
  5. #
  6. # Licensed to the Apache Software Foundation (ASF) under one or more
  7. # contributor license agreements. See the NOTICE file distributed with
  8. # this work for additional information regarding copyright ownership.
  9. # The ASF licenses this file to You under the Apache License, Version 2.0
  10. # (the "License"); you may not use this file except in compliance with
  11. # the License. You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. ......

(完)