Apache的核心思想就是模块化,将不同的功能抽成模块,当我们需要某个功能的时候,加载对应的模块就可以了,问题来了,模块我们要如何加载?这里我们就需要讨论Apache的动态和静态编译了。
动态编译即在编译的时候,通过使用--enable-mods-shared=[module] 或者--enable-[module]=shared指令来指定哪个【module】是动态动态编译;静态编译即不加以shared符号等修饰符修饰的;在静态模块中,Apache使用<ifmodule></ifmodule>来配置文件,而动态模块,Apache以loadmoule来加载模块,示例如下:
1 #以下命令将默认以静态形式进行编译 2 ./configure --prefix=/usr/local/apache2 3 . 4 . 5 . 6 7 [root@localhost bin]# pwd 8 /usr/local/apache2/bin 9 [root@localhost bin]# ./apachectl -l 10 Compiled in modules: 11 core.c 12 mod_authn_file.c 13 mod_authn_default.c 14 mod_authz_host.c 15 mod_authz_groupfile.c 16 mod_authz_user.c 17 mod_authz_default.c 18 mod_auth_basic.c 19 mod_include.c 20 mod_filter.c 21 mod_log_config.c 22 mod_env.c 23 mod_setenvif.c 24 prefork.c 25 http_core.c 26 mod_mime.c 27 mod_status.c 28 mod_autoindex.c 29 mod_asis.c 30 mod_cgi.c 31 mod_negotiation.c 32 mod_dir.c 33 mod_actions.c 34 mod_userdir.c 35 mod_alias.c 36 mod_so.c
1 #以下命令会将除了核心模块外的其他模块编译成动态模块 2 [root@localhost httpd-2.2.9]# ./configure -prefix=/usr/local/apache2 --enable-mods-shared=all 3 . 4 . 5 . 6 7 [root@localhost bin]# pwd 8 /usr/local/apache2/bin 9 [root@localhost bin]# ./apachectl -M 10 httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName 11 Loaded Modules: 12 core_module (static)-->代表静态模块 13 mpm_prefork_module (static) 14 http_module (static) 15 so_module (static) 16 authn_file_module (shared)-->代表动态模块 17 authn_dbm_module (shared) 18 authn_anon_module (shared) 19 authn_dbd_module (shared) 20 authn_default_module (shared) 21 authz_host_module (shared) 22 authz_groupfile_module (shared) 23 authz_user_module (shared) 24 authz_dbm_module (shared) 25 authz_owner_module (shared) 26 authz_default_module (shared) 27 auth_basic_module (shared) 28 auth_digest_module (shared) 29 dbd_module (shared) 30 dumpio_module (shared) 31 ext_filter_module (shared) 32 include_module (shared) 33 filter_module (shared) 34 substitute_module (shared) 35 deflate_module (shared) 36 log_config_module (shared) 37 log_forensic_module (shared) 38 logio_module (shared) 39 env_module (shared) 40 mime_magic_module (shared) 41 cern_meta_module (shared) 42 expires_module (shared) 43 headers_module (shared) 44 ident_module (shared) 45 usertrack_module (shared) 46 unique_id_module (shared) 47 setenvif_module (shared) 48 version_module (shared) 49 mime_module (shared) 50 dav_module (shared) 51 status_module (shared) 52 autoindex_module (shared) 53 asis_module (shared) 54 info_module (shared) 55 cgi_module (shared) 56 dav_fs_module (shared) 57 vhost_alias_module (shared) 58 negotiation_module (shared) 59 dir_module (shared) 60 imagemap_module (shared) 61 actions_module (shared) 62 speling_module (shared) 63 userdir_module (shared) 64 alias_module (shared) 65 rewrite_module (shared)
1 #以下命令会将以shared结尾的编译成动态模块,其他的编译成静态模块 2 [root@localhost httpd-2.2.9]# ./configure -prefix=/usr/local/apache2 --enable-modules=all 3 --enable-cache=shared 4 --enable-cache=shared 5 --enable-mem-cache=shared 6 --enable-file-cache=shared 7 --enable-rewrite=shared 8 . 9 . 10 . 11 [root@localhost bin]# pwd 12 /usr/local/apache2/bin 13 [root@localhost bin]# ./apachectl -M 14 httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName 15 Loaded Modules: 16 core_module (static) 17 authn_file_module (static) 18 authn_dbm_module (static) 19 authn_anon_module (static) 20 authn_dbd_module (static) 21 authn_default_module (static) 22 authz_host_module (static) 23 authz_groupfile_module (static) 24 authz_user_module (static) 25 authz_dbm_module (static) 26 authz_owner_module (static) 27 authz_default_module (static) 28 auth_basic_module (static) 29 auth_digest_module (static) 30 dbd_module (static) 31 dumpio_module (static) 32 ext_filter_module (static) 33 include_module (static) 34 filter_module (static) 35 substitute_module (static) 36 deflate_module (static) 37 log_config_module (static) 38 log_forensic_module (static) 39 logio_module (static) 40 env_module (static) 41 mime_magic_module (static) 42 cern_meta_module (static) 43 expires_module (static) 44 headers_module (static) 45 ident_module (static) 46 usertrack_module (static) 47 unique_id_module (static) 48 setenvif_module (static) 49 version_module (static) 50 mpm_prefork_module (static) 51 http_module (static) 52 mime_module (static) 53 dav_module (static) 54 status_module (static) 55 autoindex_module (static) 56 asis_module (static) 57 info_module (static) 58 cgi_module (static) 59 dav_fs_module (static) 60 vhost_alias_module (static) 61 negotiation_module (static) 62 dir_module (static) 63 imagemap_module (static) 64 actions_module (static) 65 speling_module (static) 66 userdir_module (static) 67 alias_module (static) 68 so_module (static) 69 file_cache_module (shared) 70 cache_module (shared) 71 mem_cache_module (shared) 72 rewrite_module (shared) 73 Syntax OK
默认情况下,Apache将几个核心的模块通过静态的方式编译到了文件中,我们可以通过命令apachectl -l来查看,静态编译的好处:一是可以提高运行效率,据不完全统计,静态编译进文件中的模块比动态加载的模块效率高出5%左右,但是比起动态模块来讲,在维护性方面就没有动态模块方便。