Linux下Apache 2.4安装和配置教程
软件准备
1.apr
下载地址:http://mirror.bit.edu.cn/apache/apr/apr-1.4.8.tar.gz
2.apr-util
下载地址:http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.2.tar.gz
3.pcre
下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
4.httpd
下载地址:http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.6.tar.gz
引言:
作为最流行的Web服务器,Apache已经很久没有用重大更新来吸引用户的目光了。2012年8月16日,Apache终于进行了自2005年12月以来的首次重大更新,发布Apache HTTP Server 2.4.3。
Apache 2.4提供了很多性能方面的提升,包括支持更大流量、更好地支持云计、利用更少的内存处理更多的并发等。除此之外,新版Apache的提升还包括性能提升、内存利用、异步I/O的支持、动态反向代理设置、与时间驱动的Web服务器相当或更好的性能、更强大的处理资源分配能力,更便捷的缓存支持以及可定制的高速服务器和代理等。其它的功能还包括更简单的错误分析、更灵活的设置项、更强大的验证机制和更完整的文档。
Apache 2.4的主要目标之一是大幅改进性能,在这款刚刚发布的Web服务器中,我们发现它也从竞争对手Nginx处借鉴了不少,增加了不少对高性能的支持。它对缓存、代理模块、会话控制、异步读写支持等都进行了改进。
Apache服务器项目管理委员会和Apache基金会主席Jim Jagielski表示,他们希望终端用户能真正地看到性能进步,Apache 2.4比许多以速度见长的Web服务器更快,例如Nginx。
Apache 2.4安装配置步骤如下:
1、安装基础包
yum install gcc gcc-c++ zlib zlib-devel openssl openssl-devel libtool -y
libtool版本过低会出现错误,最新版本可从http://www.gnu.org/software/libtool/上下载
wget http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
tar xzvf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure
make
make install
cp /usr/local/bin/libtool /usr/bin/libtool
2、安装apr
cd apr
./configure --prefix=/web/server/apr/
make
make install
错误:rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
解决方案一:
在configure里面 RM='$RM -f' 这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。把RM='$RM'改为RM='$RM -f'
3、安装apr-util
cd ../apr-util
./configure --prefix=/web/server/apr-util/ --with-apr=/web/server/apr/
make
make install
4、安装pcre
cd pcre-8.31
./configure --prefix=/web/server/pcre
make
make install
5、安装httpd 2.4.6
编译必须把 apr,apr-util 的源文件放到 apache2.4.6 源码的 srclib 目录下,并修改 apr 源码目录为apr,apr-util 源码目录为 apr-util
cp -rf apr-1.4.8 ./httpd-2.4.6/srclib/apr
cp -rf apr-util-1.5.2 ./httpd-2.4.6/srclib/apr-util
cd httpd-2.4.6
./configure --prefix=/web/server/apache --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-ssl --with-ssl=/usr/local/openssl/ --enable-dav --enable-dav-fs --enable-dav-lock --enable-maintainer-mode --enable-rewrite --enable-so --with-apr=/web/server/apr/ --with-apr-util=/web/server/apr-util/ --with-pcre=/web/server/pcre --with-included-apr
make
make install
如果出现错误cannot install `libaprutil-1.la'
则表示服务器已经安装了httpd,或者以前安装过没有删除干净
可能出现的错误:make时出现server/.libs/libmain.a(exports.o):(.data+0xcfc): undefined reference to `apr_os_uuid_get’,解决办法:
cd srclib/apr; make
cd srclib/apr-util; make
再退回 apache 的源码目录重新 make
/****************************************/
6、安装Tomcat-connectors(mod_jk.so模块)
tar zxvf tomcat-connectors-1.2.37-src.tar.gz
cd tomcat-connectors-1.2.37-src/native/
./configure --with-apxs=/web/server/apache/bin/apxs --with-java-home=/usr/local/jdk
make && make install
检查/web/server/apache/modules下是否有mod_jk.so ,如果没有就复制过去。
注意conf/httpd.conf文件中ServerName xxx.xxx.com:80需要改为ServerName 127.0.0.1:80,可以使用apactrl -t进行语法分析
/*****************************************/
7、优化Apache
cp /web/server/apache/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd #编辑此服务,将前三行修改为
#!/bin/bash
# chkconfig: 35 85 15
# description:Apache httpd
service httpd restart
chkconfig --add httpd
chkconfig --level 35 httpd on
启动apache的时候出现错误modules/mod_dav_svn.so: undefined symbol: dav_register_provider
需要在编译的时候加入--enable-dav --enable-dav-fs --enable-dav-lock,如果还是出现错误,则需要在httpd配置文件中加入
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dav_lock_module modules/mod_dav_lock.so
这些模块需要在载入svn模块前载入(参考网址:http://www.tux.hk/index.php?m=04&y=10&entry=entry100412-172421)
参考网址:http://www.weste.net/2013/2-7/88883.html
查看apache编译参数
[root@cch apache]# cd build/
[root@cch build]# cat config.nice
#! /bin/sh
#
# Created by configure
“./configure” \
2013-08-09 下午 4:41“–prefix=/web/server/apache” \
“–enable-mods-shared=all” \
“–enable-deflate” \
“–enable-speling” \
“–enable-cache” \
“–enable-file-cache” \
“–enable-disk-cache” \
“–enable-mem-cache” \
“–enable-ssl” \
“–with-ssl=/usr/local/openssl/” \
“–enable-dav” \
“–enable-dav-fs” \
“–enable-dav-lock” \
“–enable-maintainer-mode” \
“–enable-rewrite” \
“–enable-so” \
“–with-apr=/web/server/apr/” \
“–with-apr-util=/web/server/apr-util/” \
“–with-pcre=/web/server/pcre” \
“–with-included-apr” \
“$@”