在CentOS 7.x系统上编译安装httpd2.2版本

一、实验环境说明

(1) Selinux关闭;
(2) Firewalld启用,默认策略;
(3) 192.168.56.221这个单机环境;
(4) CentOS 7.3版本,X86_64;

二、下载相关软件包说明

(1) apr软件包版本 apr-1.5.2
软件包下载链接:http://archive.apache.org/dist/apr/
为了和apr-util保持一致,我也选了一个1.5.2的版本。

(2) apr-util软件包版本 apr-util-1.5.2
软件包下载链接:http://archive.apache.org/dist/apr/
进过反复实验和网上文档求证,这里因为CentOS 7.x系统原因,建议使用apr-util下于或等于1.5.2版本以下的,否则编译httpd的时候会包莫名的错误(如果要解决,可能修改源码类),只有httpd2.4版本才对apr有特殊要求,官网有给出,详情请见下面章节的说明。

(3) httpd软件包版本 httpd-2.2.34
软件包下载链接:http://archive.apache.org/dist/httpd/
httpd的包,我们无论下载是2.2.x多少都行,这里我实验是下载的2.2版本中最新的。

三、编译源码包前注意事项

1、编译安装前,先查看官网介绍的编译安装以及注意事项;
httpd2.2编译安装,官方介绍链接地址:
http://httpd.apache.org/docs/2.2/install.html
2、其次,在编译某个应用程序之前,先看一下应用程序中提供的文档或说明
README或README.mk以及其他类似字眼;
INSTALL
3、httpd2.2以及apr较旧版本,源码包中并不包含制作rpm包的spec文件,如果不懂得如何写制作rpm包用到的spec文件时,建议直接源码包安装。

4、在编译安装apr、apr-util以及httpd之前,建议先通过./configure --help来查阅相关编译选项详情,建议了解大部分的之后再来编译(出错概念减少了,了解编译选项后)

四、编译安装

4.1、httpd编译安装依赖情况

(1) 磁盘空间
安装的时候,需要50MB大小的临时空间,安装后,大约占用空间10MB,不过根据用户选择的编译选项不同,加入的模块不同,所以
实际占用空间,可能会在10MB左右变动。
(2) ANSI-C编译与编译系统
ANSI-C编译器。以及make命令
(3) 精准计时
web服务要保证你服务器时间精准。所以建议自己配置时间同步的策略。比如ntpdate等
(4) Perl 5
apxs以及dbmmanage需要Perl支持,
Perl5, 5.003或者以上版本
(5) apr/apr=util >-1.4
apr和apr-util需要1.4以及以上版本。(我们上面提到用apr-util-1.5.2以上版本会遇到问题,那种问题是可以解决的。假设安装httpd2.2的环境apr版本小于1.4,比如1.2版本,正常是直接编译错误)

4.2、安装编译所需基本组件和库文件

在linux的bash接口中执行下面的命令。前提是网络正常,而且配置的yum客户端配置文件指向的yum仓库能够正常访问。

yum -y install gcc gcc-c++ autoconf make libtool openssl-devel zlib-devel pcre-devel expat-devel openldap-devel db4-devel
安装过程省略。

4.3、编译安装apr

1、准备说明
上传软件包到一个指定的目录,我这里指定的是/opt/soft。如果不存在,先创建,然后通过相关手段上传,ftp或者其他方式等。上传过程省略。软件包信息如下:

[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# ls -l /opt/soft/
total 14004
-rw-r--r-- 1 root root  826885 Dec  8 02:03 apr-1.5.2.tar.bz2
-rw-r--r-- 1 root root  693258 Dec  7 21:39 apr-util-1.5.2.tar.bz2
-rw-r--r-- 1 root root 5779739 Dec  7 17:19 httpd-2.2.34.tar.bz2
-rw-r--r-- 1 root root 7031632 Nov 16 09:55 httpd-2.4.37.tar.bz2
[root@localhost soft]# file *.bz2
apr-1.5.2.tar.bz2:      bzip2 compressed data, block size = 900k
apr-util-1.5.2.tar.bz2: bzip2 compressed data, block size = 900k
httpd-2.2.34.tar.bz2:   bzip2 compressed data, block size = 900k
httpd-2.4.37.tar.bz2:   bzip2 compressed data, block size = 900k

确保bzip2工具有安装,如果没有安装,先安装,因为这些压缩包都是使用bzip2工具压缩的。
创建编译安装根目录:

[root@localhost soft]# mkdir -p /data/application
[root@localhost soft]# ls -l /data/application/
total 0
[root@localhost soft]# 

2、 开始编译安装apr

解压:
[root@localhost soft]# tar -xf apr-1.5.2.tar.bz2 
[root@localhost soft]# ls
apr-1.5.2  apr-1.5.2.tar.bz2  apr-util-1.5.2.tar.bz2  httpd-2.2.34.tar.bz2  httpd-2.4.37.tar.bz2

进入解压后目录:
[root@localhost soft]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --help
#帮助信息省略。
[root@localhost apr-1.5.2]# ls -l apr.spec README README.cmake 
-rw-r--r-- 1 1000 1000 2543 Apr 25  2015 apr.spec
-rw-r--r-- 1 1000 1000 5633 Mar  2  2010 README
-rw-r--r-- 1 1000 1000 4505 Jan 20  2014 README.cmake
#较新版的apr的包,里面有提供制作rpm包用到的spec文件,可以参考官方文档进行查看如何根据官方提供软件
包的spec文件来制作(之前我有一篇博文也有粗略介绍过,有兴趣可以去检索一下)。如果官方没有提供spec文
件,相信自己编写spec文件来制作rpm包,对于很多人来说,门槛过高,所以我们使用编译安装。在编译apr
之前,我们可以先看看其提供的README文档,如果有注意事项以及安装简要说明,你要特别留意,养成良好的
习惯是,在通过源码包安装软件前,要先阅读其自身提供的相关说明文档。

最终我的configure脚本为:
#这一步可以做一下,脚本中有一行代码写的略有问题,可能不同环境略有不同体现,不影响大体安装
sed -i '/$RM "$cfgfile"/s/^/#/' configure   
./configure --prefix=/data/application/apr-1.5.2
上面步骤没有报错的化,直接下面的步骤:
make
make install
安装过程,我们省略,安装后为:
[root@localhost apr-1.5.2]# ls -l /data/application/
total 0
drwxr-xr-x 6 root root 58 Dec  8 20:54 apr-1.5.2
为了多版本并存以及方便,我们对/data/application/apr-1.5.2版本做一个软链接
ln -sf /data/application/apr-1.5.2 /data/application/apr
执行创建软链接后:
[root@localhost apr-1.5.2]# ls -l /data/application/
total 0
lrwxrwxrwx 1 root root 27 Dec  8 20:55 apr -> /data/application/apr-1.5.2
drwxr-xr-x 6 root root 58 Dec  8 20:54 apr-1.5.2

#apr就编译安装完成了。

4.4、编译安装apr-util

下面我们的安装过程省略掉大部分说明语句。apr-util编译安装需要apr的二进制程序文件apr-1-config,我们可以直接指向这个文件,也可以直接指向apr编译安装的根目录。configure脚本以及简要步骤为:

cd /opt/soft/
tar -xf apr-util-1.5.2.tar.bz2
cd apr-util-1.5.2
./configure --prefix=/data/application/apr-util-1.5.2 --with-apr=/data/application/apr
make
make install
ln -sf /data/application/apr-util-1.5.2 /data/application/apr-util

#查看安装后结果:
[root@localhost apr-util-1.5.2]# ls -l /data/application/
total 0
lrwxrwxrwx 1 root root 27 Dec  8 20:55 apr -> /data/application/apr-1.5.2
drwxr-xr-x 6 root root 58 Dec  8 20:54 apr-1.5.2
lrwxrwxrwx 1 root root 32 Dec  8 21:00 apr-util -> /data/application/apr-util-1.5.2
drwxr-xr-x 5 root root 43 Dec  8 20:59 apr-util-1.5.2

apr-util的编译安装完成了。

4.5、编译安装httpd(prefork模型)

#要确保apr以及apr-util软件包符合之前的要求。httpd2.2的要求是apr和apr-util 不能低于1.4版本(可能略有不精确),建议编译安装httpd2.2的时候,使用apr和apr-util版本在1.4.x 到1.5.2之间,实际上官方只有版本不小于1.4的限制,不过我实际测试过程中,不同的编译选项会有不同的效果,网上也有很多版本出现过,经过测试apr-util版本不能使用大于apr-util-1.5.3以及以上版本, 在centos 7上编译使用httpd2.2,所以apr版本也跟着降低成apr-1.5.2最好(不过后边参照官方的SRPM包中的spec文件,发现apr和apr-util在1.5.2版本以上也没有问题,不过apr的1.6版本算是比较新的了)。

解压并进入目录:

[root@localhost apr-util-1.5.2]# cd /opt/soft/
[root@localhost soft]# tar -xf httpd-2.2.34.tar.bz2 
[root@localhost soft]# cd httpd-2.2.34
建议对以下的文件进行简单的查阅(如果有需要,可以看看自带的spec文件,可以制作rpm包的)
[root@localhost httpd-2.2.34]# ls -l README* INSTALL VERSIONING NOTICE CHANGES ABOUT_APACHE LICENSE httpd.spec
-rw-r--r-- 1 1001 1001  14882 Nov 22  2004 ABOUT_APACHE
-rw-r--r-- 1 1001 1001 147887 Jun 29  2017 CHANGES
-rw-r--r-- 1 1001 1001  12053 Jul  7  2017 httpd.spec
-rw-r--r-- 1 1001 1001   5129 Jan 10  2017 INSTALL
-rw-r--r-- 1 1001 1001  28690 Jan 19  2008 LICENSE
-rw-r--r-- 1 1001 1001    828 Jan  3  2017 NOTICE
-rw-r--r-- 1 1001 1001   5954 Jan 10  2007 README
-rw-r--r-- 1 1001 1001   4178 Aug 28  2014 README.platforms
-rw-r--r-- 1 1001 1001   2553 Dec 21  2010 README-win32.txt
-rw-r--r-- 1 1001 1001   8183 Oct 18  2005 VERSIONING

精简版的configure编译参数:(本次博文以这个为准)

cd httpd-2.2.34
./configure \
--prefix=/data/application/httpd-2.2.34 \
--sysconfdir=/data/application/httpd-2.2.34/etc \
--enable-modules=all \
--enable-mods-shared=all \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--enable-rewrite \
--enable-so \
--with-apr=/data/application/apr \
--with-apr-util=/data/application/apr-util \
--with-mpm=prefork

#上面没有问题的话,执行:
make
make install
ln -sf /data/application/httpd-2.2.34 /data/application/httpd

繁杂版的configure的编译参数:(该编译选项我也反复测试过)

cd httpd-2.2.34
./configure \
--prefix=/data/application/httpd-2.2.34 \
--bindir=/data/application/httpd-2.2.34/bin \
--sbindir=/data/application/httpd-2.2.34/sbin \
--libexecdir=/data/application/httpd-2.2.34/libexec \
--sysconfdir=/data/application/httpd-2.2.34/etc \
--sharedstatedir=/data/application/httpd-2.2.34/com \
--localstatedir=/data/application/httpd-2.2.34/var \
--libdir=/data/application/httpd-2.2.34/lib \
--includedir=/data/application/httpd-2.2.34/include \
--oldincludedir=/usr/include \
--datarootdir=/data/application/httpd-2.2.34/share \
--datadir=/data/application/httpd-2.2.34/share \
--infodir=/data/application/httpd-2.2.34/share/info \
--localedir=/data/application/httpd-2.2.34/share/locale \
--mandir=/data/application/httpd-2.2.34/share/man \
--docdir=/data/application/httpd-2.2.34/share/doc/PACKAGE \
--htmldir=/data/application/httpd-2.2.34/share/doc/PACKAGE/html \
--dvidir=/data/application/httpd-2.2.34/share/doc/PACKAGE/dvi \
--pdfdir=/data/application/httpd-2.2.34/share/doc/PACKAGE/pdf \
--psdir=/data/application/httpd-2.2.34/share/doc/PACKAGE/psdir \
--enable-modules=all \
--enable-mods-shared=all \
--enable-file-cache \
--enable-cache \
--enable-disk-cache \
--enable-mem-cache \
--enable-deflate \
--enable-mime-magic \
--enable-expires \
--enable-headers \
--enable-usertrack \
--enable-proxy \
--enable-proxy-connect \
--enable-proxy-http \
--enable-proxy-scgi \
--enable-proxy-balancer \
--enable-ssl \
--enable-http \
--enable-info \
--enable-cgi \
--enable-cgid \
--enable-rewrite \
--enable-so \
--with-apr=/data/application/apr \
--with-apr-util=/data/application/apr-util \
--with-mpm=prefork

make
make install
ln -sf /data/application/httpd-2.2.34 /data/application/httpd

httpd2.2安装后目录说明:

[root@localhost httpd-2.2.34]# cd /data/application/httpd
[root@localhost httpd]# ls -l /data/application/httpd/
total 36
drwxr-xr-x  2 root root  243 Dec  8 21:13 bin
drwxr-xr-x  2 root root  167 Dec  8 21:13 build
drwxr-xr-x  2 root root   38 Dec  8 21:13 cgi-bin
drwxr-xr-x  3 root root 4096 Dec  8 21:13 error
drwxr-xr-x  4 root root   84 Dec  8 21:13 etc
drwxr-xr-x  2 root root   24 Dec  8 21:13 htdocs
drwxr-xr-x  3 root root 8192 Dec  8 21:13 icons
drwxr-xr-x  2 root root 4096 Dec  8 21:13 include
drwxr-xr-x  2 root root    6 Dec  8 21:13 logs
drwxr-xr-x  4 root root   30 Dec  8 21:13 man
drwxr-xr-x 14 root root 8192 Dec  8 21:13 manual
drwxr-xr-x  2 root root 4096 Dec  8 21:13 modules

主目录说明:
drwxr-xr-x  2 root root  243 Dec  8 21:13 bin   #普通用户执行文件目录(我设定的编译选项,一些工具存放在这个目录了)
drwxr-xr-x  2 root root  167 Dec  8 21:13 build #构建的时候,一些文件目录
drwxr-xr-x  2 root root   38 Dec  8 21:13 cgi-bin  #cgi脚本程序目录
drwxr-xr-x  3 root root 4096 Dec  8 21:13 error #安装好后的一些固定文件目录,不可删,会影响httpd工作
drwxr-xr-x  4 root root   84 Dec  8 21:13 etc #配置文件目录
drwxr-xr-x  2 root root   24 Dec  8 21:13 htdocs #主页文件目录
drwxr-xr-x  3 root root 8192 Dec  8 21:13 icons #一些图片的目录
drwxr-xr-x  2 root root 4096 Dec  8 21:13 include  #一些头文件目录
drwxr-xr-x  2 root root    6 Dec  8 21:13 logs #日志文件目录
drwxr-xr-x  4 root root   30 Dec  8 21:13 man #man手册目录
drwxr-xr-x 14 root root 8192 Dec  8 21:13 manual #官方的离线手册目录(可以配置指向这个目录,然后浏览器一般开发,一般查看帮助文档,对于离线环境很有用)
drwxr-xr-x  2 root root 4096 Dec  8 21:13 modules #模块文件目录

#配置环境变量,以及man 手册指向
echo 'export PATH=$PATH:/data/application/httpd/bin' > /etc/profile.d/httpd22.sh
source /etc/profile

echo 'MANDATORY_MANPATH /data/application/httpd/man' >> /etc/man_db.conf
#注意centos 7和centos 6不同,centos6是:
echo 'MANPATH /data/application/httpd/man' >>/etc/man.config

如果没有配置指向我们自定义的安装路径的man,我们可以通过man的-M指定查询,例如:
man -M /data/application/httpd/man httpd
man -M /data/application/httpd/man ab
等等。

查看配置后的信息:
[root@localhost ~]# echo 'export PATH=$PATH:/data/application/httpd/bin' > /etc/profile.d/httpd22.sh
[root@localhost ~]# cat /etc/profile.d/httpd22.sh
export PATH=$PATH:/data/application/httpd/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# httpd -v
Server version: Apache/2.2.34 (Unix)
Server built:   Dec  8 2018 21:12:33
[root@localhost ~]# man -M /data/application/httpd/man httpd
[root@localhost ~]# echo $?
0
[root@localhost ~]# echo 'MANPATH /data/application/httpd/man' >>/etc/man.config
[root@localhost ~]# tail -n 1 /etc/man.config
MANPATH /data/application/httpd/man
[root@localhost ~]# 

4.6、非完全编译安装httpd(worker模型)

由于httpd2.2,prefork,worker以及event只能以静态编译的方式编译进来,通过–with-mpm=xxx,所以一旦选定,我们无法动态更改,于是会有时候为了切换方便,我们也会把worker以及event编译进来,默认不指定–with-mpm,表示是prefork。关于prefork、worker、event这三者的是什么东西以及差异点,不在我们本次博文的范围内。(是进程的io模型,这三个,我将在其他博文会有专门地方介绍)。

那么,我们之前已经编译过来prefork,那么我们现在重新指定configure时–with-mpm时候的值,然后make一下。不执行make install,我们手动拷贝编译后的httpd文件到之前编译根目录的bin目录(有时候是sbin,是具体编译指向而定)下,我们把其名字改为httpd.worker (关于这一点做法,我是借鉴的centos 6.x上yum安装的httpd可以自动切换模型的思路)

[root@localhost ~]# cd /opt/soft/httpd-2.2.34
[root@localhost httpd-2.2.34]# make clean
省略......
./configure \
--prefix=/data/application/httpd-2.2.34 \
--sysconfdir=/data/application/httpd-2.2.34/etc \
--enable-modules=all \
--enable-mods-shared=all \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--enable-rewrite \
--enable-so \
--with-apr=/data/application/apr \
--with-apr-util=/data/application/apr-util \
--with-mpm=worker

make
#到这步,我们不能再执行安装了,因为默认编译出来的二进制程序文件都叫httpd,我们为了保留prefork和worker,所以我们只需要复制通过指定为worker时候的程序文件httpd重命名为httpd.worker.
[root@localhost httpd-2.2.34]# ls -l httpd
-rwxr-xr-x 1 root root 1704312 Dec  8 21:45 httpd
[root@localhost httpd-2.2.34]# pwd
/opt/soft/httpd-2.2.34
[root@localhost httpd-2.2.34]# ./httpd -l
Compiled in modules:
  core.c
  worker.c
  http_core.c
  mod_so.c
[root@localhost httpd-2.2.34]# cp -a httpd /data/application/httpd/bin/httpd.worker
[root@localhost httpd-2.2.34]# /data/application/httpd/bin/httpd.worker -l
Compiled in modules:
  core.c
  worker.c
  http_core.c
  mod_so.c
  httpd程序的-l选项可以查看(静态编译)的模块,上面依次是核心功能模块,mpm的worker的模块,http的核心
  模块,dso模块(支持在启动或重新启动时将可执行代码和模块加载到服务器中)。

4.7、非完全编译安装httpd(event模型,实验模型)

说明:在httpd2.2中,event模型只是实验模型,所以CentOS 6通过rpm包(yum直接安装)的httpd2.2版本,默认不能切换到event,所以如果我们实验,我们可以测试一下。但是,对于生产环境,想要使用httpd的event模型,建议升级到httpd2.4。而且httpd2.4对三种模块可以通过动态模块加载的方式进行随机切换。实验测试,和上面类似:

[root@localhost httpd-2.2.34]# cd /opt/soft/httpd-2.2.34
[root@localhost httpd-2.2.34]# make clean

./configure \
--prefix=/data/application/httpd-2.2.34 \
--sysconfdir=/data/application/httpd-2.2.34/etc \
--enable-modules=all \
--enable-mods-shared=all \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-ssl \
--enable-cgi \
--enable-cgid \
--enable-rewrite \
--enable-so \
--with-apr=/data/application/apr \
--with-apr-util=/data/application/apr-util \
--with-mpm=event

给出的提示:
============================================================
    WARNING: THE 'event' MPM IS EXPERIMENTAL  #mpm的event是实验阶段的
============================================================
 The selected MPM might not be fully functional!  #非完整功能

 Development of this MPM is not complete. Do not use this
 MPM unless you are a programmer willing to help fix it.

 If you are looking for a stable server, you should not use
 the 'event' MPM until it is moved out of experimental.
============================================================

make
过程略......
[root@localhost httpd-2.2.34]# ls httpd
httpd
[root@localhost httpd-2.2.34]# pwd
/opt/soft/httpd-2.2.34
[root@localhost httpd-2.2.34]# ./httpd -l
Compiled in modules:
  core.c
  event.c
  http_core.c
  mod_so.c
[root@localhost httpd-2.2.34]# cp -a httpd /data/application/httpd/bin/httpd.event
[root@localhost httpd-2.2.34]# /data/application/httpd/bin/httpd.event -l
Compiled in modules:
  core.c
  event.c
  http_core.c
  mod_so.c

#现在我们的httpd的三个模型程序都安装的,只需要使用的时候切换了,我们这里就不演示切换和使用了,
具体操作和介绍说明,会在其他博文给出。
[root@localhost httpd-2.2.34]# ls -l /data/application/httpd/bin/http*
-rwxr-xr-x 1 root root 1665168 Dec  8 21:13 /data/application/httpd/bin/httpd
-rwxr-xr-x 1 root root 1710416 Dec  8 21:54 /data/application/httpd/bin/httpd.event
-rwxr-xr-x 1 root root 1704312 Dec  8 21:45 /data/application/httpd/bin/httpd.worker

[root@localhost ~]# httpd -M|grep 'mpm'
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK
 mpm_prefork_module (static)

[root@localhost ~]# httpd.worker -M|grep 'mpm'
httpd.worker: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK
 mpm_worker_module (static)
 
[root@localhost ~]# httpd.event -M|grep 'mpm'
httpd.event: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK
 mpm_event_module (static)

五、学习官方旧版srpm包中的spec文件的编译选项

5.1、独立环境说明

系统发型版:
CentOS 7.3 x86_64
源码包:
apr-1.6.5.tar.bz2
apr-util-1.6.1.tar.bz2
httpd-2.2.34.tar.bz2

SRPM包:(源代码格式的rpm包)
apr-1.2.8-1.src.rpm
apr-util-1.2.8-1.src.rpm
httpd-2.2.3-1.src.rpm

#查看:
[root@localhost ~]# ls -l /opt/soft/
total 6904
-rw-r--r-- 1 root root  855393 Dec  1 14:05 apr-1.6.5.tar.bz2
-rw-r--r-- 1 root root  428595 Dec  1 14:05 apr-util-1.6.1.tar.bz2
-rw-r--r-- 1 root root 5779739 Dec  7 17:19 httpd-2.2.34.tar.bz2
drwxr-xr-x 2 root root      94 Dec  8 22:01 srpm
[root@localhost ~]# ls -l /opt/soft/srpm/
total 7900
-rw-r--r-- 1 root root 1109494 Dec  8 18:58 apr-1.2.8-1.src.rpm
-rw-r--r-- 1 root root  642247 Dec  8 18:58 apr-util-1.2.8-1.src.rpm
-rw-r--r-- 1 root root 6332956 Dec  8 17:48 httpd-2.2.3-1.src.rpm

5.2、apr的spec文件中的编译选项以及最终自己微调后实测

可以从下面这个目录找到apr老版本的srpm包:
http://archive.apache.org/dist/apr/binaries/

解压apr的srpm包:

[root@localhost srpm]# mkdir apr-srpm
[root@localhost srpm]# ls
apr-1.2.8-1.src.rpm  apr-srpm  apr-util-1.2.8-1.src.rpm  httpd-2.2.3-1.src.rpm
[root@localhost srpm]# cp apr-1.2.8-1.src.rpm apr-srpm/
[root@localhost srpm]# cd apr-srpm/
[root@localhost apr-srpm]# pwd
/opt/soft/srpm/apr-srpm
[root@localhost apr-srpm]# rpm2cpio apr-1.2.8-1.src.rpm | cpio -div
apr-1.2.8.tar.gz
apr.spec
2168 blocks
[root@localhost apr-srpm]# ls -l
total 2172
-rw-r--r-- 1 root root 1109494 Dec  8 22:04 apr-1.2.8-1.src.rpm
-rw-rw-r-- 1 root root 1107189 Dec  8 22:04 apr-1.2.8.tar.gz #这格式制作rpm包时候用到的apr的源码包
-rw------- 1 root root    2393 Dec  8 22:04 apr.spec #这个是制作rpm包时的spec文件

制作apr的rpm包的spec中关于configure的部分:(没有spec基础,可以略过第五章)

%build
# regenerate configure script etc.
./buildconf
%configure \
        --prefix=/usr \
        --includedir=%{_includedir}/apr-%{aprver} \
        --with-installbuilddir=%{_libdir}/apr/build-%{aprver} \
        --with-devrandom=/dev/urandom \
        CC=gcc CXX=g++
make %{?_smp_mflags} && make dox

%check
# Run non-interactive tests
pushd test
make %{?_smp_mflags} testall CFLAGS=-fno-strict-aliasing
./testall -v || exit 1
popd

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

最终我自己生成的编译选项和精简步骤为:
cd apr-1.6.5
sed -i '/$RM "$cfgfile"/s/^/#/' configure
./configure \
    --prefix=/data/application/apr-1.6.5 \
    --with-devrandom=/dev/urandom

make
make install
ln -sf /data/application/apr-1.6.5 /data/application/apr

安装依赖库和组件:

yum -y install gcc gcc-c++ autoconf make libtool openssl-devel zlib-devel pcre-devel expat-devel openldap-devel db4-devel
过程略......

使用上面我们自己生成的选项,来编译安装:

[root@localhost ~]# mkdir -p /data/application
[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# tar -xf apr-1.6.5.tar.bz2 
[root@localhost soft]# cd apr-1.6.5
[root@localhost apr-1.6.5]# sed -i '/$RM "$cfgfile"/s/^/#/' configure
[root@localhost apr-1.6.5]# ./configure \
>     --prefix=/data/application/apr-1.6.5 \
>     --with-devrandom=/dev/urandom
过程省略......
[root@localhost apr-1.6.5]# make
过程省略......
[root@localhost apr-1.6.5]# make install
过程省略......
[root@localhost apr-1.6.5]# ls -l /data/application/
total 0
lrwxrwxrwx 1 root root 27 Dec  8 22:12 apr -> /data/application/apr-1.6.5
drwxr-xr-x 6 root root 58 Dec  8 22:11 apr-1.6.5
[root@localhost apr-1.6.5]# ls -l /data/application/apr/bin/apr-1-config 
-rwxr-xr-x 1 root root 6974 Dec  8 22:11 /data/application/apr/bin/apr-1-config

apr高版本编译安装结束,有参考rpm包的spec文件。

5.3、apr-util的spec文件中的编译选项以及最终自己微调后实测

解压apr的srpm包:

[root@localhost srpm]# ls
apr-1.2.8-1.src.rpm  apr-srpm  apr-util-1.2.8-1.src.rpm  httpd-2.2.3-1.src.rpm
[root@localhost srpm]# mkdir apr-util-srpm
[root@localhost srpm]# cp -a apr-util-1.2.8-1.src.rpm apr-util-srpm/
[root@localhost srpm]# cd apr-util-srpm/
[root@localhost apr-util-srpm]# rpm2cpio apr-util-1.2.8-1.src.rpm | cpio -div
apr-util-1.2.8.tar.gz
apr-util.spec
1268 blocks
[root@localhost apr-util-srpm]# ls -l
total 1264
-rw-r--r-- 1 root root 642247 Dec  8 18:58 apr-util-1.2.8-1.src.rpm
-rw-rw-r-- 1 root root 646379 Dec  8 22:13 apr-util-1.2.8.tar.gz
-rw------- 1 root root   2395 Dec  8 22:13 apr-util.spec

spec文件中关于configure的部分:

%build
%configure --with-apr=%{_prefix} \
        --includedir=%{_includedir}/apr-%{apuver} \
        --with-ldap --without-gdbm
make %{?_smp_mflags} && make dox

%check
# Run non-interactive tests
pushd test
make %{?_smp_mflags} testall CFLAGS=-fno-strict-aliasing
./testall -v || exit 1
popd

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

最终自己生成的编译选项和精简安装步骤:
./configure \
    --prefix=/data/application/apr-util-1.6.1 \
    --with-apr=/data/application/apr \
    --with-ldap \
    --without-gdbm
make
make install
ln -s /data/application/apr-util-1.6.1 /data/application/apr-util

使用上面我们自己生成的选项,来编译安装:

[root@localhost test]# ls
httpd-2.2.3  httpd-2.2.3-1.src.rpm  httpd-2.2.3.tar.gz  httpd.spec
[root@localhost test]# vim httpd.spec 
[root@localhost apr-util-srpm]# vim apr-util.spec 
[root@localhost apr-util-srpm]# cd /opt/soft/
[root@localhost soft]# tar -xf apr-util-1.6.1.tar.bz2 
[root@localhost soft]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure \
>     --prefix=/data/application/apr-util-1.6.1 \
>     --with-apr=/data/application/apr \
>     --with-ldap \
>     --without-gdbm
过程省略......
[root@localhost apr-util-1.6.1]# make
过程省略......
[root@localhost apr-util-1.6.1]# make install
过程省略......
ln -s /data/application/apr-util-1.6.1 /data/application/apr-util

查看:
[root@localhost apr-util-1.6.1]# ls -l /data/application/
total 0
lrwxrwxrwx 1 root root 27 Dec  8 22:12 apr -> /data/application/apr-1.6.5
drwxr-xr-x 6 root root 58 Dec  8 22:11 apr-1.6.5
lrwxrwxrwx 1 root root 32 Dec  8 22:20 apr-util -> /data/application/apr-util-1.6.1
drwxr-xr-x 5 root root 43 Dec  8 22:19 apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ls -l /data/application/apr-util/bin/apu-1-config 
-rwxr-xr-x 1 root root 6177 Dec  8 22:19 /data/application/apr-util/bin/apu-1-config

#apr-util编译安装结束。

5.4、httpd的spec文件中的编译选项以及最终自己微调后实测

解压srpm包:

[root@localhost srpm]# ls
apr-1.2.8-1.src.rpm  apr-srpm  apr-util-1.2.8-1.src.rpm  apr-util-srpm  httpd-2.2.3-1.src.rpm
[root@localhost srpm]# mkdir httpd-srpm
[root@localhost srpm]# cd httpd-srpm/
[root@localhost httpd-srpm]# cp ../httpd-2.2.3-1.src.rpm .
[root@localhost httpd-srpm]# rpm2cpio httpd-2.2.3-1.src.rpm | cpio -div
httpd-2.2.3.tar.gz
httpd.spec
12426 blocks
[root@localhost httpd-srpm]# ls -l
total 12404
-rw-r--r-- 1 root root 6332956 Dec  8 22:21 httpd-2.2.3-1.src.rpm
-rw-r--r-- 1 root root 6342475 Dec  8 22:22 httpd-2.2.3.tar.gz
-rw------- 1 root root   19127 Dec  8 22:22 httpd.spec

spec文件中关于httpd的configure部分:

../configure -C \
        --prefix=%{_sysconfdir}/httpd \
        --with-apr=/usr/bin/apr-1-config \
        --with-apr-util=/usr/bin/apu-1-config \
        --exec-prefix=%{_prefix} \
        --bindir=%{_bindir} \
        --sbindir=%{_sbindir} \
        --mandir=%{_mandir} \
        --libdir=%{_libdir} \
        --sysconfdir=%{_sysconfdir}/httpd/conf \
        --includedir=%{_includedir}/httpd \
        --libexecdir=%{_libdir}/httpd/modules \
        --datadir=%{contentdir} \
        --with-mpm=$mpm \
        --enable-suexec --with-suexec \
        --with-suexec-caller=%{suexec_caller} \
        --with-suexec-docroot=%{contentdir} \
        --with-suexec-logfile=%{_localstatedir}/log/httpd/suexec.log \
        --with-suexec-bin=%{_sbindir}/suexec \
        --with-suexec-uidmin=500 --with-suexec-gidmin=500 \
        --with-devrandom \
        --with-ldap --enable-ldap --enable-authnz-ldap \
        --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache \
        --enable-ssl --with-ssl \
        --enable-deflate --enable-cgid \
        --enable-proxy --enable-proxy-connect \
        --enable-proxy-http --enable-proxy-ftp \
        $*

make %{?_smp_mflags}
popd
}

# Only bother enabling optional modules for main build.
mpmbuild prefork --enable-mods-shared=all

# To prevent most modules being built statically into httpd.worker, 
# easiest way seems to be enable them shared.
mpmbuild worker --enable-mods-shared=all

这里介绍一个系统文件,里面有定义一些书写spec文件的一些常见的宏变量:

/usr/lib/rpm/macros文件中有定义宏:(以下是我摘录于该系统配置文件,编译简单理解上面的spec的语法)
%{_sysconfdir}对应目录为:/etc
%{_prefix}对应目录为:/usr
%{_bindir}对应目录为:/usr/bin
%{_sbindir}对应目录为: /usr/sbin
%{_mandir}对应目录为:/usr/share/man
%{_libdir}对应目录为:/usr/lib  #如果是64位系统,到时候会替换为/usr/lib64
%{_includedir}对应目录为:/usr/include
%{contentdir} 这里的宏在spec文件中有定义,默认的宏定义文件不存在,spec文件中定义的值为/var/www
%{suexec_caller} 在spec中定义的值为apache
%{_localstatedir}值为:/usr/var

最终自己生成的一份configure和精简安装步骤:
./configure \
    --prefix=/data/application/httpd-2.2.34 \
    --with-apr=/data/application/apr/bin/apr-1-config \
    --with-apr-util=/data/application/apr-util/bin/apu-1-config \
    --exec-prefix=/data/application/httpd-2.2.34 \
    --bindir=/data/application/httpd-2.2.34/bin \
    --sbindir=/data/application/httpd-2.2.34/sbin \
    --mandir=/data/application/httpd-2.2.34/share/man \
    --libdir=/data/application/httpd-2.2.34/lib64 \
    --sysconfdir=/data/application/httpd-2.2.34/conf \
    --includedir=/data/application/httpd-2.2.34/include/httpd \
    --libexecdir=/data/application/httpd-2.2.34/modules \
    --datadir=/data/application/httpd-2.2.34/www \
    --with-mpm=prefork \
    --enable-suexec \
    --with-suexec \
    --with-suexec-caller=apache \
    --with-suexec-docroot=/data/application/httpd-2.2.34/www \
    --with-suexec-logfile=/data/application/httpd-2.2.34/var/log/httpd/suexec.log \
    --with-suexec-bin=/data/application/httpd-2.2.34/sbin/suexec \
    --with-suexec-uidmin=500 \
    --with-suexec-gidmin=500 \
    --with-devrandom \
    --with-ldap \
    --enable-ldap \
    --enable-authnz-ldap \
    --enable-cache \
    --enable-disk-cache \
    --enable-mem-cache \
    --enable-file-cache \
    --enable-ssl \
    --with-ssl \
    --enable-deflate \
    --enable-cgid \
    --enable-proxy \
    --enable-proxy-connect \
    --enable-proxy-http \
    --enable-proxy-ftp \
    --enable-mods-shared=all
make
make install
ln -sf /data/application/httpd-2.2.34 /data/application/httpd	

实际安装步骤略(我们按照之前介绍的,把三种mpm,prefork、worker、event都编译成静态文件),安装后结果为:

[root@localhost ~]# ls -l /data/application/httpd
lrwxrwxrwx 1 root root 30 Dec  8 22:30 /data/application/httpd -> /data/application/httpd-2.2.34
[root@localhost ~]# ls -l /data/application/httpd/
total 4
drwxr-xr-x 2 root root    6 Dec  8 22:30 bin
drwxr-xr-x 4 root root   84 Dec  8 22:30 conf
drwxr-xr-x 3 root root   19 Dec  8 22:30 include
drwxr-xr-x 2 root root    6 Dec  8 22:30 logs
drwxr-xr-x 2 root root 4096 Dec  8 22:30 modules
drwxr-xr-x 2 root root  296 Dec  8 22:35 sbin
drwxr-xr-x 3 root root   17 Dec  8 22:30 share
drwxr-xr-x 8 root root   88 Dec  8 22:30 www
[root@localhost ~]# ls  /data/application/httpd/sbin/
ab         apxs      dbmmanage  envvars-std   htdbm     htpasswd  httpd.event   httxt2dbm   rotatelogs
apachectl  checkgid  envvars    htcacheclean  htdigest  httpd     httpd.worker  logresolve  suexec
[root@localhost ~]# cd /data/application/httpd/sbin/
[root@localhost sbin]# ./httpd -l 
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c
[root@localhost sbin]# ./httpd.worker -l 
Compiled in modules:
  core.c
  worker.c
  http_core.c
  mod_so.c
[root@localhost sbin]# ./httpd.event -l 
Compiled in modules:
  core.c
  event.c
  http_core.c
  mod_so.c
[root@localhost sbin]# ls
ab         apxs      dbmmanage  envvars-std   htdbm     htpasswd  httpd.event   httxt2dbm   rotatelogs
apachectl  checkgid  envvars    htcacheclean  htdigest  httpd     httpd.worker  logresolve  suexec
[root@localhost sbin]# cd ../
[root@localhost httpd]# ls
bin  conf  include  logs  modules  sbin  share  www
[root@localhost httpd]# ls -l share/man
total 0
drwxr-xr-x 2 root root  95 Dec  8 22:30 man1
drwxr-xr-x 2 root root 144 Dec  8 22:30 man8
[root@localhost httpd]# pwd
/data/application/httpd
[root@localhost httpd]# ls -l www/
total 28
drwxr-xr-x  2 root root  167 Dec  8 22:30 build
drwxr-xr-x  2 root root   38 Dec  8 22:30 cgi-bin
drwxr-xr-x  3 root root 4096 Dec  8 22:30 error
drwxr-xr-x  2 root root   24 Dec  8 22:30 htdocs
drwxr-xr-x  3 root root 8192 Dec  8 22:30 icons
drwxr-xr-x 14 root root 8192 Dec  8 22:30 manual
[root@localhost httpd]# ls -l conf/
total 88
drwxr-xr-x 2 root root   290 Dec  8 22:30 extra
-rw-r--r-- 1 root root 17425 Dec  8 22:30 httpd.conf
-rw-r--r-- 1 root root 12958 Dec  8 22:30 magic
-rw-r--r-- 1 root root 53015 Dec  8 22:30 mime.types
drwxr-xr-x 3 root root    37 Dec  8 22:30 original
[root@localhost httpd]# ls -l bin/
total 0
[root@localhost httpd]# ls -l logs/
total 0
[root@localhost httpd]# ls -l modules/ | tail -n 3
-rwxr-xr-x 1 root root   43776 Dec  8 22:30 mod_usertrack.so
-rwxr-xr-x 1 root root   26928 Dec  8 22:30 mod_version.so
-rwxr-xr-x 1 root root   39872 Dec  8 22:30 mod_vhost_alias.so
[root@localhost httpd]# ls -l modules/ | wc -l
69

添加环境变量和man手册的指向:

echo 'export PATH=$PATH:/data/application/httpd/sbin' > /etc/profile.d/httpd22.sh
source /etc/profile
echo 'MANPATH /data/application/httpd/share/man' >>/etc/man.config

查看:
[root@localhost httpd]# httpd -v
Server version: Apache/2.2.34 (Unix)
Server built:   Dec  8 2018 22:28:44
[root@localhost httpd]# httpd.worker -v
Server version: Apache/2.2.34 (Unix)
Server built:   Dec  8 2018 22:31:42
[root@localhost httpd]# httpd.event -v
Server version: Apache/2.2.34 (Unix)
Server built:   Dec  8 2018 22:33:53
[root@localhost httpd]# httpd -l && httpd.worker -l && httpd.event -M |grep 'mpm'
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c
Compiled in modules:
  core.c
  worker.c
  http_core.c
  mod_so.c
httpd.event: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK
 mpm_event_module (static)

apache的httpd项目的官网地址:http://httpd.apache.org/
apache的apr项目的官网地址:https://apr.apache.org/
旧版的httpd的源码包官网的下载链接:http://archive.apache.org/dist/httpd/
旧版的apr先关的源码包官网的下载链接:http://archive.apache.org/dist/apr/
apache所有项目的旧版源码包官网的下载链接:http://archive.apache.org/dist/
可以从下面这个目录找到httpd2.2老版本的srpm包和rpm包:http://archive.apache.org/dist/httpd/binaries/
可以从下面这个目录找到apr以及apr-util老版本的srpm包:http://archive.apache.org/dist/apr/binaries/

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值