<b>六、編譯Apache</b>
<b>配置編譯選項</b>
請根據伺服器架構和實際應用添加相應的子產品。
現在對伺服器性能密切的MPM子產品做一下解釋。
下面的内容為Apache 2.2中文文檔内容(非官方)
多路處理子產品(MPM)
workerMPM使用多個子程序,每個子程序中又有多個線程。每個線程處理一個請求。該MPM通常對高流量的伺服器是一個不錯的選擇。因為它比preforkMPM需要更少的記憶體且更具有伸縮性。
preforkMPM使用多個子程序,但每個子程序并不包含多線程。每個程序隻處理一個連結。在許多系統上它的速度和workerMPM一樣快,但是需要更多的記憶體。這種無線程的設計在某些情況下優于workerMPM:它可以應用于不具備線程安全的第三方子產品(比如php3/4/5),且在不支援線程調試的平台上易于調試,而且還具有比workerMPM更高的穩定性。
用worker還是用prefork一要看伺服器的架構,二要應用,要看是是穩定性和相容性更重要,還是性能特别重要呢。我這裡選擇了preforkMPM
預設情況下,APR在每個目标OS/CPU上使用其最有效的特性執行這些操作。比如許多現代CPU的指令集中有一個原子的比較交換 (compare-and-swap, CAS)操作指令。在一些老式平台上,APR預設使用一種緩慢的、基于互斥執行的原子API以保持對沒有CAS指令的老式CPU的相容。如果你隻打算在新 式的CPU上運作Apache,你可以在編譯時使用 --enable-nonportable-atomics 選項:
./buildconf
./configure --with-mpm=worker --enable-nonportable-atomics=yes
在添加子產品支援前請務必把mode-ssl這個子產品加上,并且要添加OpenSSL支援
我們分别通過--enable-ssl --with-ssl=/usr/local/openssl/lib這兩個選項來實作。
# ./configure --prefix=/usr/local/httpd-2.2.11 --docdir=/data/web --enable-so --enable-cgi --enable-mime-magic --enable-ssl --with-ssl=/usr/local/openssl/lib --with-mpm=prefork --enable-modules=most --enable-mods-shared=all --enable-rewrite
<b>編譯并安裝</b>
# make
# make install
建立一個軟連結
# cd /usr/local;ln –s /usr/local/httpd-2.2.11 apache
<b>手動啟動Apache</b>
/usr/local/apache/bin/apachectl會顯示幫助資訊
# /usr/local/apache/bin/apachectl
Usage: /usr/local/httpd-2.2.11/bin/httpd [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-k start|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
-D name : define a name for use in <IfDefine name> directives
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
-C "directive" : process directive before reading config files
-c "directive" : process directive after reading config files
-e level : show startup errors of level (see LogLevel)
-E file : log startup errors to file
-v : show version number
-V : show compile settings
-h : list available command line options (this page)
-l : list compiled in modules
-L : list available configuration directives
-t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)
-S : a synonym for -t -D DUMP_VHOSTS
-t -D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t : run syntax check for config files
啟動用
# /usr/local/apache/bin/apachectl start
在早前的apache版本支援startssl的操作方式,但這個版本中把這個參數給廢除了。
# /usr/local/apache/bin/apachectl startssl
The startssl option is no longer supported.
Please edit httpd.conf to include the SSL configuration settings
and then use apachectl start.
同時它提示了我們進一步的操作:編譯http.conf配置檔案添加SSL相關的設定,這個我們也會在下一個章節做詳細闡述。
<b>添加服務</b>
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
# vi /etc/init.d/httpd
如果是在Redhat或相關的作業系統上,請在#!/bin/sh 下面添加下面的幾段話,目的是使chkconfig和service指令有控制這個服務的能力。
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
有必要簡單地說明一下,關于chkconfig的字段的含意。chkconfig和description字段可以被Redhat等一些發行版的chkconfig和service 指令識别,其中第二部分表示在哪些運作級别下服務開啟,第三部分和第四部分分别表示啟動和關閉的優先級别(順序)。
添加到chkconfig清單中
# chkconfig –add httpd
# chkconfig httpd on
啟動服務的方法:
/etc/init.d/httpd start或者service httpd start(隻支援RedHat系列的系統)
# service httpd start
本文轉自xiaoyuwang 51CTO部落格,原文連結:http://blog.51cto.com/wangxiaoyu/206489,如需轉載請自行聯系原作者