Apache靜態編譯與動態編譯詳解

來源:互聯網
上載者:User

標籤:

Apache擁有4層結構,從核心到外層的module。而外層的module可以用通過靜態和動態兩種方式與Apache共同工作。這也就引入下文的“動態”和“靜態”兩種編譯安裝方式:

靜態編譯:

編譯的時候,所有的模組自己編譯進 httpd 這個檔案中 ,啟動Apache的時候這些模組就已經載入進來了,可以直接來使用,而不用再 httpd.conf 中在 LoadModule 來載入,只要在 <ifmodule></ifmodule> 中來配置就可以了。

動態編譯:

編譯的時候,使用enable-MODULE=shared 或者enable-mods-shared=MODULE來動態編譯。 動態顯然就不編譯到httpd裡面去了,啟動的時候根本不會載入這個模組, 而是給你一個module.so 檔案。你想用,就在httpd.conf中使用 loadmodule 這個文法來載入,這個模組才有效。

區別是:

靜態模組通常在http.conf中用<ifmodule></ifmodule> 來配置,動態要先loadmoule來載入,然後再<ifmodule></ifmodule>配置。

官方說靜態比動態在效能方面多5%左右。

相對來說,靜態效率高些,而動態方式配置方面靈活。想想如果編譯進去的C這個module你想升級或者去掉,靜態方式的就只能重新編譯Apache了。

下面這句在Apache源檔案夾下運行,可以查看預設情況下Apache都給你裝了那些module進去:

./configure –help | grep disable

讓Apache日後可以動態編譯和載入模組:

如果想讓Apache日後可以支援動態編譯(DSO)更多的module,需要在初次安裝時把so這個模組編譯到核心(即,靜態編譯)。

如果編譯中包含任何DSO模組,則mod_so會被自動包含進核心。如果希望核心以後能夠裝載DSO,但不實際編譯任何DSO模組,則需明確指定:

針對apache1.x: --enable-module=so

針對apache2.x: --enable-so=static

Apache模組的類型:

基本(B)模組預設包含,必須明確禁用;

擴充(E)/實驗(X)模組預設不包含,必須明確啟用。

那麼,針對以上這些類型的模組,有以下幾種操作方式:

--disable-MODULE

禁用MODULE模組(僅用於基本模組)

--enable-MODULE=shared

將MODULE編譯為DSO(可用於所有模組)

--enable-MODULE=static

將MODULE靜態串連進核心(僅用於擴充和實驗模組)

--enable-mods-shared=MODULE-LIST

將MODULE-LIST中的所有模組都編譯成DSO(可用於所有模組)

--enable-modules=MODULE-LIST

將MODULE-LIST靜態串連進核心(可用於所有模組)

針對--enable-modules和--enable-mods-shared有兩個懶辦法就是 most參數和all參數,分別表示“很多的”和“所有”。

例如:

mod_alias是個基本模組,不想安裝的話就: --disable-alias

mod_rewrite是個擴充模組,想動態載入它:--enable-rewrite=shared,想靜態載入就是:--enable-rewrite=static

想靜態編譯mod_alias和mod_rewrite:--enable-modules=‘alias rewrite‘

想動態編譯mod_alias和mod_rewrite:--enable-mods-shared=‘alias rewrite‘

針對Apache2.2.x的一些例子:

最大化靜態安裝Apache:

./configure --prefix=/usr/local/apache --enable-modules=all

最大化動態安裝Apache:

./configure --prefix=/usr/local/apache --enable-mods-shared=all

靜態安裝rewrite、動態安裝deflate以及headers

./configure --prefix=/usr/local/apache --enable-rewrite=static --enable-deflate=shared --enable-headers=shared

不安裝基本的alais,保留以後的擴充DSO能力:

./configure --prefix=/usr/local/apache --enable-so=static --disable-alias

 

 

在Apache的源碼目錄,運行命令 ./configure -help 可查看所有編譯參數解釋

[[email protected] ~]# cd /usr/local/src/httpd-2.2.22[[email protected] httpd-2.2.22]# ./configure -help`configure‘ configures this package to adapt to many kinds of systems.Usage: ./configure [OPTION]... [VAR=VALUE]...To assign environment variables (e.g., CC, CFLAGS...), specify them asVAR=VALUE.  See below for descriptions of some of the useful variables.Defaults for the options are specified in brackets.Configuration:  -h, --help              display this help and exit      --help=short        display options specific to this package      --help=recursive    display the short help of all the included packages  -V, --version           display version information and exit  -q, --quiet, --silent   do not print `checking...‘ messages      --cache-file=FILE   cache test results in FILE [disabled]  -C, --config-cache      alias for `--cache-file=config.cache‘  -n, --no-create         do not create output files      --srcdir=DIR        find the sources in DIR [configure dir or `..‘]Installation directories:  --prefix=PREFIX         install architecture-independent files in PREFIX                          [/usr/local/apache2]  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX                          [PREFIX]By default, `make install‘ will install all the files in`/usr/local/apache2/bin‘, `/usr/local/apache2/lib‘ etc.  You can specifyan installation prefix other than `/usr/local/apache2‘ using `--prefix‘,for instance `--prefix=$HOME‘.For better control, use the options below.Fine tuning of the installation directories:  --bindir=DIR            user executables [EPREFIX/bin]  --sbindir=DIR           system admin executables [EPREFIX/sbin]  --libexecdir=DIR        program executables [EPREFIX/libexec]  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]  --libdir=DIR            object code libraries [EPREFIX/lib]  --includedir=DIR        C header files [PREFIX/include]  --oldincludedir=DIR     C header files for non-gcc [/usr/include]  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]  --infodir=DIR           info documentation [DATAROOTDIR/info]  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]  --mandir=DIR            man documentation [DATAROOTDIR/man]  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]  --htmldir=DIR           html documentation [DOCDIR]  --dvidir=DIR            dvi documentation [DOCDIR]  --pdfdir=DIR            pdf documentation [DOCDIR]  --psdir=DIR             ps documentation [DOCDIR]System types:  --build=BUILD     configure for building on BUILD [guessed]  --host=HOST       cross-compile to build programs to run on HOST [BUILD]  --target=TARGET   configure for building compilers for TARGET [HOST]Optional Features:  --disable-option-checking  ignore unrecognized --enable/--with options  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]  --enable-layout=LAYOUT  --enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections  --enable-exception-hook Enable fatal exception hook  --enable-maintainer-mode                          Turn on debugging and compile time warnings  --enable-pie            Build httpd as a Position Independent Executable  --enable-modules=MODULE-LIST                          Space-separated list of modules to enable | "all" |                          "most"  --enable-mods-shared=MODULE-LIST                          Space-separated list of shared modules to enable |                          "all" | "most"  --disable-authn-file    file-based authentication control  --enable-authn-dbm      DBM-based authentication control  --enable-authn-anon     anonymous user authentication control  --enable-authn-dbd      SQL-based authentication control  --disable-authn-default authentication backstopper  --enable-authn-alias    auth provider alias  --disable-authz-host    host-based authorization control  --disable-authz-groupfile                          ‘require group‘ authorization control  --disable-authz-user    ‘require user‘ authorization control  --enable-authz-dbm      DBM-based authorization control  --enable-authz-owner    ‘require file-owner‘ authorization control  --enable-authnz-ldap    LDAP based authentication  --disable-authz-default authorization control backstopper  --disable-auth-basic    basic authentication  --enable-auth-digest    RFC2617 Digest authentication  --enable-isapi          isapi extension support  --enable-file-cache     File cache  --enable-cache          dynamic file caching  --enable-disk-cache     disk caching module  --enable-mem-cache      memory caching module  --enable-dbd            Apache DBD Framework  --enable-bucketeer      buckets manipulation filter  --enable-dumpio         I/O dump filter  --enable-echo           ECHO server  --enable-example        example and demo module  --enable-case-filter    example uppercase conversion filter  --enable-case-filter-in example uppercase conversion input filter  --enable-reqtimeout     Limit time waiting for request from client  --enable-ext-filter     external filter module  --disable-include       Server Side Includes  --disable-filter        Smart Filtering  --enable-substitute     response content rewrite-like filtering  --disable-charset-lite  character set translation  --enable-charset-lite   character set translation  --enable-deflate        Deflate transfer encoding support  --enable-ldap           LDAP caching and connection pooling services  --disable-log-config    logging configuration  --enable-log-forensic   forensic logging  --enable-logio          input and output logging  --disable-env           clearing/setting of ENV vars  --enable-mime-magic     automagically determining MIME type  --enable-cern-meta      CERN-type meta files  --enable-expires        Expires header control  --enable-headers        HTTP header control  --enable-ident          RFC 1413 identity check  --enable-usertrack      user-session tracking  --enable-unique-id      per-request unique ids  --disable-setenvif      basing ENV vars on headers  --disable-version       determining httpd version in config files  --enable-proxy          Apache proxy module  --enable-proxy-connect  Apache proxy CONNECT module  --enable-proxy-ftp      Apache proxy FTP module  --enable-proxy-http     Apache proxy HTTP module  --enable-proxy-scgi     Apache proxy SCGI module  --enable-proxy-ajp      Apache proxy AJP module  --enable-proxy-balancer Apache proxy BALANCER module  --enable-ssl            SSL/TLS support (mod_ssl)  --enable-distcache      Select distcache support in mod_ssl  --enable-optional-hook-export                          example optional hook exporter  --enable-optional-hook-import                          example optional hook importer  --enable-optional-fn-import                          example optional function importer  --enable-optional-fn-export                          example optional function exporter  --enable-static-support Build a statically linked version of the support                          binaries  --enable-static-htpasswd                          Build a statically linked version of htpasswd  --enable-static-htdigest                          Build a statically linked version of htdigest  --enable-static-rotatelogs                          Build a statically linked version of rotatelogs  --enable-static-logresolve                          Build a statically linked version of logresolve  --enable-static-htdbm   Build a statically linked version of htdbm  --enable-static-ab      Build a statically linked version of ab  --enable-static-checkgid                          Build a statically linked version of checkgid  --enable-static-htcacheclean                          Build a statically linked version of htcacheclean  --enable-static-httxt2dbm                          Build a statically linked version of httxt2dbm  --enable-http           HTTP protocol handling  --disable-mime          mapping of file-extension to MIME  --enable-dav            WebDAV protocol handling  --disable-status        process/thread monitoring  --disable-autoindex     directory listing  --disable-asis          as-is filetypes  --enable-info           server information  --enable-suexec         set uid and gid for spawned processes  --disable-cgid          CGI scripts  --enable-cgi            CGI scripts  --disable-cgi           CGI scripts  --enable-cgid           CGI scripts  --enable-dav-fs         DAV provider for the filesystem  --enable-dav-lock       DAV provider for generic locking  --enable-vhost-alias    mass virtual hosting module  --disable-negotiation   content negotiation  --disable-dir           directory request handling  --enable-imagemap       server-side imagemaps  --disable-actions       Action triggering on requests  --enable-speling        correct common URL misspellings  --disable-userdir       mapping of requests to user-specific directories  --disable-alias         mapping of requests to different filesystem parts  --enable-rewrite        rule based URL manipulation  --enable-so             DSO capabilityOptional Packages:  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)  --with-included-apr     Use bundled copies of APR/APR-Util  --with-apr=PATH         prefix for installed APR or the full path to                             apr-config  --with-apr-util=PATH    prefix for installed APU or the full path to                             apu-config  --with-pcre=PATH        Use external PCRE library  --with-port=PORT        Port on which to listen (default is 80)  --with-sslport=SSLPORT  Port on which to securelisten (default is 443)  --with-z=DIR            use a specific zlib library  --with-sslc=DIR         RSA SSL-C SSL/TLS toolkit  --with-ssl=DIR          OpenSSL SSL/TLS toolkit  --with-mpm=MPM          Choose the process model for Apache to use.                          MPM={beos|event|worker|prefork|mpmt_os2|winnt}  --with-module=module-type:module-file                          Enable module-file in the modules/<module-type>                          directory.  --with-program-name     alternate executable name  --with-suexec-bin       Path to suexec binary  --with-suexec-caller    User allowed to call SuExec  --with-suexec-userdir   User subdirectory  --with-suexec-docroot   SuExec root directory  --with-suexec-uidmin    Minimal allowed UID  --with-suexec-gidmin    Minimal allowed GID  --with-suexec-logfile   Set the logfile  --with-suexec-safepath  Set the safepath  --with-suexec-umask     umask for suexec‘d processSome influential environment variables:  CC          C compiler command  CFLAGS      C compiler flags  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a              nonstandard directory <lib dir>  LIBS        libraries to pass to the linker, e.g. -l<library>  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if              you have headers in a nonstandard directory <include dir>  CPP         C preprocessorUse these variables to override the choices made by `configure‘ or to helpit to find libraries and programs with nonstandard names/locations.Report bugs to the package provider.[[email protected] httpd-2.2.22]# 

Apache靜態編譯與動態編譯詳解

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.