WEB安装文档
1. GCC4.1.0安装(可选)
下载地址: ftp://linuxforum.net/pub/gcc/releases/gcc-4.1.0/gcc-4.1.0.tar.bz2
# tar jxf gcc-4.1.0.tar.bz2
# mkdir gcc-build;cd gcc-build
# ../gcc-4.1.0/configure --prefix=/usr/local/gcc4.1 && make && make install
# cd /usr/bin; mv gcc _gcc
# ln -s /usr/local/gcc4.1/bin/gcc gcc
# gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1.0/configure --prefix=/usr/local/gcc4.1
Thread model: posix
gcc version 4.1.0
如果有以上的输出,说明gcc编译安装成功.
2. APACHE2.2编译安装
下载apache2.2源码包 http://mirror.vmmatrix.net/apache/httpd/httpd-2.2.0.tar.bz2
2.1. 解压缩
# tar jxvf httpd-2.2.0.tar.bz2
# cd httpd-2.2.0
2.2. 修改部分源代码
# 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
2.3. 编译配置
优化编译选项及配置apache可加载的模块
# CFLAGS="-O6 -mpentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" > ./configure --prefix=/usr/local/apache2.2 --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-suexec
2.4. 编译及安装
# gmake && make install
3. 优化apache配置选项
3.1. 修改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 50
MaxSpareThreads 256
ThreadsPerChild 128
MaxRequestsPerChild 0
</IfModule>
3.2. 修改apache2.2子进程所有者
# vi /usr/local/apache2.2/conf/httpd.conf
把daemon改为nobody
User nobody
Group nobody
3.3. 语法检查及建立软链接
# vi /usr/local/apache2.2/conf/httpd.conf
在主配置文件httpd.conf添加如下一行,这样做的目的是把apache的功能配置分成小文件,便于修改和移植
# Include conf/Includes/*.conf
运行语法检查命令检查语法,出现错误后继续调整。
# ./bin/apachectl -t
没有错误后在 /usr/local/ 目录下建立软链接
# ln -s apache2.2 apache2
4. 安装tomcat和连接器JK
原先的JK2模块已经不被官方支持,而且在性能上和现有的jk模块也有差距,所以改用JK模块。
4.1. 下载tomcat-5.5.16
http://apache.justdn.org/tomcat/tomcat-5/v5.5.16/bin/apache-tomcat-5.5.16.tar.gz
JDK自行安装,安装后要记得设置 JAVA_HOME系统变量。
# export JAVA_HOME=/usr/local/jdk1.5.0_06
# tar zxf apache-tomcat-5.5.16.tar.gz -C /usr/local/
# mv apache-tomcat-5.5.16 tomcat-5.5.16
# ln -s tomcat-5.5.16 tomcat1
# cd /usr/local/tomcat1/bin
# ./bin/startup.sh //启动tomcat
# ./bin/shutdown.sh //停止tomcat
4.2. 下载连接器JK源码
http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz
4.3. 编译安装
# tar zxvf jakarta-tomcat-connectors-1.2.15-src.tar.gz
# cd jakarta-tomcat-connectors-1.2.15-src
# cd jk/native/
# ./configure --with-apxs=/usr/local/apache2.2/bin/apxs > --with-java-home=/usr/local/jdk15 --with-java-platform=2
# make
# cp apache-2.0/mod_jk.so /usr/local/apache2.2/modules/
4.4. 配置
# cd /usr/local/apache2.2/conf/Includes
# vi mod_jk.conf
在文本中添加如下配置
# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /usr/local/apache2/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/apache2/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel error
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkShmFile /usr/local/apache2/logs/mod_jk.shm
# Send jsp,servlet for context * to worker named worker1
JkMount /status/* worker1
JkMount /*.jsp worker1
JkMount /*.jsps worker1
JkMount /*.do worker1
JkMount /*Servlet worker1
JkMount /manager/* worker1
JkMount /ScanIM worker1
JkMount /SendIMMsg worker1
JkMount /CheckMsgServlet worker1
JkMount /TestIM worker1
# vi ../workers.properties
在配置文件中添加如下配置
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=127.0.0.1
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.reclycle_timeout=300
4.5. 测试
如果在80端口能访问.jsp,.do等文件说明配置连接器成功。
5. 配置静态页面压缩输出模块deflate
这个扩展模块在安装apache的时候已经动态的编译到apache里去了。现在进行配置。
# cd /usr/local/apache2.2/conf/Includes
上面添加的是apache扩展配置文件的目录
# vi mod_deflate.conf
在配置文件里添加如下语句
DeflateMemLevel 9
SetOutputFilter DEFLATE
DeflateFilterNote ratio
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
6. 配置mod_cache模块
# cd /usr/local/apache2.2/conf/Includes
# vi mod_cache.conf
在配置文件里添加如下语句
<IfModule mod_cache.c>
#LoadModule disk_cache_module modules/mod_disk_cache.so
<IfModule mod_disk_cache.c>
CacheRoot /
CacheSize 256
CacheEnable disk /
CacheDirLevels 5
CacheDirLength 3
</IfModule>
LoadModule mem_cache_module modules/mod_mem_cache.so
<IfModule mod_mem_cache.c>
CacheEnable mem /
MCacheSize 4096
MCacheMaxObjectCount 100
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048
</IfModule>
</IfModule>
7. 检查apache运行状态
检查apache2.2所有配置文件是否有错误
# /usr/local/apache2.2/bin/apachectl -t
有错继续修改调整,没有就启动apache2.2
# /usr/local/apache2.2/bin/apachectl start
查看80端口是否在监听
# netstat -apn|grep '\<80\>'
查看apache进程是否运行
# ps aux|grep httpd
建立测试页面测试.
8. 安装apache日志切割工具cronolog
# tar zxf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure --prefix=/usr/local/cronolog && make && make install
9. apache基本虚拟主机配置
比如某一机器 域名 www.test.com IP: 59.42.25.35
在apache安装目录下
# vi conf/httpd.conf
在最后一行添加全局虚拟主机配置
NameVirtualHost 59.42.25.35
# vi conf/Includes/www.test.com.conf
建立www.test.com 虚拟主机 配置文件
<Directory "/www/www.test.com /www/htdocs">
order allow,deny
allow from all
</Directory>
<Directory "/www/www.test.com /www/htdocs/WEB-INF">
order deny,allow
deny from all
allow from 127.0.0.1 10.10.10.86 59.34.215.86 61.144.207.69
</Directory>
<VirtualHost 59.42.25.35>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/www.test.com /www/htdocs
ServerName /www.test.com
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
#LoadModule deflate_module modules/mod_deflate.so
#DeflateFilterNote ratio
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
ErrorLog "|/usr/local/cronolog/sbin/cronolog /www//www.test.com /www/logs/%Y/%m/%d/error.log"
#SetEnvIf Request_URI "^[/im/checkIM]\.jsp|\.do|\.html|.jsps" please_log
SetEnvIf Request_URI "\.jsp" please_log
SetEnvIf Request_URI "\.jsps" please_log
SetEnvIf Request_URI "\.do" please_log
SetEnvIf Request_URI "\.html" please_log
CustomLog "|/usr/local/cronolog/sbin/cronolog /www/www.test.com /www/logs/%Y/%m/%d/%p/access.log" combined env=please_log
</VirtualHost>
10. tomcat基本虚拟主机配置
在tomcat安装目录下
# vi conf/server.xml
在文件的标签 </Engine>添加
<Host name="www.test.com" debug="0" appBase="/www/www.test.com/www/htdocs" unpackWARs="true"
autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="test."
suffix=".log" timestamp="true"/>
<Context path="/manager" docBase="${catalina.home}/server/webapps/manager"
debug="0" privileged="true">
<ResourceLink name="users" global="UserDatabase" type="org.apache.catalina.UserDatabase"/>
</Context>
<Context docBase="/www/www.test.com/www/htdocs" path="" reloadable="true">
</Context>
<alias>mail.test.com</alias>
<alias>forum.test.com</alias>
<alias>group.test.com</alias>
<alias>favorites.test.com</alias>
<alias>classifieds.test.com</alias>
</Host>