一、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可以正常使用了