1. 程式人生 > >centos7源碼編譯安裝httpd、加入systemctl並設置開機自啟動

centos7源碼編譯安裝httpd、加入systemctl並設置開機自啟動

.sh start chkconfig ash figure -a centos7 function star

  • 所需軟件:
    apr-1.6.3.tar.gz
    (下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz)
    apr-util-1.6.1.tar.gz
    (下載地址:http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz)
    httpd-2.4.29.tar.gz
    (下載地址:http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.29.tar.gz)
  • 安裝編譯環境:
    yum  -y  install  gcc  pcre  pcre-devel  libtool
  • 安裝apr:
    tar  -xzf  apr-1.6.3.tar.gz
    cd  apr-1.6.3/
    ./configure  &&  make  &&  make  install
  • 安裝apr-util:
    tar  -xzf  apr-util-1.6.1.tar.gz
    cd  apr-util-1.6.1/
    ./configure  --with-apr=/usr/local/apr/
    make  &&  make  install
  • 安裝httpd:
    tar  httpd-2.4.29.tar.gz
    cd httpd-2.4.29/
    ./configure  &&  make  &&  make  install
  • 編寫啟動腳本:vim myhttpd
    #!/bin/bash
    # chkconfig: 12345 80 90
    function start_http()
    {
    /usr/local/apache2/bin/apachectl  start
    }
    function stop_http()
    {
     /usr/local/apache2/bin/apachectl  stop
    }
    case "$1" in
    start)
        start_http
    ;;  
    stop)
        stop_http
    ;;  
    restart)
        stop_http
        start_http
    ;;
    *)
        echo "Usage : start | stop | restart"
    ;;
    esac
  • 加入系統服務:
    chmod  a+x  myhttpd
    cp  -arf  myhttpd  /etc/init.d/
  • 啟動自己編寫的服務:
    systemctl  start  myhttpd
  • 設置開機自啟動:
    chkconfig  --add  myhttpd
  • centos7源碼編譯安裝httpd、加入systemctl並設置開機自啟動