您的位置:首页 > 理论基础 > 计算机网络

天下武功尽出LAMP之http篇(3)

2015-07-24 23:07 671 查看
有了前两篇的介绍我相信大家对http已经有了基本的认识,今天我们来说一下httpd-2.4,这是Apache对于httpd-2.2的比较大的改进,增加许多实用性的新功能,我们来大致看一下。

httpd-2.4新特性:

(1) MPM支持运行DOS机制;
(2) 支持event MPM;
(3) 支持异步读写;
(4) 支持每模块及每个目录分别使用各自的日志级别;
(5) 每请求配置;<If>
(6) 增强版的表达式分析器;
(7) 支持毫秒级的keepalive timeout;
(8) 基于FQDN的虚拟主机不再需要NameVirtualHost指令;
(9) 支持用户自定义变量;

新模块:

(1) mod_proxy_fcgi#与PHP结合的模块
(2) mod_ratelimit#限制下载速率的模块
(3) mod_remoteip#设定远程客户端IP
修改的配置机制:不再支持使用order, allow, deny定义基于ip的访问控制,改为require在编译安装时httpd依赖于apr, apr-util这两个包,其中apr(Apache portable runtime)叫做Apache可移植运行时环境,这个东西可以简单的理解成Apache的虚拟机,作用是为了使httpd代码可以在不同的操作系统上运行的。因为httpd-2.4需要的apr版本最低为1.4而我的系统上的是1.3.9,所以我们需要将apr也一同编译安装。
安装编译环境

[root@localhost ~]# yum groupinstall "Development tools" "Server Platform Development" y

编译安装apr,再安装apr-util最后安装httpd,这是有顺序的

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

编译安装httpd-2.4

[root@localhost ~]# tar xf httpd-2.4.10.tar.bz2
[root@localhost ~]# cd httpd-2.4.10
[root@localhost httpd-2.4.10]# ./configure help#查看config选项
[root@localhost httpd-2.4.10]# ./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=prefork
[root@localhost httpd-2.4.10]# make && make install

4、httpd-2.4编译参数详解:
--prefix:#安装路径
--sysconfdir:#指定配置文件路径
--enable-so:#DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效
--enable-ssl:#支持SSL/TLS,可实现https访问 需已安装openssl-devel
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能,URL重写
--enable-deflate:#支持压缩功能
--with-zlib:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找 需已安装pcre-devel
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-mpms-shared:#支持动态加载的MPM模块,可选参数:all
--with-mpm:#设置默认启用的MPM模式,{prefork|worker|event}
--enable-modules:#支持动态启用的模块,可选参数:all,most,few,reallyall
5、编译后的辅助工作
[root@localhost httpd-2.4.10]# vim /etc/profile.d/httpd24.sh#添加环境变量
1 export PATH=/usr/local/apache/bin:$PATH
[root@localhost httpd-2.4.10]# . /etc/profile.d/httpd24.sh#重读环境变量脚本
[root@localhost httpd-2.4.10]# ln -sv /usr/local/apache/include/ /usr/include/httpd24#导出头文件
[root@localhost httpd-2.4.10]# vim /etc/man.config#导出帮助文档
43 MANPATH /usr/local/apache/man
[root@localhost httpd-2.4.10]# vim /etc/rc.d/init.d/httpd24 #编写服务脚本
1 #!/bin/bash
2 #
3 # httpd        Startup script for the Apache HTTP Server
4 #
5 # chkconfig: - 85 15
6 # description: The Apache HTTP Server is an efficient and extensible  \
7 #              server implementing the current HTTP standards.
8 # processname: httpd
9 # config: /etc/httpd/conf/httpd.conf
10 # config: /etc/sysconfig/httpd
11 # pidfile: /var/run/httpd/httpd.pid
12 #
13 ### BEGIN INIT INFO
14 # Provides: httpd
15 # Required-Start: $local_fs $remote_fs $network $named
16 # Required-Stop: $local_fs $remote_fs $network
17 # Should-Start: distcache
18 # Short-Description: start and stop Apache HTTP Server
19 # Description: The Apache HTTP Server is an extensible server
20 #  implementing the current HTTP standards.
21 ### END INIT INFO
22
23 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 if [ -f /etc/sysconfig/httpd ]; then
27         . /etc/sysconfig/httpd
28 fi
29
30 # Start httpd in the C locale by default.
31 HTTPD_LANG=${HTTPD_LANG-"C"}
32
33 # This will prevent initlog from swallowing up a pass-phrase prompt if
34 # mod_ssl needs a pass-phrase from the user.
35 INITLOG_ARGS=""
36
37 # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
38 # with the thread-based "worker" MPM; BE WARNED that some modules may not
39 # work correctly with a thread-based MPM; notably PHP will refuse to start.
40
41 # Path to the apachectl script, server binary, and short-form for messages.
42 apachectl=/usr/local/apache/bin/apachectl
43 httpd=${HTTPD-/usr/local/apache/bin/httpd}
44 prog=httpd
45 pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
46 lockfile=${LOCKFILE-/var/lock/subsys/httpd}
47 RETVAL=0
48 STOP_TIMEOUT=${STOP_TIMEOUT-10}
49
50 # The semantics of these two functions differ from the way apachectl does
51 # things -- attempting to start while running is a failure, and shutdown
52 # when not running is also a failure.  So we just do it the way init scripts
53 # are expected to behave here.
54 start() {
55         echo -n $"Starting $prog: "
56         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
57         RETVAL=$?
58         echo
59         [ $RETVAL = 0 ] && touch${lockfile}
60         return $RETVAL
61 }
62
63 # When stopping httpd, adelay (of default 10 second) is required
64 # before SIGKILLing thehttpd parent; this gives enough time for the
65 # httpd parent to SIGKILLany errant children.
66 stop() {
67         echo -n $"Stopping $prog: "
68         killproc -p ${pidfile} -d${STOP_TIMEOUT} $httpd
69         RETVAL=$?
70         echo
71         [ $RETVAL = 0 ] && rm -f${lockfile} ${pidfile}
72 }
73 reload() {
74     echo -n $"Reloading $prog: "
75     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t>&/dev/null; then
76         RETVAL=6
77         echo $"not reloading due toconfiguration syntax error"
78         failure $"not reloading $httpddue to configuration syntax error"
79     else
80         # Force LSB behaviour from killproc
81         LSB=1 killproc -p ${pidfile} $httpd-HUP
82         RETVAL=$?
83         if [ $RETVAL -eq 7 ]; then
84             failure $"httpdshutdown"
85         fi
86     fi
87     echo
88 }
89
90 # See how we were called.
91 case $1 in
92 start)
93         start
94         ;;
95   stop)
96         stop
97         ;;
98   status)
99         status -p ${pidfile} $httpd
100         RETVAL=$?
101         ;;
102   restart)
103         stop
104         start
105         ;;
106   condrestart|try-restart)
107         if status -p${pidfile} $httpd >&/dev/null; then
108                 stop
109                 start
110         fi
111         ;;
112   force-reload|reload)
113         reload
114         ;;
115  graceful|help|configtest|fullstatus)
116         $apachectl $@
117         RETVAL=$?
118         ;;
119   *)
120         echo $"Usage:$prog{start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|conf    igtest}"
121         RETVAL=2
122 esac
123
124 exit $RETVAL
#其实这个脚本很简单,就是把原来httpd-2.2的脚本改一下就行了,内容相对比较简单,大家可以看一下
[root@localhost httpd-2.4.10]# chkconfig --add httpd24 #添加到服务列表
[root@localhost httpd-2.4.10]# chkconfig httpd24 on    #设置开机启动,不过要把httpd-2.2停掉


6、httpd-2.4的配置文件
/etc/httpd24 #为编译安装时定义的目录
/etc/httpd24/httpd.conf # 主配置文件
/etc/httpd24/extra/httpd-default.conf # 默认配置文件(keepalive、AccessFileName等设置)
/etc/httpd24/extra/httpd-userdir.conf # 用户目录配置文件
/etc/httpd24/extra/httpd-mpm.conf # MPM配置文件
/etc/httpd24/extra/httpd-ssl.conf # SSL配置文件
/etc/httpd24/extra/httpd-vhosts.conf # 虚拟主机配置文件
/etc/httpd24/extra/httpd-info.conf # server-status页面配置文件

好了,我们本篇文章就到这里了,httpd-2.4的配置其实和2.2差不多,我们下一篇文章再具体介绍,如有错误敬请指出。

本文出自 “Linuxlove” 博客,请务必保留此出处http://linuxlover.blog.51cto.com/2470728/1678206
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: