编译httpd细节

html { font-family: sans-serif }
body { margin: 0 }
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary { display: block }
audio,canvas,progress,video { display: inline-block; vertical-align: baseline }
audio:not([controls]) { display: none; height: 0 }
[hidden],template { display: none }
a { background: transparent }
a:active,a:hover { outline: 0 }
abbr[title] { border-bottom: 1px dotted }
b,strong { font-weight: bold }
dfn { font-style: italic }
h1 { font-size: 2em; margin: 0.67em 0 }
mark { background: #ff0; color: #000 }
small { font-size: 80% }
sub,sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline }
sup { top: -0.5em }
sub { bottom: -0.25em }
img { border: 0 }
svg:not(:root) { overflow: hidden }
figure { margin: 1em 40px }
hr { height: 0 }
pre { overflow: auto }
code,kbd,pre,samp { font-family: monospace, monospace; font-size: 1em }
button,input,optgroup,select,textarea { color: inherit; font: inherit; margin: 0 }
button { overflow: visible }
button,select { text-transform: none }
button,html input[type="button"],input[type="reset"],input[type="submit"] { cursor: pointer }
button[disabled],html input[disabled] { cursor: default }
button::-moz-focus-inner,
input::-moz-focus-inner { border: 0; padding: 0 }
input { line-height: normal }
input[type="checkbox"],input[type="radio"] { padding: 0 }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { height: auto }
input[type="search"] { }
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { }
fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em }
legend { border: 0; padding: 0 }
textarea { overflow: auto }
optgroup { font-weight: bold }
table { border-collapse: collapse; border-spacing: 0 }
td,th { padding: 0 }
* { }
*::before,*::after { }
html { font-size: 62.5% }
body { font-family: "Helvetica Neue", Helvetica, Arial, "Microsoft Yahei", sans-serif; font-size: 14px; line-height: 1.42857143; color: #333333 }
input,button,select,textarea { font-family: inherit; font-size: inherit; line-height: inherit }
a { color: #428bca; text-decoration: none }
a:hover,a:focus { color: #2a6496; text-decoration: underline }
a:focus { outline: 5px auto -webkit-focus-ring-color }
figure { margin: 0 }
img { vertical-align: middle }
.hljs { display: block; padding: 0.5em; color: #333; background: #f8f8f8 }
.hljs-comment,.hljs-template_comment,.diff .hljs-header,.hljs-javadoc { color: #998; font-style: italic }
.hljs-keyword,.css .rule .hljs-keyword,.hljs-winutils,.javascript .hljs-title,.nginx .hljs-title,.hljs-subst,.hljs-request,.hljs-status { color: #333; font-weight: bold }
.hljs-number,.hljs-hexcolor,.ruby .hljs-constant { color: #099 }
.hljs-string,.hljs-tag .hljs-value,.hljs-phpdoc,.tex .hljs-formula { color: #d14 }
.hljs-title,.hljs-id,.coffeescript .hljs-params,.scss .hljs-preprocessor { color: #900; font-weight: bold }
.javascript .hljs-title,.lisp .hljs-title,.clojure .hljs-title,.hljs-subst { font-weight: normal }
.hljs-class .hljs-title,.haskell .hljs-type,.vhdl .hljs-literal,.tex .hljs-command { color: #458; font-weight: bold }
.hljs-tag,.hljs-tag .hljs-title,.hljs-rules .hljs-property,.django .hljs-tag .hljs-keyword { color: #000080; font-weight: normal }
.hljs-attribute,.hljs-variable,.lisp .hljs-body { color: #008080 }
.hljs-regexp { color: #009926 }
.hljs-symbol,.ruby .hljs-symbol .hljs-string,.lisp .hljs-keyword,.tex .hljs-special,.hljs-prompt { color: #990073 }
.hljs-built_in,.lisp .hljs-title,.clojure .hljs-built_in { color: #0086b3 }
.hljs-preprocessor,.hljs-pragma,.hljs-pi,.hljs-doctype,.hljs-shebang,.hljs-cdata { color: #999; font-weight: bold }
.hljs-deletion { background: #fdd }
.hljs-addition { background: #dfd }
.diff .hljs-change { background: #0086b3 }
.hljs-chunk { color: #aaa }
#container { padding: 15px }
pre { border: 1px solid #ccc; display: block; background-color: #f8f8f8 }
pre code { white-space: pre-wrap }
.hljs,code { font-family: Monaco, Menlo, Consolas, "Courier New", monospace }
:not(pre)>code { padding: 2px 4px; font-size: 90%; color: #c7254e; background-color: #f9f2f4; white-space: nowrap }

本文目录
1.1 下载和解决依赖关系
1.2 httpd编译选项
1.3 模块动静态编译
1.4 动静态编译的优先级规则
1.5 MPM的安装
1.6 关于"--enable-so"
1.7 开始编译httpd
1.8 编译后的规范操作

1.1 下载和解决依赖

以httpd 2.4.27为例。

资源下载:

apache自己的站点提供了基金会下所有的(包括所有版本)资源,包括httpd。

地址:http://archive.apache.org/dist/
httpd下载地址:http://archive.apache.org/dist/httpd

清华大学有一个httpd归档的镜像站点,里面提供最新测试版和最新稳定版的下载,还提供一些依赖包或模块的下载。

地址:http://mirrors.tuna.tsinghua.edu.cn/apache/httpd/
apache基金会下所有资源地址:http://mirrors.tuna.tsinghua.edu.cn/apache/

httpd同样使用"./configure"、"make && make install"的编译流程编译。但是它有一些依赖包需要提前装好。官方上指定的依赖环境有:apr、apr-util、pcre、pcre-devle,此外还需要expat-devel包。其中pcre、pcre-devel和expat.devel可以直接使用yum安装,apr和apr-util需要编译安装。下载地址可以从站点 http://mirrors.tuna.tsinghua.edu.cn/apache/ap/ 找到。

yum -y install pcre pcre-devel expat-devel

以下是编译apr和apr-util的过程。

tar xf apr-1.6.2.tar.gz
tar xf arp-1.6.0.tar.gz
cd apr-1.6.0
./configure --prefix=/usr/local/apr
make
make install
cd ../apr-util-1.6.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

然后是编译httpd,httpd编译对刚接触的人来说可能有些麻烦,因为编译选项太多,其中的一些"潜规则"也不太熟悉。所以下面详细地说明说明。

1.2 httpd编译选项

httpd的编译选项非常多。以下是截取./configure -h中的一部分,使用"......"表示省略了一堆信息。

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 specify
an 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]
........................................

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-dtrace         Enable DTrace probes
  --enable-hook-probes    Enable APR hook probes
  --enable-exception-hook Enable fatal exception hook
  --enable-load-all-modules
                          Load all modules
  --enable-maintainer-mode
                          Turn on debugging and compile time warnings and load
                          all compiled modules
  --enable-debugger-mode  Turn on debugging and compile time warnings and turn
                          off optimization
  --enable-pie            Build httpd as a Position Independent Executable
  --enable-modules=MODULE-LIST
                          Space-separated list of modules to enable | "all" |
                          "most" | "few" | "none" | "reallyall"
  --enable-mods-shared=MODULE-LIST
                          Space-separated list of shared modules to enable |
                          "all" | "most" | "few" | "reallyall"
  --enable-mods-static=MODULE-LIST
                          Space-separated list of static modules to enable |
                          "all" | "most" | "few" | "reallyall"
.........................................

Optional 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
....................

以下是一个编译配置:

./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event

但这个配置中有些项是多余的,以下是等价编译配置:

./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --enable-mpms-shared=all --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event

具体哪些项多余,看完下面的1.3-1.6就知道了。

1.3 模块动静态编译

httpd是高度模块化的程序,各个功能通过加载各个模块来实现。但前提是将功能对应的模块先编译好,以供httpd加载。

httpd对模块有两种编译方式:静态编译和动态编译。

  • 静态编译:将模块直接编译进httpd的核心中。静态编译的所有模块都会随着httpd的启动和启动。
  • 动态编译:将模块编译好,但不编译到httpd的核心中。要启动动态编译的模块,需要在httpd的配置文件中使用LoadModule指令加载。

httpd的一个优点是可以实现动态模块的热插拔。因为httpd是独立于终端的守护进程,可以通过发送HUP信号给httpd让其重读配置文件。而是否加载动态编译模块正是由httpd配置文件中的LoadModule指令决定的。当想要加载某个模块A时(即模块热插),使用LoadModule指定A模块的链接地址,再发送HUP信号重读配置文件即可。而想要停止某个模块A时(即模块热拔),只需将对应模块的LoadModule指令行给注释,再重读配置文件即可。

甚至,可以随时动态编译某个外部模块到httpd中,然后再热插。因为何时编译需要动态加载的模块对httpd来说是无关紧要的,它只需LoadModule和重读配置文件两个过程对模块进行控制。

在编译选项中,有几种类型的选项:

--disable-FEATURE:禁用某特性,等价于--enable-FEATURE=no
--enable-FEATURE[=ARG]:启用某特性,默认参数值为YES
--enable-Module_Name=shared:指定的模块Module_Name以动态编译方式安装
--enable-Module_Name=static:指定的模块Module_Name以静态编译方式安装

对于./configure --help中给定的选项,如果该选项是--disable的,那么表示该选项默认是启用的,需要显式使用--disable选项禁用;如果该选项是--enable的,那么表示该选项默认是禁用的,需要使用--enable选项来启用。例如:

--disable-authz-user  :表示authz-user特性默认启用,编译时无需指定该项。如果要禁用,编译时需显式指定--disable-authz-user
--enable-echo    :表示echo特性默认是禁用的,如果要启用,则编译时需显式指定--enable-echo

模块名的书写是有规则的,一般模块的全称类似于"mod_BASENAME.so"格式,例如"mod_charset_lite.so",但在编译选项中指定模块时,只需指定BASENAME,且如果basename中包含下划线时,需要转换为短横线。例如"--enable-echo"表示编译的模块是"mod_echo.so"。

此外,还支持3种列表方式的动静态编译选项:列表项之间使用空格分隔,但要使用单引号包围。

--enable-modules=‘Module_Name1 Moduel_Name2‘
--enable-mods-shared=‘Module_Name1 Module_Name2‘
--enable-mods-statics=‘Module_Name1 Module_Name2‘

列表部分还可以使用关键字"all/few/most/reallyall"。分别表示编译所有、少量、大多数、真正的所有模块。

"--enable-modules"基本等价于"--enable-mods-shared",都是动态编译给定列表中的模块,但"--enable-modules"可以额外使用一个关键字"none",表示不编译所有模块。

1.4 动静态编译的优先级规则

httpd动静态模块编译有一套规则,各种动静态便宜选项之间有优先级的存在。例如,某个非核心模块既指定了动态编译,同时又指定了静态编译,那到底是静态还是动态编译?

以下是我总结的一些优先级规则。

  1. 不指定任何模块编译选项时,默认的选项为"--enable-mods-shared",而该选项的默认值又是most,所以等价于"--enable-mods-shared=most"。
  2. 显式指定要动态或静态编译的优先级最高。有以下几种方式显式指定:
    --enable-Module_Name=shared
    --enable-Module_Name=static
    --enable-mods-shared=‘Module_Name1 Module_Name2‘
    --enable-mods-statics=‘Module_Name1 Module_Name2‘
    --enable-modules=‘Module_Name1 Moduel_Name2‘
    

    如果某个模块既显式指定了动态,又显式指定了静态编译,则静态编译优先级更高。例如:

    --enable-echo=shared
    --enable-echo=static
    

    那么,mod_echo模块将被静态编译。

  3. 指定了关键字(all/most/few/reallyall)的"--enable-mods-static"选项,优先级高于指定或未指定关键字的"--enable-mods-shared"和"--enable-modules"选项,即静态关键字规则强于动态关键字规则。
    例如,下面两个编译配置中,都是"--enable-mods-static=few"生效。第二个编译配置语句中将忽略"--enable-mods-shared=all"。
    ./configure --prefix=/tmp/apache --enable-mods-static=few
    ./configure --prefix=/tmp/apache --enable-mods-static=few --enable-mods-shared=all
    

    对于下面的例子,authn-file和echo这两个模块既指定了动态编译又指定了静态编译,静态优先级高于动态,所以这两个模块静态被静态编译。由于没有使用关键字,所以会使用默认的"--enable-mods-shared=most"配置。即动态编译大部分,但指定的这两个模块被静态编译。

    ./configure --prefix=/tmp/apache --enable-mods-static=‘authn-file echo‘ --enable-mods-shared=‘authn-file echo‘
    

    而下面这个例子由于额外指定了使用"--enable-mods-static=few"选项,其优先级高于默认的"--enable-mods-shared=most",所以结果是静态编译few,且显式指定的两个模块也被静态编译。

    ./configure --prefix=/tmp/apache \
    --enable-mods-static=‘authn-file echo‘ \
    --enable-mods-shared=‘authn-file echo‘ \
    --enable-mods-static=few
    
  4. 使用了关键字的"--enable-mods-static"、"--enable-mods-shared "和"--enable-modules"的选项,隐含了"没有指定何种编译方式的模块"的默认编译方式。
    例如下面的编译配置,"--enable-mods-static"指定了关键字few,它将优先于默认的配置规则"--enable-mods-shared=most",所以没有指定编译方式的模块"data"将以静态的方式编译。
    ./configure --prefix=/tmp/apache --enable-mods-static=few --enable-data
    

    下面的配置如何编译的?由于默认的是"--enable-mods-shared=most"编译方式,所以模块"data"将以动态的方式编译。

    ./configure --prefix=/tmp/apache --enable-data
    

    再看下面的例子,配置中出现了"--enable-mods-static=few"和"--enable-mods-shared"(未给定值时也是默认为most),static的优先级高于shared,所以没有指定编译方式的模块"data"使用静态编译方式编译,而显式指定了编译方式的模块"echo"其优先级最强,所以动态编译"echo"。

    ./configure --prefix=/tmp/apache \
    --enable-mods-static=few --enable-mods-shared --enable-data --enable-echo=shared
    

1.5 MPM的安装

编译mpm模块(prefork/worker/event)和其他模块差不多,唯一的区别是必须至少编译一个mpm模块,且必须有且仅有一个加载被httpd加载。

编译安装时默认的mpm是event模式(和发行版有关)。但可以通过"--with-mpm=MPM_NAME"来指定被加载的mpm模块。以下是几个相关编译选项:

--with-mpm=MPM_Name:用于指定默认的mpm模块,它所指定的模块会被静态编译,并在httpd启动时加载。
--enable-mpms-shared=MPM-LIST:指定动态编译安装的MPM列表,动态编译的MPM必须使用LoadModule指令加载才能使用。

如果定"--with-mpm"选项指定了某个mpm,则默认该模块被静态编译,但如果同时使用"--enable-mpms-shared"指定了该mpm,则该mpm模块被动态编译。

如果某个mpm模块被静态编译,在httpd启动时会加载它,如果想要切换到其他mpm模块,只有一种方法:重新编译httpd。

而动态编译mpm模块时,则可以通过LoadModule来切换到其他mpm模块。由于编译时自带默认mpm模块,还可以使用"--with-mpm"指定默认mpm模块,所以动态编译mpm模块无疑比静态编译要好。

"--enable-mpms-shared"可以指定动态编译的mpm列表,使用空格分隔,但需要使用单引号包围。还可以使用关键字"all"表示动态编译所有mpm模块。 例如:

--enable-mpms-shared=‘prefork worker‘
--enable-mpms-shared=all

1.6 关于"--enable-so"

一个模块被动态编译,在需要加载的时候使用LoadModule指令指定该模块,并重读配置文件即可。但httpd为什么能加载该动态模块?这就是mod_so的能力。实际上,LoadModule和LoadFile指令就是该模块提供的。

该选项使得httpd有加载某动态模块的能力(DSO,Dynamic Shared Object),也因此它只能使用静态编译方式随httpd启动被加载。只要不显式指定"--enable-so=shared"或者将其加入显式编译列表,它都会默认以静态方式编译。实际上,只要显式指定了动态方式编译该选项,编译时会报错。

1.7 开始编译httpd

至此,就可以开始编译httpd了。过程如下:

cd
tar xf httpd-2.4.27.tar.gz
cd httpd-2.4.27
./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event --enable-mpms-shared=all

其中安装路径为/usr/local/apache,配置文件路径为/etc/apache。

[root@xuexi ~]# ls /usr/local/apache/
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules

bin目录为二进制程序存放位置,如启动脚本apachectl、httpd、htpasswd、ab(压力测试工具)等;htdocs目录存放网页文件,默认里面有index.html;logs目录存放了日志文件,除了日志文件,默认还有httpd运行的pid文件httpd.pid,这个建议修改到/var/run目录下(方便判断);modules存放了编译后的模块;man目录为帮助文档路径。

使用httpd的启动脚本bin/apahcectl启动httpd,然后测试其是否正常。

[root@xuexi apache]# bin/apachectl start
[root@xuexi apache]# netstat -tnlp | grep httpd
tcp        0      0 :::80          :::*         LISTEN      38798/httpd

在浏览器中输入IP地址即可访问。

1.8 编译后的规范化操作

  1. 设置man路径。

    echo "MANPATH /usr/local/apache/man" >>/etc/man.config
    
  2. 设置PATH环境变量。
    echo ‘PATH=/usr/local/apache/bin:$PATH‘ >/etc/profile.d/apache.sh
    source /etc/profile.d/apache.sh
    
  3. 输出头文件。
    ln -s /usr/include /usr/local/apache/include
    
  4. 提供服务启动脚本。

提供不提供没多大所谓,因为apachectl或httpd命令自身可以管理进程的启停,但自身管理启停时不提供lock文件。

如果要提供的话,从yum安装的httpd提供的/usr/lib/systemd/system/httpd.service(systemd)或/etc/init.d/httpd(sysV)拷贝后稍作修改就可以了。以下是按照我上面编译的环境做了修改后的systemd和sysV服务管理脚本。

以下是httpd的systemd服务管理脚本/usr/lib/systemd/system/httpd.service。

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/local/apache/bin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/local/apache/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

说明:上面的脚本中使用了"kill -WINCH"信号,它是graceful stop的信号。如不明白,见我的另一篇文章:进程和信号

以下是httpd的sysV服务管理脚本/etc/rc.d/init.d/httpd。

#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#           server implementing the current HTTP standards.
#
######################################################################
#  若httpd配置文件中指定了PidFile,则修改此脚本中的pidfile变量            #
######################################################################

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=/usr/local/apache/bin/apachectl
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
config=/etc/apache/httpd.conf

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd -f $config $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    status -p ${pidfile} $httpd > /dev/null
    if [[ $? = 0 ]]; then
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    else
        echo -n $"Stopping $prog: "
        success
    fi
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl [email protected]
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL

回到Linux系列文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7048359.html

回到数据库系列文章大纲:http://www.cnblogs.com/f-ck-need-u/p/7586194.html

转载请注明出处:http://www.cnblogs.com/f-ck-need-u/p/7605563.html

注:若您觉得这篇文章还不错请点击右下角推荐,您的支持能激发作者更大的写作热情,非常感谢!

时间: 2024-08-29 01:42:07

编译httpd细节的相关文章

CentOS6.5 LAMP之一编译httpd

apache服务器程序 命令httpd: -t 测试配置文件 -l 静态模块 -D DUMP_MODULES 动态模块 -h获得帮助 -M:相当于-D DUMP_MODULES -D DUMP_VHOSTS:列出虚拟主机 htpasswd: 为基于文件basic认证创建和更新用户认证文件 apachectl 自带脚本 apachectl start 开启httpd服务 httpd服务控制工具: ab:apache benchmark Apache性能基准测试工具 apxs:httpd得以扩展使用

linux下编译httpd程序

编译httpd程序 使用的程序包 httpd-2.4.25.tar.bz2 环境 Centos7 一: 先用tar工具解压程序包.    二:解压后在目录下可以看到程序包里的文件,我们重点关注的是Makefile.in的模板文件,还有README程序说明文件,以及INSTALL编译方法文件不会编译可以看看里面的说明步骤. 绿色的configure是一个可执行文件.    三: 设置好选项就可以开始了,这里我只设置了安装路径,其他的可按需添加    四:由于是第一次安装,不知道会缺少说明依赖包,我

手动编译httpd

httpd :2.4.4 apr   : apr-util: apr-iconv rpm包: 二进制程序 /bin, /sbin, /usr/bin, /usr/sbin 库文件   /lib,/usr/lib 配置文件 /etc 帮助文档 /usr/share/{doc,man} 编译安装: /usr/local/   存放第三方软件的地方 bin ,sbin 二进制文件 lib        库文件 etc        配置文件 share/{doc,man} 帮助文件 源码编译卸载方式:

ansible编译httpd playbook示例

以下是playbook的内容.它的处理流程是: 1.先在本地下载apr,apr-util,httpd共3个.tar.gz文件. 2.解压这3个文件. 3.安装pcre和pcre-devel依赖包. 4.编译安装apr 5.编译安装apr-util 6.编译安装httpd --- - hosts: all tasks: - name: download apr,apr-util,httpd get_url: url="{{item}}" dest=/root/pkg/ with_item

二进制编译httpd

安装开发工具包 #yum -y groupinstall "Development Tools" "Server Platform Development" 把之前httpd服务关闭并查看状态是否关闭 #systemctl stop httpd#systenctl status httpd 编译前安装编译工具及库 #yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* c

二进制编译Httpd服务器

前言: Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速.可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中. 环境介绍 系统环境:CentOS7 所需软件包:apr-1.5.1.tar.gz.apr-util-1.5.4.tar.gz.httpd-2.4.12.tar.gz 注意:httpd2.4需要依

Linux下编译安装httpd

本章学习内容 ---------介绍httpd ----------rpm和yum不同 ----------编译安装优势 ----------编译httpd 1.Apache和http的关系 http是一款超文本传输协议,早期的Apache团队利用此协议研发了一款web服务软件,叫做http.后来通过bug的修复和功能的完善,在http的基础上开发了另外一款软件,称为A Patchy Server,简称Apache,与Apache组织正好重名.后来Apache团队逐渐强大,最终成为一个开源软件基

httpd的编译安装

1.环境介绍 系统:2.6.32-279.el6.i686 2.准备编译环境 [[email protected] ~]# yum groupinstall "Server Platform Development" "Development tools" -y [[email protected] ~]# yum install pcre-devel -y 3.下载安装需要软件 [[email protected] ~]# cd /usr/src #切换到src目

通过编译php为httpd的模块实现lamp

简单罗列基础命令,只分享我的想法! 要求:把php编译成为httpd的模块,实现lamp,并且在httpd上面建立两个虚拟机,一个用于PHPAdmin,另外一个实现discuz. 环境:httpd-2.4.10,apr-1.5.0,apr-until-1.4.1,PHP-5.4.40,mariaDB-5.5.43和CentOS 6.6 一.首先编译httpd 编译2.4版本以上的httpd需要首先安装1.4版本以上的apr和apr-until 1)编译apr-1.5.0,这个软件类似于一个php