httpd-2.4 编译安装(centos6)

centos6 上编译安装 httpd-2.4


APR 介绍

APR的全称是 Apache portable Run-time libraries,也就是Apache可移植运行库。
ARP主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。
ARP在很大程度上与JVM或JRE的概念是类似的。
在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数。
随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。
这样,APR的开发就从Apache中独立出来,Apache仅仅是使用 APR而已。
目前APR主要还是由Apache使用,由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR。
该项目不仅仅适用于Apache,开源项目比如用于服务器压力测试的Flood loader tester,http://httpd.apache.org/test/flood

在centos6上默认安装的是 apr-1.3+,centos7上默认安装的是apr-1.4+。
httpd2.2是基于apr-1.3+运行的,httpd2.4是基于apr-1.4+运行的,所以默认在centos6上yum安装的是httpd2.2,默认在centos7上yum安装的是httpd2.4。
要想在centos6上运行 httpd2.4 就需要编译安装apr-1.4+以及相关的软件才可以。

  • centos6
[root@centos6 ~]# rpm -qa apr
apr-1.3.9-5.el6_2.x86_64
  • centos7
[root@centos7 ~]# rpm -qa apr
apr-1.4.8-3.el7_4.1.x86_64

下载apr相关的依赖软件包

  • httpd-2.4.37.tar.bz2
  • apr-1.6.5.tar.bz2
  • apr-util-1.6.1.tar.bz2
  • apr-iconv-1.2.2.tar.bz2(可选,这里就不安装了,因为centos默认也没有安装)

centos6 编译安装httpd-2.4方法一(分步编译)

### 安装其他必要的依赖
yum groupinstall "Development Tools"
yum install gcc glibc make openssl-devel pcre-devel expat-devel -y

### 解压软件包(在存放软件包的目录执行)
for i in `ls`;do tar xf $i;done

### 创建安装目录
[ ! -d /web ] && mkdir -p /web

### 安装apr-1.4+
cd apr-1.6.5
./configure --prefix=/web/apr
make && make install

### 安装apr-util-1.4+
cd ../apr-util-1.6.1
./configure --prefix=/web/apr-util --with-apr=/web/apr/
make -j 4 && make install

### 编译安装httpd-2.4
cd ../httpd-2.4.37
./configure --prefix=/web/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/web/apr/ \
--with-apr-util=/web/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make -j 4 && make install

ln -s ../web/httpd24 /web/httpd

### 创建服务账号 apache(其他用户名也可以)并在配置文件中指定用户
useradd -r -s /sbin/nologin apache
cp /web/httpd/conf/httpd.conf{,.bak}
sed -ri "/^(User|Group)/s/daemon/apache/" /web/httpd/conf/httpd.conf 
sed -rn "/^(User|Group)/p" /web/httpd/conf/httpd.conf

### 环境变量设置及检查
echo 'export PATH=/web/httpd/bin:$PATH' >  /etc/profile.d/httpd24.sh
cat  /etc/profile.d/httpd24.sh
. /etc/profile.d/httpd24.sh
which httpd

### 编辑 man 配置文件 /etc/man.config
echo 'MANPATH /web/httpd/man' >> /etc/man.config
tail -1 /etc/man.config

### 自定义启动脚本 /etc/rc.d/init.d/httpd24 (参考httpd-2.2的服务脚本)
#!/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.
# processname: httpd24
# config: /web/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server 
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /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=/web/httpd/bin/apachectl
httpd=${HTTPD-/web/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/web/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# 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 $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 $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac

exit $RETVAL


### 开机启动
chmod +x /etc/init.d/httpd24
chkconfig --add httpd24 ;chkconfig --list httpd24;chkconfig httpd24 on;chkconfig --list httpd24

### 启动问题的解决
问题
[root@centos6 ~]# /etc/init.d/httpd24 start
Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for centos6
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message'
                                                           [  OK  ]
解决
将httpd.conf中 #ServerName www.example.com:80 取消注释,或指定其他的主机名即可。

centos6 编译安装httpd-2.4方法二(一步编译)

### 与方法1 不同的说明
1. 本方法只列出与方法一不同的地方,就是将解压后的 apr-1.6.5 和 apr-util-1.6.1 拷贝到 httpd-2.4.37/srclib/ 下面并分别改名为apr 和 apr-util
2. 编译的参数将方法1中的 --with-apr=/web/apr/ 和 --with-apr-util=/web/apr-util/ 改为 --with-included-apr

Httpd编译过程:/web/httpd24/build/config.nice
自带的服务控制脚本:/web/httpd24/bin/apachectl

### 安装其他必要的依赖
yum groupinstall "Development Tools"
yum install gcc glibc make openssl-devel pcre-devel expat-devel -y

### 解压软件包(在存放软件包的目录执行)
for i in `ls`;do tar xf $i;done

### 创建安装目录
[ ! -d /web ] && mkdir -p /web

### 拷贝apr 相关软件到 httpd-2.4.37/srclib/apr 并改名
cp -av apr-1.6.5 httpd-2.4.37/srclib/apr
cp -av apr-util-1.6.1 httpd-2.4.37/srclib/apr-util

### 编译安装httpd-2.4
cd httpd-2.4.37
./configure --prefix=/web/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make -j 4 && make install

ln -s ../web/httpd24 /web/httpd

### 创建服务账号 apache(其他用户名也可以)并在配置文件中指定用户
useradd -r -s /sbin/nologin apache
cp /web/httpd/conf/httpd.conf{,.bak}
sed -ri "/^(User|Group)/s/daemon/apache/" /web/httpd/conf/httpd.conf 
sed -rn "/^(User|Group)/p" /web/httpd/conf/httpd.conf

### 环境变量设置及检查
echo 'export PATH=/web/httpd/bin:$PATH' >  /etc/profile.d/httpd24.sh
cat  /etc/profile.d/httpd24.sh
. /etc/profile.d/httpd24.sh
which httpd

### 编辑 man 配置文件 /etc/man.config
echo 'MANPATH /web/httpd/man' >> /etc/man.config
tail -1 /etc/man.config

### 自定义启动脚本 /etc/rc.d/init.d/httpd24 (参考httpd-2.2的服务脚本)
与方法1中的脚本内容相同

### 开机启动
chmod +x /etc/init.d/httpd24
chkconfig --add httpd24 ;chkconfig --list httpd24;chkconfig httpd24 on;chkconfig --list httpd24

### 启动问题的解决
问题
[root@centos6 ~]# /etc/init.d/httpd24 start
Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for centos6
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message'
                                                           [  OK  ]
解决
将httpd.conf中 #ServerName www.example.com:80 取消注释,或指定其他的主机名即可。


本文链接:https://www.cnblogs.com/shichangming/p/10062581.html

posted @ 2018-12-04 14:20  scm1911  阅读(480)  评论(0编辑  收藏  举报
/** ####################################################################### */