码迷,mamicode.com
首页 > Web开发 > 详细

编译安装apache添加开机自启动

时间:2020-07-19 11:27:10      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:local   报错信息   解决   开机   emctl   init   redirect   pac   daemon   

1、系统版本信息

[root@linux /]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@linux /]# uname -r
3.10.0-693.el7.x86_64

2、源码编译安装apache服务后,设置开机自启动报错信息

[root@linux ~]# systemctl enable httpd
httpd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig httpd on

[root@linux ~]# chkconfig --add httpd
service httpd does not support chkconfig

3、解决方法或思路

1)编写apache启动脚本

[root@linux ~]# cd /etc/init.d/
[root@linux init.d]# touch httpd
[root@linux ~]# vim httpd
#!/bin/bash
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server

function httpd_start(){
/usr/local/apache/bin/apachectl start
}

function httpd_stop(){
/usr/local/apache/bin/apachectl stop
}

case $1 in
start)
httpd_start
;;
stop)
httpd_stop
;;
restart)
httpd_stop
httpd_start
;;
*)
echo "Usage: httpd start|stop|restart!"
;;
esac

注意:以下两行内容是服务能够在chkconfig里添加的必要代码

#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server
2)把编写的启动脚本赋予执行权限,(添加到系统服务中)

[root@linux ~]# chmod +x httpd
[root@linux ~]# ll

-rwxr-xr-x 1 root root 496 Jul 18 10:12 httpd

3)重新加载守护进程,启动服务

[root@linux ~]# systemctl daemon-reload #先加载守护进程,否则无法启动服务
[root@linux ~]# systemctl start httpd
[root@linux ~]# netstat -lnpt|grep http
tcp6 0 0 :::80 :::* LISTEN 1077/httpd

4)设置开机自启动

[root@linux ~]# chkconfig --add httpd

5)查看开机自启动结果:

[root@linux ~]# chkconfig --list|grep httpd

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

6)apache的安装路径:

/usr/local/apachectl
[root@linux apache]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules

编译安装apache添加开机自启动

标签:local   报错信息   解决   开机   emctl   init   redirect   pac   daemon   

原文地址:https://blog.51cto.com/1283684/2511576

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!