1、編譯安裝httpd-2.4.25html
一、環境正則表達式
OS:CentOS6.5 x86_64apache
已安裝了經常使用的開發包組:vim
[root@Node4 ~]# yum grouplist Loaded plugins: fastestmirror Setting up Group Process Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com epel/group_gz | 150 kB 00:00 Installed Groups: Additional Development Desktop Platform Development #桌面平臺開發 Development tools #開發工具 E-mail server Fonts General Purpose Desktop Graphical Administration Tools Input Methods Legacy X Window System compatibility Milkymist Perl Support Security Tools Server Platform Development #服務器平臺開發 Installed Language Groups: Chinese Support [zh]
從官網獲取軟件包,並驗證其來源合法性及完整性:api
驗證方法:
bash
% pgpk -a KEYS % pgpv httpd-2.4.25.tar.gz.asc or % pgp -ka KEYS % pgp httpd-2.4.25.tar.gz.asc or % gpg --import KEYS % gpg --verify httpd-2.4.25.tar.gz.asc httpd-2.4.25.tar.gz
驗證:服務器
[root@Node4 ~]# [root@Node4 ~]# cd src [root@Node4 src]# ls apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz httpd-2.4.25.tar.gz httpd-2.4.25.tar.gz.asc KEYS [root@Node4 src]# gpg --import KEYS . . . gpg: Total number processed: 64 gpg: w/o user IDs: 4 gpg: unchanged: 60 [root@Node4 src]# gpg --verify httpd-2.4.25.tar.gz.asc httpd-2.4.25.tar.gz gpg: Signature made Sat 17 Dec 2016 02:25:00 AM CST using RSA key ID 791485A8 gpg: Good signature from "Jim Jagielski (Release Signing Key) <jim@apache.org>" #出現這一行說明這個簽名是有效的 gpg: aka "Jim Jagielski <jim@jaguNET.com>" gpg: aka "Jim Jagielski <jim@jimjag.com>" gpg: WARNING: This key is not certified with a trusted signature! #這個警告是由於本地密鑰庫不信任該公鑰 gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: A93D 62EC C3C8 EA12 DB22 0EC9 34EA 76E6 7914 85A8 [root@Node4 src]#
二、安裝httpd-2.4.25依賴的包
網絡
1)pcredom
httpd支持正則表達式依賴於pcre(正則表達式函數庫),須要安裝其開發包pcre-devel異步
[root@Node4 ~]# rpm -qa|grep pcre pcre-7.8-6.el6.x86_64 [root@Node4 ~]# yum install httpd -y #使用yum安裝pcre-devel包
注意:
能夠不卸載系統上yum安裝httpd和其依賴包,但必定要關閉httpd並禁止其開機啓動。建議刪掉
2)apr及apr-util
httpd-2.4 依賴於較高版本的apr(1.5以上)和apr-util
apr:apache portable runtime apache可移植執行環境
是一個api,一個底層庫,實現讓apache可以跨平臺的工具
[root@Node4 ~]# rpm -qa|grep apr #系統中自帶(或yum安裝)的apr版本低了,需編譯安裝apr及apr-util apr-1.3.9-5.el6_2.x86_64 apr-util-ldap-1.3.9-3.el6_0.1.x86_64 apr-util-1.3.9-3.el6_0.1.x86_64
編譯安裝apr:
[root@Node4 src]# tar xf apr-1.5.2.tar.gz [root@Node4 src]# cd apr-1.5.2 [root@Node4 apr-1.5.2]# ls apr-config.in buildconf dso libapr.rc NOTICE support apr.dep build.conf emacs-mode LICENSE NWGNUmakefile tables apr.dsp build-outputs.mk encoding locks passwd test apr.dsw CHANGES file_io Makefile.in poll threadproc apr.mak CMakeLists.txt helpers Makefile.win random time apr.pc.in config.layout include memory README tools apr.spec configure libapr.dep misc README.cmake user atomic configure.in libapr.dsp mmap shmem build docs libapr.mak network_io strings [root@Node4 apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@Node4 apr-1.5.2]# make && make install [root@Node4 apr-1.5.2]# ls /usr/local/apr/ bin build-1 include lib
編譯安裝apr-util:
[root@Node4 apr-1.5.2]# cd .. [root@Node4 src]# tar xf apr-util-1.5.4.tar.gz [root@Node4 src]# cd apr-util-1.5.4 [root@Node4 apr-util-1.5.4]# ls aprutil.dep buildconf dbd libaprutil.dsp NWGNUmakefile aprutil.dsp build.conf dbm libaprutil.mak README aprutil.dsw build-outputs.mk docs libaprutil.rc README.cmake aprutil.mak CHANGES encoding LICENSE renames_pending apr-util.pc.in CMakeLists.txt export_vars.sh.in Makefile.in strmatch apr-util.spec config.layout hooks Makefile.win test apu-config.in configure include memcache uri buckets configure.in ldap misc xlate build crypto libaprutil.dep NOTICE xml [root@Node4 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #apr-util依賴於apr因此要使用with-apr指定apr程序的位置 [root@Node4 apr-util-1.5.4]# make && make install [root@Node4 apr-util-1.5.4]# ls /usr/local/apr-util/ bin include lib
三、編譯安裝httpd-2.4.25
[root@Node4 apr-util-1.5.4]# cd .. [root@Node4 src]# tar xf httpd-2.4.25.tar.gz [root@Node4 src]# cd httpd-2.4.25 [root@Node4 httpd-2.4.25]# ls ABOUT_APACHE BuildBin.dsp emacs-style LAYOUT NOTICE srclib acinclude.m4 buildconf httpd.dep libhttpd.dep NWGNUmakefile support Apache-apr2.dsw CHANGES httpd.dsp libhttpd.dsp os test Apache.dsw CMakeLists.txt httpd.mak libhttpd.mak README VERSIONING apache_probes.d config.layout httpd.spec LICENSE README.cmake ap.d configure include Makefile.in README.platforms build configure.in INSTALL Makefile.win ROADMAP BuildAll.dsp docs InstallBin.dsp modules server
httpd編譯參數詳解:
[root@Node4 httpd-2.4.25]# ./configure --prefix=/usr/local/apache \ #安裝路徑 > --sysconfdir=/etc/httpd24 \ #配置文件路徑 > --enable-so \ #啓用支持動態共享模塊 > --enable-ssl \ #支持ssl > --enable-cgi \ #支持cgi > --enable-rewrite \ #支持URL重寫 > --with-zlib \ #依賴zlib庫文件,網絡上發送數據報文時通用壓縮庫的API > --with-pcre \ #指定依賴pcre包,不指定路徑,系統就會去系統中查找(rpm包的安裝路徑) > --with-apr=/usr/local/apr \ #指定依賴apr包路徑 > --with-apr-util=/usr/local/apr-util \ #指定依賴apr-util包路徑 > --enable-modules=most|all \ #安裝大多數模塊或所有模塊 > --enable-mpms-shared=all \ #以動態共享模塊方式安裝所有MPM > --with-mpm=event #指定默認使用event MPM
啓動並測試:
[root@Node4 httpd-2.4.25]# cd /usr/local/apache/ [root@Node4 apache]# ls bin build cgi-bin error htdocs icons include logs man manual modules [root@Node4 apache]# ls bin ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs [root@Node4 apache]# ./bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.10.4. Set the 'ServerName' directive globally to suppress this message httpd (pid 32245) already running
四、後續的配置
導出二進制程序:
# vim /etc/profile.d/apache.sh export PATH=/usr/local/apache/bin:$PATH
導出頭文件:
[root@Node4 apache]# ln -sv /usr/local/apache/include/ /usr/include/httpd `/usr/include/httpd' -> `/usr/local/apache/include/'
導出庫文件:沒有生成庫文件
導出man手冊:
# vi /etc/man.conf 添加 MANPATH /usr/local/apache/man 或者直接使用命令:man -M /usr/local/apache/man apache
建立SysV(System V)風格的服務腳本:
最簡單的方法是修改原yum安裝的httpd服務腳本
編譯安裝後httpd默認的pid文件路徑爲:
[root@Node4 apache]# ls logs access_log error_log httpd.pid
指定pid文件路徑:
在/etc/httpd2.4/httpd.conf中添加一行:PidFile "/var/run/httpd2.4.pid" #我這裏不修改
修改原yum安裝的http服務腳本:/etc/rc.d/init.d/httpd
# Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does
測試:
[root@Node4 ~]# service httpd Usage: httpd {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest} [root@Node4 ~]# service httpd status httpd (pid 49500) is running... [root@Node4 ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@Node4 ~]# service httpd status httpd (pid 49620) is running... [root@Node4 ~]# chkconfig --list httpd service httpd supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add httpd') [root@Node4 ~]# chkconfig --add httpd [root@Node4 ~]# chkconfig --list httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@Node4 ~]# chkconfig httpd on [root@Node4 ~]# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
注意:
編譯安裝2.4版本的主配置文件/etc/apache2.4沒有像yum安裝的2.2版本的主配置文件/etc/httpd/conf/httpd.conf同樣分爲三段,分段配置文件爲/etc/apache2.4/extra/*.conf
[root@Node4 apache]# cd /etc/httpd24/ [root@Node4 httpd24]# ls extra httpd.conf magic mime.types original [root@Node4 httpd24]# ls extra/ httpd-autoindex.conf httpd-languages.conf httpd-ssl.conf httpd-dav.conf httpd-manual.conf httpd-userdir.conf httpd-default.conf httpd-mpm.conf httpd-vhosts.conf httpd-info.conf httpd-multilang-errordoc.conf proxy-html.conf [root@Node4 httpd24]#
httpd-vhost.conf:配置虛擬主機
httpd-ssl.conf:配置ssl
httpd-mpm.conf:配置MPM
2、httpd-2.4新特性
一、MPM支持(DSO)運行時裝載
在httpd-2.2中MPM如何切換的?
編譯時使用下面的選項開啓該功能:
--enable-mpms-shared=all 編譯全部支持的MPM
--with-mpm=event 設定默認啓用的MPM
二、支持event MPM
三、支持異步讀寫
四、在每模塊及每目錄上指定日誌級別
五、每請求配置:<If>,<Elseif>
六、加強版的表達分析器
七、毫秒級的keepalive timout
八、基於FQDN的虛擬主機再也不須要NameVirtualHost指令
九、配置文件支持使用自定義變量
十、新增了一些模塊:mod_proxy_fcgi,mod_ratelimit,mod_request,mod_remoteip
對於基於IP的訪問控制作了修改:再也不支持用order,allow,deny這些機制而是統一使用require進行;中心主機和虛擬主機都必須明肯定義權限才能夠訪問,不然無權限訪問
十一、基於IP訪問控制
再也不支持使用order,allow,deny這些機制,而是統一使用require
容許全部主機訪問:Require all granted
拒絕全部主機訪問:Require all deny
控制某主機的訪問:
Require ip IPADDR
Require not ip IPADDR
IPADDR可以使用的格式:
能夠是單個IP地址, 例如:172.16.100.7
能夠是network/netmask 例如:172.16.0.0/255.255.0.0
network/Length 例如:172.16.0.0/16
Net 例如:172.16
Require host HOSTNAME
Require not host HOSTNAME
Hostname可以使用的格式:
FQDN:具體的主機 例如:www.magedu.com
DOMAIN: 域名 例如:.magedu.com
3、啓用服務器狀態
mod_status模塊可讓管理員查看服務器的執行狀態,它經過一個HTML頁面展現了當前服務器的統計數據。這些數據一般包括但不限於:
(1) 處於工做狀態的worker進程數;
(2) 空閒狀態的worker進程數;
(3) 每一個worker的狀態,包括此worker已經響應的請求數,及由此worker發送的內容的字節數;
(4) 當前服務器總共發送的字節數;
(5) 服務器自上次啓動或重啓以來至當前的時長;
(6) 平均每秒鐘響應的請求數、平均每秒鐘發送的字節數、平均每一個請求所請求內容的字節數;
查看是否裝載了該模塊:
[root@Node4 ~]# /usr/local/apache/bin/httpd -M|grep status status_module (shared)
啓用狀態頁面的方法很簡單,只須要在httpd主配置文件中添加以下內容便可:
<Location /server-status> SetHandler server-status Require all granted </Location>
須要提醒的是,這裏的狀態信息不該該被全部人隨意訪問,所以,應該限制僅容許某些特定地址的客戶端查看。好比使用Require ip 172.16.0.0/16來限制僅容許指定網段的主機查看此頁面。