CentOS 7.4 添加 Apache 开机启动
本文介绍在 CentOS 7.4 系统中,将 Apache 服务添加到开机启动项中。
设置开机启动 Apache 服务,执行命令:
systemctl enable httpd.service
出现错误:
[root@123si ~]# systemctl enable httpd.service
httpd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig httpd on
service httpd does not support chkconfig
解决办法:
使用vi
命令,编辑vi /etc/rc.d/init.d/httpd
文件,在#!/bin/sh
下面添加,如下。
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
加上上面这两行就可以,必须带井号(#)。
其中:2345 是设为要启动的运行级别,10 是启动优先级,90 是结束进程的优先级,谁优先谁先挂的意思。
最终效果:
[root@123si ~]# cat /etc/rc.d/init.d/httpd
#!/bin/sh
#chkconfig: 2345 10 90
#description: Activates/Deactivates Apache Web Server
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
......
(完)