编译安装Apache

温习编译Apahce的相关知识

预备知识

Makefile的惯例

  1. make clean 清除当前目录下在 make 过程中产生的文件。它不能删除软件包的配置文件,也不能删除 build 时创建的那些文件。
  2. make distclean 类似于”clean”,但增加删除当前目录下的的配置文件、build 过程产生的文件。
  3. make install-strip 和”make install”类似,但是会对复制到安装目录下的可执行文件进行 strip 操作。

make的常用选项

  1. -jN , –jobs[=N],指定并行执行的命令数目。
  2. -n –just-print,–dry-run,–recon,只打印出所要执的命令,但并不实际执行命令。
  3. -s –silent,–quit,不显示所执行的命令。

编译Apache的要求

  1. 磁盘空间
  2. ANSI-C编译器及编译环境
  3. 确保准确的时间
  4. Perl 5 [可选]
  5. apr/apr-util >= 1.2

apr和apr-util包含在Apache httpd的发行源代码中,并且在绝大多数情况下使用都不会出现问题。当然,如果apr或apr-util的1.0或1.1版本已经安装在你的系统中了,则必须将你的apr/apr-util升级到1.2版本,或者将httpd单独分开编译。要使用发行源代码中自带的apr/apr-util源代码进行安装,你必须手动完成:
# 编译和安装 apr 1.2
cd srclib/apr
./configure –prefix=/usr/local/apr-httpd/
make
make install

# 编译和安装 apr-util 1.2
cd ../apr-util
./configure –prefix=/usr/local/apr-util-httpd/ –with-apr=/usr/local/apr-httpd/
make
make install

# 配置 httpd
cd ../../
./configure –with-apr=/usr/local/apr-httpd/ –with-apr-util=/usr/local/apr-util-httpd/

Apache的模块状态

通常我们认为Apache的模块分五类:多路处理模块(MPM),基本模块(Base),扩展模块(Extension),实验性模块(Experimental),第三方模块(External)。
关于各模块的状态详情可以查看手册。第三方模块不包含在发行版中,手册中只标识了四种状态:

M 多路处理模块 必须有且仅有一个MPM被静态编译到服务器中。
B 基本模块 默认包含,必须明确禁用。
E 扩展模块 默认不包含,必须明确启用。
X 试验模块 默认不包含,必须明确启用。

Apache的基本模块

Apache 2.2.14 默认被静态编译进httpd的模块:

核心模块

不可或缺
core.c
http_core.c
mod_so.c
prefork.c(Linux上默认是prefork.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
mod_mime.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_cgi.c
mod_negotiation.c
mod_dir.c
mod_actions.c
mod_userdir.c
mod_alias.c

我的Apache的常用模块

最简单的认证模块组合

[B]mod_auth_basic.c 或
[E]mod_auth_digest.c 加 (2.2.14版时,已经由实验模块转为扩展模块)
[B]mod_authn_file.c 加
[B]mod_authz_user.c
注意!basic加密方式密码是明文传送的,不安全,建议使用digest方式的认证。

保护认证而加载的模块

[B]mod_authn_default.c
[B]mod_authz_default.c
出于安全考虑,强烈建议加载!

最常用的访问控制模块

[B]mod_authz_host.c
提供基与主机名、IP地址以及请求特征的访问控制。

其它常用模块

[B]mod_log_config.c
[B]mod_alias.c
[B]mod_dir.c
[B]mod_mime.c
[B]mod_setenvif.c
[E]mod_rewrite.c
[E]mod_deflate.c
[E]mod_expires.c
[E]mod_headers.c

我常用的编译指令


1. ./configure --prefix=/opt/httpd-2.2.14 --with-mpm=prefork --enable-mods-shared=all LDFLAGS='-s'
2. ./configure --prefix=/opt/httpd-2.2.14 --with-mpm=prefork --enable-mods-shared=all --enable-cache --enable-mem-cache --enable-ssl --enable-file-cache --enable-disk-cache --enable-proxy --enable-proxy-http LDFLAGS='-s'
3. ./configure --prefix=/opt/httpd-2.2.14 --with-mpm=prefork --enable-mods-shared=all --enable-dir=static --enable-authz-host=static --enable-auth-basic=static --enable-authn_file=static --enable-authz_user=static --enable-authn-default=static --enable-authz-default=static --enable-setenvif=static --enable-alias=static --enable-log-config=static --enable-deflate=static --enable-rewrite=static --enable-mime=static --enable-expires=static --enable-cache=static --enable-mem-cache=static --enable-headers=shared --enable-disk-cache=shared --enable-file-cache=shared LDFLAGS='-s'

注意:因为Apache的./configure生成的Makefile不支持make install-strip,所以使用 LDFLAGES=’-s’来编译被strip的代码。

参考:
深入理解软件包的配置、编译与安装
Apache 2.2 手册-编译与安装
Apache 2.2 手册-动态共享对象支持
Apache 2.2 手册-各模块的简介描述
Apache 2.2 手册-描述模块的术语
Apache 2.2 手册-指令速查

On this day..

Tags: , , , ,

Leave a comment