httpd-2.4 編譯安裝(centos6)

scm1911發表於2018-12-04

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

相關文章