apache源码安装笔记0815

来源:互联网 发布:黑马程序员有用吗 编辑:程序博客网 时间:2024/04/28 06:26

    昨天加班太晚了,没什么时间搞,进行继续。。。。

    前天基本就算是把apache安装起来了,来点进阶点的吧

    1.大家都知道apache支持三种工作模式,prefork、worker、event,worker模式性能相对比较高,目前是大多web服务的首选,废话不多说,先看安装起来的apache的工作模式是什么

root@ubuntu:/usr/local/apache2/bin# ./httpd -lCompiled 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=workermake

发现编译的时候有好几个error(忘了是哪几个了),应该是之前prefork时产生的源文件没有替换掉,于是我直接把所有的文件都删除掉,重新来

./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=workermakemake installmake clean

跑到apache根目录下

root@ubuntu:/usr/local/apache2/bin# ./httpd -lCompiled 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算是到了一个里程碑了,能支持静态输出和动态输出,能满足网站最基本的需求了。接下来会再接触一些高阶特性和功能,使之能达到真正的商用环境。

原创粉丝点击