zoukankan      html  css  js  c++  java
  • [乐意黎原创]Centos 7里apache(httpd)自启动

    最近,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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    C
    B
    A
    G
    BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)
    Codevs_1230_元素查找_(set/Hash)
    POJ_2503_Babelfish_(Trie/map)
    POJ_2001_Shortest_Prefixes_(Trie)
    BZOJ_3670_[NOI2014]_动物园_(kmp)
    BZOJ_3196_二逼平衡树_(树套树,线段树+Treap)
  • 原文地址:https://www.cnblogs.com/linuxandy/p/10838383.html
Copyright © 2011-2022 走看看