天天看点

Linux|UNIX下LAMP环境的搭建及常见问题[连载9编译Apache]

<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 &lt;IfDefine name&gt; 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,如需转载请自行联系原作者

继续阅读