apache源碼安裝筆記0815

    昨天加班太晚了,沒什麼時間搞,進行繼續。。。。

    前天基本就算是把apache安裝起來了,來點進階點的吧

    1.大家都知道apache支持三種工作模式,prefork、worker、event,worker模式性能相對比較高,目前是大多web服務的首選,廢話不多說,先看安裝起來的apache的工作模式是什麼

root@ubuntu:/usr/local/apache2/bin# ./httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  mod_version.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgid.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_so.c

重點關注到了prefork.c,那麼可以知道目前是prefork模式。到conf/extra/http-mpm.conf中,看到prefork的配置已經存在

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

這個是prefork模式對應的配置,各個配置項就不細說了,註釋裏面都解釋清楚了,這裏主要是prefork模式的進程數配置。

由於我現在想改爲worker模式,我需要檢查一下這個配置文件中是否已經存在worker模式的配置,找到了

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

同樣的,這裏主要是worker模式的進程和線程數量的配置(如果不存在這個配置,需要添加一下)。檢查完這裏,還需要到conf/httpd.conf中保護這個httpd-mpm.conf文件

# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf

由於apache的各個工作模式都在代碼級別做了相應的優化和加速,而且web服務與apache工作模式是有點關聯的,所以apache沒有將兩種模式的代碼一起編譯,apache的工程師們認爲使用者應該在編譯安裝階段就確定好使用什麼模式。好了,開始真正的切換工作吧。

轉到apache根目錄,重新部署和編譯源文件

./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker
make

發現編譯的時候有好幾個error(忘了是哪幾個了),應該是之前prefork時產生的源文件沒有替換掉,於是我直接把所有的文件都刪除掉,重新來

./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker
make
make install
make clean

跑到apache根目錄下

root@ubuntu:/usr/local/apache2/bin# ./httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  mod_version.c
  worker.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgid.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_so.c

可以注意到有一個worker.c,說明已經是worker工作模式,大功告成。啓動apache

2.修改vhost配置,支持動態網頁的輸出在conf/extra/httpd-vhost.conf的vhost配置中增加

ScriptAlias /cgi-bin/ "/usr/local/apache2/docs/cgi-examples/"

重啓apache,然後在瀏覽器中輸入

http://192.168.148.128/cgi-bin/test-cgi

觀察到有執行了腳本程序,並且返回了結果,這樣,表明apache已經支持動態輸出了。
到這裏,我的Apache算是到了一個里程碑了,能支持靜態輸出和動態輸出,能滿足網站最基本的需求了。接下來會再接觸一些高階特性和功能,使之能達到真正的商用環境。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章