httpd-2.4編譯安裝及新特性詳解 --LAMP

 

安裝環境

  1. 系統環境:CentOS 6.5-x86_64

  2. 所需軟件包:

    1. apr-1.5.0.tar.bz2

    2. apr-util-1.5.3.tar.bz2

    3. httpd-2.4.9.tar.bz2

  3. 下載地址:

    1. http://apr.apache.org/

    2. http://httpd.apache.org/


安裝步驟

  1. 注:httpd-2.4版本依賴於更高版本(1.5版本以上)的apr和apr-util;apr全稱爲apache portable runtime,能實現httpd跨平臺運行

  2. 解決依賴關係

    yum -y groupinstall "Development tools"  # 安裝開發包組,包括gcc,automake等
    yum -y groupinstall "Server Platform Development" # 安裝開發包組
    yum -y install pcre-devel # 兼容Perl的正則表達式庫
  3. 編譯安裝apr-1.5.0

    tar xf apr-1.5.0.tar.bz2
    cd apr-1.5.0
    ./configure --prefix=/usr/local/apr
    make && make install
  4. 編譯安裝apr-util-1.5.3

    tar xf apr-util-1.5.3.tar.bz2
    cd apr-util-1.5.3
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
    make && make install
  5. httpd編譯安裝

tar xf httpd-2.4.9.tar.bz2
cd httpd-2.4.9
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd249 --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-deflate --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install
# 各編譯參數詳解
--prefix:#安裝路徑
--sysconfdir:#指定配置文件路徑
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,動態共享對象,可實現模塊動態生效
--enable-ssl:#支持SSL/TLS,可以實現https訪問
--enable-cgi:#支持CGI腳本(默認對非線程的MPM模式開啓)
--enable-rewrite:#啓用Rewrite功能
--enable-deflate:#支持壓縮
--with-z:#使用指定的zlib庫,不指定路徑會自動尋找
--with-pcre:#使用指定的PCRE庫,不指定路徑會自動尋找
--with-apr:#指定apr安裝路徑
--with-apr-util:#指定apr-util安裝路徑
--enable-modules:#支持動態啓用的模塊,可選參數有“all”,“most”,“few”,“reallyall”
--enable-mpms-shared:#支持動態加載的MPM模塊,可選“all”
--with-mpm:#設置默認啓用的MPM模式

後續配置

           i.修改httpd的主配置文件,設置其Pid文件的路徑

# vi /etc/httpd249/httpd.conf
PidFile  "/var/run/httpd.pid"

           ii.導出頭文件

ln -sv /usr/local/apache/include /usr/include/httpd

           iii.導出man手冊

vi /etc/man.config
    MANPATH /usr/local/apache/man  # man文件在apache安裝目錄下哦

           iv.編寫服務腳本(因是編譯安裝,不會自動生成服務腳本)

# vi /etc/rc.d/init.d/httpd
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
    echo -n $"Starting $prog: "
    LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
}
stop() {
     echo -n $"Stopping $prog: "
     killproc -p ${pidfile} -d 10 $httpd
     RETVAL=$?
     echo
     [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
# See how we were called.
case "$1" in
start)
    start;;
stop)
    stop;;
status)
    status -p ${pidfile} $httpd
    RETVAL=$?;;
restart)
    stop
    start;;
condrestart)
    if [ -f ${pidfile} ] ; then
        stop
        start
    fi;;
reload)
    reload;;
graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?;;
*)
    echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
    exit 1
esac
exit $RETVAL


啓動服務並測試

# 爲服務腳本賦予執行權限:
chmod +x /etc/rc.d/init.d/httpd
# 加入服務列表:
chkconfig --add httpd
# 啓動服務
service httpd start

瀏覽器訪問:http://Server_IP/   # 顯示“It works”,即表示httpd服務啓動成功


httpd 2.4新特性說明

  1. 新增特性

    1. MPM支持在運行時裝載

    2. 支持event MPM類型

    3. 支持異步讀寫

    4. 在每模塊及每目錄上指定日誌級別

    5. 每請求配置:<If>,<Elseif>

    6. 增強版的表達式分析器

    7. 毫秒級的keepalive timeout

    8. 基於FQDN的虛擬主機不再需要NameVirtualHost指令

    9. 支持使用自定義變量

  2. 新增模塊

    1. mod_proxy_fcgi

    2. mod_ratelimit

    3. mod_request

    4. mod_remoteip

  3. 修改

    1. 對於基於IP的訪問控制做了修改,不再支持使用order, allow, deny這些機制,而是統一使用require進行


下一篇:httpd-2.4基礎配置講解及實現


本文出自 “小小忍者” 博客,請務必保留此出處http://xxrenzhe.blog.51cto.com/4036116/1380704

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章