日期:2014-05-16  浏览次数:20705 次

linux下apache2.2性能优化和安装_重要
2011年02月17日 星期四 23:31转载自 macaque1101最终编辑 macaque1101# 解压缩
tar jxvf httpd-2.2.2.tar.bz2
cd httpd-2.2.0

# vi server/mpm/worker/worker.c
找到下面几行,并改成如下的数值,其目的是在源码中修改apache可支持的最大线程数和最大客户端数目。
# define DEFAULT_SERVER_LIMIT 256
# define MAX_SERVER_LIMIT 40000
# define DEFAULT_THREAD_LIMIT 256
# define MAX_THREAD_LIMIT 40000


# 编译和安装 apr 1.2
cd srclib/apr
./configure --prefix=/home/liuchao/local/apr
make
make install

# 编译和安装 apr-util 1.2
cd ../apr-util
./configure --prefix=/home/local/apr-util --with-apr=/home/local/apr
make
make install

优化编译选项及配置apache可加载的模块
patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff
/usr/local/apache2.2.3/bin/apxs -c -i -a mod_limitipconn.c
/usr/local/apache2.2/bin/apxs -c -i -a mod_evasive20.c

更改2Glogs
export CFLAGS="-O2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
然后编译cronolog即可
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

./configure --prefix=/usr/local/apache2.2.3 --enable-mods-shared=all --enable-so --with-mpm=worker --enable-deflate --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-proxy --enable-rewrite --enable-charset-lite --enable-suexec --with-suexec-bin=/usr/sbin/suexec --disable-ipv6 -disable-dav --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

# 编译及安装
gmake && make install

二、优化apache配置选项

在主配置文件httpd.conf注释下一行,这样做的目的是把apache的功能配置分成小文件,便于修改和移植
Include conf/Includes/*.conf

修改MPM(多道处理器)参数
# cd /usr/local/apache2.2
# vi conf/extra/httpd-mpm.conf
找到如下选项,并改成对应的数值

<IfModule mpm_worker_module>
ServerLimit           64
ThreadLimit          128
StartServers           8
MaxClients          8192
MinSpareThreads       64
MaxSpareThreads       256
ThreadsPerChild       128
MaxRequestsPerChild    0
</IfModule>

ServerLimit              64
ThreadLimit              64
StartServers              8
MaxClients             4096
MinSpareThreads          64
MaxSpareThreads         256
ThreadsPerChild          64
MaxRequestsPerChild     500

测试过的配置:<IfModule mpm_worker_module>
ServerLimit          32
ThreadLimit          64
StartServers          8
MaxClients         2048
MinSpareThreads      64
MaxSpareThreads      256
ThreadsPerChild       64
MaxRequestsPerChild   0
</IfModule>

修改apache2.2子进程所有者
# vi /usr/local/apache2.2/conf/httpd.conf
把daemon改为nobody
User nobody
Group nobody

一般说来,可以不需要的模块包括:
#LoadModule env_module libexec/mod_env.so
#LoadModule negotiation_module libexec/mod_negotiation.