源码的好处是比较灵活,想放哪里定制路径就放哪里

前提准备:Centos7系统、下载httpd2.4源代码、安装编译前的软件环境;连接教室物理网络。

1、下载httpd2.4.25源码 [root@Magedu ~]# yum -y install lftp [root@Magedu ~]# lftpget ftp://172.18.0.1/pub/Sources/sources/httpd/httpd-2.4.25.tar.bz2 将下载好的http2.4.25进行解压缩, [root@centos7 data]# ll total 6268 -rw------- 1 root root 1421 Jan 30 13:05 anaconda-ks.cfg -rwxr-xr-x 1 root root 360 Jan 26 14:24 hallo.sh drwxr-xr-x 11 501 games 4096 Dec 17 2016 httpd-2.4.25 -rw-r--r-- 1 root root 6398218 Oct 15 08:31 httpd-2.4.25.tar.bz2 -rw-r--r-- 1 root root 984 Jan 24 20:34 magedu.pubkey [root@centos7 data]# du -sh httpd-2.4.25 43M httpd-2.4.25 [root@centos7 data]# cd httpd-2.4.25/ [root@centos7 httpd-2.4.25]# ls ABOUT_APACHE CMakeLists.txt INSTALL NWGNUmakefile acinclude.m4 config.layout InstallBin.dsp os Apache-apr2.dsw configure LAYOUT README Apache.dsw configure.in libhttpd.dep README.cmake apache_probes.d docs libhttpd.dsp README.platforms ap.d emacs-style libhttpd.mak ROADMAP build httpd.dep LICENSE server BuildAll.dsp httpd.dsp Makefile.in srclib BuildBin.dsp httpd.mak Makefile.win support buildconf httpd.spec modules test CHANGES include NOTICE VERSIONING [root@centos7 httpd-2.4.25]# tree │   └── wintty.mak ├── test │   ├── check_chunked │   ├── cls.c │   ├── Makefile.in │   ├── make_sni.sh │   ├── README │   ├── tcpdumpscii.txt │   ├── test_find.c │   ├── test_limits.c │   ├── test_parser.c │   ├── test_select.c │   ├── test-writev.c │   └── time-sem.c └── VERSIONING

95 directories, 2776 files 可以看到有非常多“ . c ”文件, [root@centos7 httpd-2.4.25]# find -name "*.c" |wc -l 284 共284个 对于此类复杂脚本如何编译安装,我们接着看:

2、安装编译前的环境即安装Development tools包组及依赖 [root@Magedu ~]# yum -y groupinstall “Development Tools” [root@centos7 httpd-2.4.25]# make make: *** No targets specified and no makefile found. Stop. [root@centos7 httpd-2.4.25]# which make /usr/bin/make [root@centos7 httpd-2.4.25]# rpm -qf /usr/bin/make make-3.82-23.el7.x86_64 [root@centos7 httpd-2.4.25]# file /usr/bin/make /usr/bin/make: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=77eee6e2b89ced609bef92cd9ef75bb7e056d83b, stripped make本身是一个二进制文件,要借助于mskefile文本文件。 我们要在Makefile文件中放安装路径,那些文件启用哪些文件不启用。利用 make 项目管理器就能实现自动安装和编译安装。

3、预编译config配置 [root@centos7 httpd-2.4.25]# ./configure --prefix=/apps/httpd/ --sysconfdir=/etc/httpd/ --enable-ssl checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation. [root@centos7 httpd-2.4.25]# yum search apr Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile ============================= N/S matched: apr ============================= apr-devel.i686 : APR library development kit apr-devel.x86_64 : APR library development kit apr-util-devel.i686 : APR utility library development kit apr-util-devel.x86_64 : APR utility library development kit apr-util-ldap.x86_64 : APR utility library LDAP support apr-util-mysql.x86_64 : APR utility library MySQL DBD driver apr-util-nss.x86_64 : APR utility library NSS crytpo support apr-util-odbc.x86_64 : APR utility library ODBC DBD driver apr-util-openssl.x86_64 : APR utility library OpenSSL crytpo support apr-util-pgsql.x86_64 : APR utility library PostgreSQL DBD driver apr-util-sqlite.x86_64 : APR utility library SQLite DBD driver libapreq2-devel.x86_64 : Development files for libapreq2 libchromaprint-devel.x86_64 : Headers for developing programs that will use : chromaprint pcp-pmda-haproxy.x86_64 : Performance Co-Pilot (PCP) metrics for HAProxy php-whitehat101-apr1-md5.noarch : Apache's APR1-MD5 algorithm in pure PHP apr.i686 : Apache Portable Runtime library apr.x86_64 : Apache Portable Runtime library apr-util.i686 : Apache Portable Runtime Utility library apr-util.x86_64 : Apache Portable Runtime Utility library golang-github-armon-go-proxyproto-devel.noarch : Golang package to handle : HAProxy Proxy Protocol haproxy.x86_64 : TCP/HTTP proxy and load balancer for high availability : environments libapreq2.x86_64 : Apache HTTP request library libchromaprint.x86_64 : Library implementing the AcoustID fingerprinting libfap.x86_64 : An APRS parser written in C perl-libapreq2.x86_64 : Perl interface to the Apache HTTP request library snapraid.x86_64 : Disk array backup for many large rarely-changed files Name and summary matches only, use "search all" for everything. [root@centos7 httpd-2.4.25]# yum install apr-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package apr-devel.x86_64 0:1.4.8-3.el7_4.1 will be installed --> Finished Dependency Resolution

Dependencies Resolved

============================================================================ Package Arch Version Repository Size

Installing: apr-devel x86_64 1.4.8-3.el7_4.1 development 188 k

Transaction Summary

Install 1 Package

Total download size: 188 k Installed size: 771 k Is this ok [y/d/N]: y Downloading packages: apr-devel-1.4.8-3.el7_4.1.x86_64.rpm | 188 kB 00:00
Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : apr-devel-1.4.8-3.el7_4.1.x86_64 1/1 Verifying : apr-devel-1.4.8-3.el7_4.1.x86_64 1/1

Installed: apr-devel.x86_64 0:1.4.8-3.el7_4.1

Complete!

此处报错提示“ checking for APR... no ”,我们要安装的是“ yum install apr-devel ”。

我们再次检查,报错提示: [root@centos7 httpd-2.4.25]# ./configure --prefix=/apps/httpd/ --sysconfdir=/etc/httpd/ --enable-ssl checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... yes setting CC to "gcc" setting CPP to "gcc -E" setting CFLAGS to " -pthread" setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE" setting LDFLAGS to " " configure: configure: Configuring Apache Portable Runtime Utility library... configure: checking for APR-util... no configure: error: APR-util not found. Please read the documentation. [root@centos7 httpd-2.4.25]# yum search apr Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile ============================= N/S matched: apr ============================= apr-devel.i686 : APR library development kit apr-devel.x86_64 : APR library development kit apr-util-devel.i686 : APR utility library development kit apr-util-devel.x86_64 : APR utility library development kit apr-util-ldap.x86_64 : APR utility library LDAP support apr-util-mysql.x86_64 : APR utility library MySQL DBD driver apr-util-nss.x86_64 : APR utility library NSS crytpo support apr-util-odbc.x86_64 : APR utility library ODBC DBD driver apr-util-openssl.x86_64 : APR utility library OpenSSL crytpo support apr-util-pgsql.x86_64 : APR utility library PostgreSQL DBD driver apr-util-sqlite.x86_64 : APR utility library SQLite DBD driver libapreq2-devel.x86_64 : Development files for libapreq2 libchromaprint-devel.x86_64 : Headers for developing programs that will use : chromaprint pcp-pmda-haproxy.x86_64 : Performance Co-Pilot (PCP) metrics for HAProxy php-whitehat101-apr1-md5.noarch : Apache's APR1-MD5 algorithm in pure PHP apr.i686 : Apache Portable Runtime library apr.x86_64 : Apache Portable Runtime library apr-util.i686 : Apache Portable Runtime Utility library apr-util.x86_64 : Apache Portable Runtime Utility library golang-github-armon-go-proxyproto-devel.noarch : Golang package to handle : HAProxy Proxy Protocol haproxy.x86_64 : TCP/HTTP proxy and load balancer for high availability : environments libapreq2.x86_64 : Apache HTTP request library libchromaprint.x86_64 : Library implementing the AcoustID fingerprinting libfap.x86_64 : An APRS parser written in C perl-libapreq2.x86_64 : Perl interface to the Apache HTTP request library snapraid.x86_64 : Disk array backup for many large rarely-changed files

Name and summary matches only, use "search all" for everything. [root@centos7 httpd-2.4.25]# yum install apr-util-devel Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package apr-util-devel.x86_64 0:1.5.2-6.el7 will be installed --> Processing Dependency: openldap-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64 --> Processing Dependency: libdb-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64 --> Processing Dependency: expat-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64 --> Running transaction check ---> Package expat-devel.x86_64 0:2.1.0-10.el7_3 will be installed ---> Package libdb-devel.x86_64 0:5.3.21-24.el7 will be installed ---> Package openldap-devel.x86_64 0:2.4.44-20.el7 will be installed --> Processing Dependency: cyrus-sasl-devel(x86-64) for package: openldap-devel-2.4.44-20.el7.x86_64 --> Running transaction check ---> Package cyrus-sasl-devel.x86_64 0:2.1.26-23.el7 will be installed --> Finished Dependency Resolution

Dependencies Resolved

============================================================================ Package Arch Version Repository Size

Installing: apr-util-devel x86_64 1.5.2-6.el7 development 76 k Installing for dependencies: cyrus-sasl-devel x86_64 2.1.26-23.el7 development 310 k expat-devel x86_64 2.1.0-10.el7_3 development 57 k libdb-devel x86_64 5.3.21-24.el7 development 38 k openldap-devel x86_64 2.4.44-20.el7 development 804 k

Transaction Summary

Install 1 Package (+4 Dependent packages)

Total download size: 1.3 M Installed size: 5.2 M Is this ok [y/d/N]: y Downloading packages: (1/5): apr-util-devel-1.5.2-6.el7.x86_64.rpm | 76 kB 00:00
(2/5): cyrus-sasl-devel-2.1.26-23.el7.x86_64.rpm | 310 kB 00:00
(3/5): expat-devel-2.1.0-10.el7_3.x86_64.rpm | 57 kB 00:00
(4/5): libdb-devel-5.3.21-24.el7.x86_64.rpm | 38 kB 00:00
(5/5): openldap-devel-2.4.44-20.el7.x86_64.rpm | 804 kB 00:00

Total 1.2 MB/s | 1.3 MB 00:01
Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libdb-devel-5.3.21-24.el7.x86_64 1/5 Installing : expat-devel-2.1.0-10.el7_3.x86_64 2/5 Installing : cyrus-sasl-devel-2.1.26-23.el7.x86_64 3/5 Installing : openldap-devel-2.4.44-20.el7.x86_64 4/5 Installing : apr-util-devel-1.5.2-6.el7.x86_64 5/5 Verifying : openldap-devel-2.4.44-20.el7.x86_64 1/5 Verifying : apr-util-devel-1.5.2-6.el7.x86_64 2/5 Verifying : cyrus-sasl-devel-2.1.26-23.el7.x86_64 3/5 Verifying : expat-devel-2.1.0-10.el7_3.x86_64 4/5 Verifying : libdb-devel-5.3.21-24.el7.x86_64 5/5

Installed: apr-util-devel.x86_64 0:1.5.2-6.el7

Dependency Installed: cyrus-sasl-devel.x86_64 0:2.1.26-23.el7
expat-devel.x86_64 0:2.1.0-10.el7_3
libdb-devel.x86_64 0:5.3.21-24.el7
openldap-devel.x86_64 0:2.4.44-20.el7
Complete! 我们按上面的思路安装即可。第一次安装无经验,下一次安装就知道缺什么,就可直接安装了。

4、编译:[root@Magedu httpd-2.4.25]# make -j 4 注意:使用-j 4表示编译时,使用4个cpu同时工作

5、安装:[root@Magedu httpd-2.4.25]# make install 6、添加全局环境变量即将执行命令和帮助文档的路径写入PATH [root@Magedu httpd-2.4.25]# vim /etc/profile.d/env.sh 添加: export PATH=/app/apache24/BIN:$PATH 使其立即生效: [root@Magedu httpd-2.4.25]# source /etc/profile.d/env.sh 配置帮助文档路径: [root@Magedu httpd-2.4.25]# vim /etc/man_db.conf 添加: MANDATORY_MANPATH /app/apache24/man

7、关闭防火墙: [root@Magedu ~]# apachectl start [root@Magedu ~]# iptables -F 完成!