新版本的httpd-2.4新增以下特性;

新增模块;

mod_proxy_fcgi(可提供fcgi代理)

mod_ratelimit(限制用户带宽)

mod_request(请求模块,对请求做过滤)

mod_remoteip(匹配客户端的IP地址)

对于基于IP的访问控制做了修改,不再支持allow,deny,order机制,而是统一使用require进行

还新增以下几条新特性;

1、MPM支持在运行时装载;不过要开启这种特性,在编译安装要启用这三种功能;

         --enable-mpms-shared=all  --with-mpm=event

2、支持event

3、支持异步读写

4、在每个模块及每个目录上指定日志级别
5、增强版的表达式分析器
6、每请求配置:<If>, <Elseif>
7、毫秒级别的keepalive timeout
8、基于FQDN的虚拟主机不再需要NameVirtualHost指令
9、支持使用自定义变量


一;准备环境

Centos6.5-64位

安装httpd前需准备的程序包组;这几个程序包系统自带光盘就有,只需挂载到指定目录,制作成本地yum源即可安装使用。(此处不做过多介绍)

解决依赖关系
yum groupinstall -y "Server Platform Development"
yum groupinstall -y "Development tools"
yum install -y pcre-devel-7.8-6.el6.x86_64

二;编译安装httpd2.4所依赖的软件包

httpd2.4依赖于更高版本的apr和apr-util,apr全称为apache portable runtime(apache可运行时移值)。它是个能够让Apache跨平台工作的工具,是个底层库,安装上apr后。如果在win和linux上安装上apr后,Apache的同一个代码,即可以在win上运行也可在linux上运行;

  1.安装apr-1.5.0.tar.bz2

wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.bz2

[root@www xf]# tar xf ^Cr-1.5.0.tar.bz2
[root@www xf]# cd apr-1.5.0
[root@www apr-1.5.0]# ./configure --prefix=/usr/local/apr
[root@www apr-1.5.0]# make && make install

2.安装apr-util-1.5.3

ftp://ftp.mirrorservice.org/sites/ftp.apache.org/apr/apr-util-1.5.3.tar.bz2

[root@www xf]# tar xf apr-util-1.5.3.tar.bz2
[root@www xf]# cd apr-util-1.5.3
[root@www apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@www apr-util-1.5.3]# make && make install

3.以上两步编译完成,现正式开始编译httpd-2.4.9.tar.bz2

http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2

[root@www xf]# tar xf httpd-2.4.9.tar.bz2
[root@www xf]# cd httpd-2.4.9
[root@www httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
--prefix=/usr/local/apache 安装路径
--sysconfdir=/etc/httpd24 配置文件路径
--enable-so 允许运行时加载DSO模块
--enable-ssl 如果不加载将无法使用使用https
--enable-cgi 允许使用cgi脚本
--enable-rewrite 支持URL重写机制
--with-zlib 支持网络通用压缩库
--with-pcre 支持pcre
--with-apr=/usr/local/apr 指定apr的安装路径
--with-apr-util=/usr/local/apr-util/ 指定apr-util的安装路径
--enable-modules=most 启用大多数常用的模块
--enable-mpms-shared=all 启用MPM所有支持的模式
--with-mpm=event 默认使用enevt模式
查看安装后所生成的文件 extra目录是2.4版新增目录
[root@www httpd24]# ls
extra  httpd.conf  magic  mime.types  original
[root@www httpd24]# cd extra/
[root@www extra]# ls
httpd-autoindex.conf  httpd-info.conf       httpd-mpm.conf                 httpd-userdir.conf
httpd-dav.conf        httpd-languages.conf  httpd-multilang-errordoc.conf  httpd-vhosts.conf
httpd-default.conf    httpd-manual.conf     httpd-ssl.conf                 proxy-html.conf


三、安装后所需配置;

   1、导出头文件;以目录链接的形式来实现

[root@station154 ~]# ln -sv /usr/local/apache/include/ /usr/include/httpd
`/usr/include/httpd' -> `/usr/local/apache/include/'

2、输出二进制程序

root@station154 ~]# vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
root@station154 ~]#. /etc/profile.d/httpd24.sh
[root@www ~]# httpd -V    显示httpd版本信息

3、导出man文件

[root@www ~]# vim /etc/man.config
MANPATH /usr/local/apache/man
[root@www ~]# man -M /usr/local/apache/man httpd

4、启动httpd

[root@www ~]# apachectl start
[root@www ~]# ss -tunl | grep 80
tcp    LISTEN     0      128                   :::80                   :::*

 5、修改服务脚本;

      修改服务前先把httpd关闭;apachect1 stop

       vim /etc/init.d/httpd24.sh

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#              server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
HTTPD_LANG=${HTTPD_LANG-"C"}
INITLOG_ARGS=""
apachectl=/usr/local/httpd24/bin/apachectl
httpd=/usr/local/apache/bin/httpd
prog=httpd
pidfile=${PIDFILE-/var/run/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
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 ${STOP_TIMEOUT} $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=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}
# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status -p ${pidfile} $httpd >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac
exit $RETVAL
现在可以利用脚本来启动httpd服务
[root@www ~]# service httpd24 restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@www ~]# elinks -dump www.ouyang.com/index.html   elinks 测试启动
                                   It works!


下篇将介绍httpd2.4基本功能的实现...