一、HTTPD版本:
httpd-1.3
httpd-2.0
httpd-2.2
httpd-2.4
二、http2.4的新特性:
1)MPM支持运行时装载
--enable-mpms-shared=all--with-mpm=prefork|worker|event
2)支持event MPM
3)异步读写
4)支持每模块及每目录分别使用不同的日志级别
5)每请求配置; <If> (用户每请求一个特殊资源,都可以做限制)
6)增强版的表达式分析器;
7)支持毫秒级keepalive timeout;
8)基于FQDN的虚拟主机不再需要NameVirtualHost;
9)支持用户使用自定义变量;
新增一些模块:mod_proxy_fcgi,mod_ratelimit, mod_request, mod_remoteip
修改了一些配置机制:不再支持使用order,allow, deny来实现基于IP的访问控制;
三、编译安装;
3.1 httpd依赖于apr, apr-util
apr:apache portable runtime
httpd-2.4依�于1.4+及以上版本的apr
3.2检查开发环境,若没有则:yum groupinstall “ServerPlatform Development” “DevelopmentTools ”
yum install pcre-devel ………………支持扩展正则表达式的
[root@burgess ~]# rpm -qapr ………………..查询版本
apr-1.3.9-5.el6_2.x86_64 ……………………….此为支持httpd2.2版本的,不便卸载,安装时指定路径
[root@burgess ~]# rpm -qapr-util
apr-util-1.3.9-3.el6_0.1.x86_64
3.3官方下载站点http://apr.apache.org/ ;本人装载环境为教室,有此压缩包;
[root@burgess ~]# lftp 172.16.0.1/pub
cd ok, cwd=/pub
lftp172.16.0.1:/pub> cdSources/sources/httpd/
cd ok,cwd=/pub/Sources/sources/httpd
lftp172.16.0.1:/pub/Sources/sources/httpd>ls ……………….只是列出了教室最新的版本
-rwxr--r-- 1 500 500 813976 Mar 18 2014 apr-1.5.0.tar.bz2
-rwxr--r-- 1 500 500 695303 Mar 18 2014 apr-util-1.5.3.tar.bz2
-rwxr--r-- 1 500 500 4994460 Mar 18 2014 httpd-2.4.9.tar.bz2
lftp 172.16.0.1:/pub/Sources/sources/httpd>mget apr-1.5.0.tar.bz2apr-util-1.5.3.tar.bz2
1509279 bytestransferred
Total 2 filestransferred
lftp172.16.0.1:/pub/Sources/sources/httpd> bye
[root@burgess ~]# ls
apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
[root@burgess ~]# tar xfapr-1.5.0.tar.bz2
[root@burgess ~]# ls
apr-1.5.0
apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
[root@burgess ~]# cd apr-1.5.0
[root@burgess apr-1.5.0]# ./configure--prefix=/usr/local/apr ………………………指定路径
[root@burgess apr-1.5.0]#make&& make install …………………编译安装
注意:检查是否执行成功可用echo $?;如果不打算对httpd做二次开发,则无需将/usr/local/apr/路径下的文件输出
3.4 apr-util 安装基本重复上面步骤;
[root@burgess ~]# tar xfapr-util-1.5.3.tar.bz2
[root@burgess ~]# cd apr-util-1.5.3
[[email protected]]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr ………………..此文件依赖与apr,所以要把apr路径告诉其
[[email protected]]# make && make install
3.5 Httpd2.4安装:在ftp上下载,解压,之后cd到解压后的文档里面,执行命令如下;
[[email protected]]# ./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
[[email protected]]# make && make install …………………………….若出现pcre模块没装,执行yuminstall pcre-devel即可
3.5.1选项解析:
--enable-so DSO capability. This module willbe automatically ……………………支持动态模块装卸载(DSO)
enabled unless youbuild all modules statically.
--enable-ssl SSL/TLS support (mod_ssl) ………………………………支持ssl模块
--enable-cgi CGI scripts. Enabled by defaultwith non-threaded MPMs(common gateway interface通用网关接口;可以让静态webserver支持动态web服务器解析的一个协议或接口)
--enable-rewrite rule based URL manipulation ………………………………………………..支持URL重写
--with-pcre=PATH Use external PCRE library ……………………………………………支持扩展正则表达式
--enable-modules=MODULE-LIST ………………………………………..启用的模块
Space-separated listof modules to enable | "all" |
"most" |"few" | "none" | "reallyall"
--enable-mods-shared=MODULE-LIST ………………………….以共享模式编译模块
Space-separated listof shared modules to enable |
"all" |"most" | "few" | "reallyall"
--with-z=PATH use a specific zlib library………………………………………基于网络实现的压缩库;如果本地对应的开发包zlib有了,则不需要此选项
--enable-mpms-shared=MPM-LIST ……………………………..指明哪些是默认的(必须指的是编译进来的)
Space-separated listof MPM modules to enable for
dynamic loading.MPM-LIST=list | "all"
--with-mpm=MPM Choose the process model for Apacheto use by ………………………..指定默认MPM
default.MPM={event|worker|prefork|winnt} This will
be statically linkedas the only available MPM
unless--enable-mpms-shared is also specified.
3.6 服务脚本创建(修改)
[root@burgess ~]#cp /etc/rc.d/init.d/httpd~/ …………………………………将2.2版本的服务脚本复制到家目录,在此基础修改之;
[root@burgess ~]# ls
apr-util-1.5.3.tar.bz2 httpd-2.4.9.tar.bz2 mariadb-5.5.36-linux-x86_64.tar.gz
apr-1.5.0 apr-1.5.0.tar.bz2 httpd apr-util-1.5.3 httpd-2.4.9
[root@burgess ~]# vimhttpd
#if [ -f/etc/sysconfig/httpd ]; then
# . /etc/sysconfig/httpd
#fi ……………………..把此函数注释掉,则启动后httpd的mpm不会以worker启动,可以vim /etc/sysconfig/httpd的脚本文件内容有#HTTPD=/usr/sbin/httpd.worker,没有启动,source也无效
apachectl=/usr/local/bin/apachectl ………………………..此项为更改后的路径;可用ls /usr/local/bin/apachectl 查看程序都在此目录下
httpd=${HTTPD-/usr/local/apache/bin/httpd} …………………………..更改后路径
[root@burgess ]# ls /usr/local/apache ……………………………….一些重要文件的简要介绍
bin:二进制程序文件
build :编译时候用到的一些子目录
cgi-bin:cgi动态网站网页资源
error:错误页面,可以自定义,如404更改为自定义页面
htdocs :网页页面程序的存放位置
include :头文件
icons logs man manual modules
配置文件:/etc/httpd24/httpd.conf 补充类的配置文件/etc/httpd24/extra
3.7 启动httpd2.4vession,(用命令apachectl)
确保80端口的web服务为关闭的,才能启动编译的2.4version ……………….(ss -tnl)
查看apachectl 命令路径…………………用which;显示:/usr/sbin/apachectl;因为我们是编译的版本,所以应该与编译路径保持一致,此环境下,修改PATH环境变量
[root@burgess ~]# vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
[root@burgess ~]# . /etc/profile.d/httpd24.sh
[root@burgess ~]# echo $PATH
/usr/local/apache/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@burgess ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@burgess ~]# apachectl start …………………….尝试启动一下
AH00557: httpd: apr_sockaddr_info_get() failedfor burgess.wen
AH00558: httpd: Could not reliably determinethe server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName'directive globally to suppress this message
报错并不影响服务的启动,可以用(ss -tnl)查看80端口是否启动,或者在浏览器中输入172.16.249.214(虚拟主机IP)查看,显示IT works!
[root@burgess~]# mkdir /www/htdocs -pv
mkdir: created directory `/www'
mkdir: created directory `/www/htdocs'
[root@burgess ~]# vim /www/htdocs/index.html
<h1>/www/hcdocs What is a friend? Asingle soul dwelling in two bodies.</h1>
[root@burgess ~]# vim /etc/httpd24/httpd.conf
#DocumentRoot"/usr/local/apache/htdocs" ……………..此行注释掉,改为下一行路径
DocumentRoot "/www/htdocs"
ServerName www.burgess.com:80 #方法一:将此项启用起来,解决AH00557,AH00558报错信息.
[root@burgessconf]# vim /etc/hosts
172.16.100.16burgess.wen #.................方法二:将本地通信IP与主机名添加至/etc/hosts 也可解决报错信息(此步骤为可选项,二选一即可)
刷新浏览器显示信息:
Forbidden
You don't have permission to access /on this server.
[root@burgess ~]# vim/etc/httpd24/httpd.conf
<Directory "/www/htdocs"> #将路径改为此路径<网络路径>
#Options Indexes FollowSymLinks
Options None #将上面的Indexes FollowSymLinks停用
再次刷新网页,则会内容显示;
/www/hcdocs What is a friend? A singlesoul dwelling in two bodies.
3.8 启用manual手册
[root@burgess ~]# vim /etc/httpd24/httpd.conf
Include /etc/httpd24/extra/httpd-manual.conf #.............将此项启动,手册
LoadModule negotiation_modulemodules/mod_negotiation.so #…………………将此项启动
[root@burgess httpd24]# apachectl stop
AH00526: Syntax error on line 31 of/etc/httpd24/extra/httpd-manual.conf:
Invalid command 'LanguagePriority', perhapsmisspelled or defined by a module not included in the server configuration
([root@burgess httpd24]# vim /etc/httpd24/extra/httpd-manual.conf
# AddLanguage da .da
# SetEnvIf Request_URI ^/manual/(da|de|en|es|fr|ja|ko|pt-br|ru|tr|zh-cn)/prefer-language=$1
# RedirectMatch 301^/manual(?:/(da|de|en|es|fr|ja|ko|pt-br|ru|tr|zh-cn)){2,}(/.*)?$ /manual/$1$2
# LanguagePriority en da de es fr ja ko pt-br ru tr
# ForceLanguagePriority Prefer Fallback #………………如果语言类再报错,则执行此蓝色步骤;此步骤在开启LoadModulenegotiation_module modules/mod_negotiation.so 之前会有报错,需要执行,开启之后未有时间测试)
#将上面关于语言的选项全部注释掉,则不会再报错
访问浏览器,则显示
3.9 切换使用的MPM
[root@burgess ~]# vim /etc/httpd24/httpd.conf
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
LoadModule mpm_event_module modules/mod_mpm_event.so #.........将上一行注释掉,改为event模块
用apachectl关闭&开启,再用httpd -M查看 mpm_event_module(shared) 已经装载;还可用ps aux | grep ‘httpd’查看此时的httpd进程服务次数
3.10 服务脚本启用;
[root@burgess ~]# cphttpd /etc/rc.d/init.d/httpd24
[root@burgess ~]# cd/usr/local/apache/logs
[root@burgess logs]# ls
access_log error_log httpd.pid 将其路径修改为/var/run/httpd/httpd.conf
[root@burgess ~]# vim /etc/httpd24/httpd.conf
LoadModule cgi_module modules/mod_cgi.so #因为很多模块编译了,但是没有启动,所以启用cgi模块,;
# least PidFile.
PidFile "/var/run/httpd/httpd.conf" #新添加Pid路径 ;要先停掉apachectl服务;
[root@burgess apache]# chkconfig --add httpd24
[root@burgess apache]# chkconfig --list httpd24
httpd24 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@burgess apache]# service httpd24 start …………………..此时启用httpd2.4需要此类选项操作(restart,stop,status等都可以使用了)
此时编译安装已完成,httpd2.4version可以正常使用了