首页 技术 正文
技术 2022年11月11日
0 收藏 820 点赞 3,389 浏览 1618 个字

最近,Aerchi在折腾 ECS服务器 (Centos 7),每次重启后都要手动开启apache服务,好繁琐。

仔细研究了下:
Apache 的服务
第一、启动、终止、重启
systemctl start httpd.service #启动

systemctl stop httpd.service #停止

systemctl restart httpd.service #重启

第二、设置开机启动/关闭
systemctl enable httpd.service #开机启动

systemctl disable httpd.service #开机不启动

第三、检查httpd状态
systemctl status httpd.service

需要将Apache注册到Linux服务里面啊!
注册Apache到Linux服务
在Centos 7 安装完Apache后,启动关闭Apache可以通过如下命令实现: 

/usr/local/apache/bin/apachectl start | stop | restart
如果想将httpd列入系统自动启动的服务,可以直接将上述的apachectl文件拷贝到 /etc/rc.d/init.d 中,然后在相应的启动级别如3,5中加入链接即可。命令如下:

cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd # 复制到init.d 并重命名为httpd

ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
链接文件的S61是启动时的序号。当init.d目录下有httpd脚本后,我们就可以通过service命令来启动关闭apache了。在任意路径下执行:

service httpd start | stop | restart
这时有个问题就是:虽然apache已经可以自动启动,但在linux的服务列表中却看不到它,要添加服务,一般通过chkconfig –add xxx来实现,但需要脚本中有相应的信息才行,否则chkconfig就会提示:xxx 服务不支持 chkconfig。所以我们首先编辑httpd脚本,在第2行(#!/bin/sh下面)添加如下注释信息(包括#):

# chkconfig: 35 61 61
# description: Apache
第一行的3个参数意义分别为:在哪些运行级别启动httpd(3,5);启动序号(S61);关闭序号(K61)。注意:第二行的描述必须要写!
保存后执行:

chkconfig –add httpd #所有开机模式下自启动,另外chkconfig httpd on 表示345模式下自启动
就将httpd添加入服务了。在rc3.d、rc5.d路径中将来就会出现S61httpd的链接,其他运行级别路径中会出现K61httpd的链接。

最后,修改 rc.local文件添加自启动

vim /etc/rc.d/rc.local
添加如下:

13 touch /var/lock/subsys/local
 14 /etc/init.d/mysqld start
 15 #/usr/local/apache/bin/apachectl start
 16 #apachectl restart
 17 touch /usr/local/apache/bin/
 18 /usr/local/apache/bin/apachectl start

运行下面的命令查看服务,就可以看到httpd的服务了。

chkconfig –list

systemctl list-unit-files

——————————————

乐意黎
2018-06-29
———————
作者:aerchi
来源:CSDN
原文:https://blog.csdn.net/aerchi/article/details/80859894
版权声明:本文为博主原创文章,转载请附上博文链接!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849