之前已经讲过web基本概念与http请求响应报文,下面将以编译方式来安装http2.4.9服务器软件。与httpd2.2相比,httpd 2.4增加了如下特性:
1、MPM可于运行时装载;
2、Event MPM
3、异步读写
4、在每模块及每目录上指定日志级别;
5、每请求配置;<If>, <ElseIf>, <Else>;
6、增强的表达式分析器;
7、毫秒级的KeepAlive Timeout;
8、基于域名的虚拟主机不再需要NameVirtualHost指令;
9、降低了内存占用;
10、支持在配置文件中使用自定义变量;
新增加的模块:
mod_proxy_fcgi(可以提供fcgi代理)
mod_proxy_scgi(支持scgi协议)
mod_proxy_express
mod_remoteip(能够强大的匹配客户端的IP地址)
mod_session(保持用户会话)
mod_ratelimit(限制每个用户的带宽)
mod_request(请求模块,对请求做强大的过滤)
等等;
一、准备阶段
本机环境 | [root@bogon ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m [root@bogon ~]# uname -r 2.6.32-431.el6.x86_64 |
预安装软件包 | [root@bogon run]# yum groupinstall -y "Server Platform Development" [root@bogon run]# yum groupinstall -y "Development tools" [root@bogon run]#yum install -y pcre-7.8-6.el6.x86_64 pcre-devel-7.8-6.el6.x86_64 |
二、下载apr-1.5.0、apr-util-1.5.3、http2.4.9
[root@bogon Downloads]#wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2 [root@bogon Downloads]#wget ftp://ftp.mirrorservice.org/sites/ftp.apache.org/apr/apr-util-1.5.3.tar.bz2 [root@bogon Downloads]#wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.bz2
三、编译安装软件包
1、apr-1.5.0.tar.bz2
apr:apache portable run-time是apache运行时环境,为了能使apache运行在不同的平台上
并且能使用同样的机制,所以apr能够抹除不同系统的数据库,让apache运行环境的机制都一样,
并且能让apache的某些特性跨平台的使用。
[root@bogon local]# tar xf apr-1.5.0.tar.bz2 [root@bogon local]#cd apr-1.5.0 [root@bogon apr-1.5.0]# ./configure --prefix=/usr/local/apr [root@bogon apr-1.5.0]#make && make install
2、apr-util-1.5.3.tar.bz2
#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
3、http2.4.9.tar.bz2
#tar xf httpd-2.4.9.tar.bz2 # cd 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 #make && make install
编译参数说明:
--prefix=/usr/local/apache:指定安装路径
--sysconfdir=/etc/httpd24:指定配置文件存放位置
--enable-so:允许运行时加载DSO模块
--enable-ssl: 提供对安全套接字层(SSL)和传输层安全(TLS)协议实现高强度加密传输
--enable-cgi:提供对CGI脚本执行的支持
--enable-rewrite:支持重写
--with-zlib:是支持zlib库
--with-pcre:启用正则表达式
--with-apr=/usr/local/apr:Apache可移植运行时(APR)是httpd源码的一部分并会自动与httpd一起创建。如果你想使用一个已经存在的APR ,就必须在这里指定apr-config脚本的路径。
--with-apr-util=/usr/local/apr-util/:Apache可移植运行时工具包(APU)是httpd源码的一部分并会自动与httpd一起创建。如果你想使用一个已经存在的APU ,就必须在这里指定apu-config脚本的路径。
--enable-modules=most:启用大多数常用模块。
--enable-mpms-shared=all:启用MPM支持的所有模式。
--with-mpm=event:设置默认MPM为event。
四、参数设置
1、导出库文件
[root@bogon apache]# ln -s /usr/local/apache/include/ /usr/include/httpd24
2、输出二进制程序
#vim /etc/profile.d/http24.sh export PATH=/usr/local/apache/bin:$PATH #source /etc/profile.d/http24.sh
3、导出man手册
#vim /etc/man.config #MANPATH /usr/local/apache/man
五、测试
# apachectl start # ss -tunl |grep ":80" tcp LISTEN 0 128 :::80 :::* # curl 192.168.1.114 <html><body><h1>It works!</h1></body></html>
六、添加服务脚本
1、先关掉apache服务
#apachectl stop
2、修改httpd的主配置文件,设置其Pid文件的路径,编辑/etc/httpd24/httpd.conf,添加如下行即可
# vim /etc/httpd24/httpd.conf PidFile "/var/run/httpd24.pid"
3、修改服务脚本
#!/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 # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # 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=/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} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. 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) 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
=========================================完==========================================
下篇将对编译安装的http-2.4.9进行功能测试
本文出自 “和风细雨” 博客,请务必保留此出处http://essun.blog.51cto.com/721033/1379986