hanwentan 2020-07-19
[ /]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[ /]# uname -r
3.10.0-693.el7.x86_64
[ ~]# systemctl enable httpd
httpd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig httpd on
[ ~]# chkconfig --add httpd
service httpd does not support chkconfig
1)编写apache启动脚本
[ ~]# cd /etc/init.d/
[ init.d]# touch httpd
[ ~]# 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)把编写的启动脚本赋予执行权限,(添加到系统服务中)
[ ~]# chmod +x httpd
[ ~]# ll
-rwxr-xr-x 1 root root 496 Jul 18 10:12 httpd
3)重新加载守护进程,启动服务
[ ~]# systemctl daemon-reload #先加载守护进程,否则无法启动服务
[ ~]# systemctl start httpd
[ ~]# netstat -lnpt|grep http
tcp6 0 0 :::80 :::* LISTEN 1077/httpd
4)设置开机自启动
[ ~]# chkconfig --add httpd
5)查看开机自启动结果:
[ ~]# chkconfig --list|grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
6)apache的安装路径:
/usr/local/apachectl
[ apache]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules