首先下载以下软件包至服务器/usr/local/src目录
apache-tomcat-6.0.29.tar.gz
httpd-2.2.17.tar.gz
jdk-6u22-linux-x64-rpm.bin
libopenssl0_9_8-0.9.8k-6.2.x86_64.rpm
libopenssl-devel-0.9.8k-6.2.x86_64.rpm
tomcat-connectors-1.2.31-src.tar.gz
zlib-devel-1.2.3-134.1.x86_64.rpm
(服务器操作系统为64SUSE11,,32位操作系统请下载相应的32RPM包)
JDK安装
 
cd /usr/local/src
sh /usr/local/src/jdk-6u22-linux-x64-rpm.bin
 
安装完成后输入java version检测是否已经设置环境变量
java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)
 
#vi test.java
class test {    
       public static void main(String[] args) {
              System.out.println("hello world");
       }
}
保存退出
#javac test.java
#java test
如果终端输出
hello world
则表示java环境已经装好。
(由于此版本会自动设置环境变量,无需再做设置)
如果环境变量没有自动设置,则在/etc/profile中加入如下配置,重新加载环境变量即可。
export JAVA_HOME=/usr/java/jdk1.6.0_23
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH:
export JRE_HOME=$JAVA_HOME/jre/bin
 
apache安装
首先安装openssl-devel包,否则不能编译支持ssl
rpm -Uvh libopenssl0_9_8-0.9.8k-6.2.x86_64.rpm
rpm -ivh zlib-devel-1.2.3-134.1.x86_64.rpm
rpm -ivh libopenssl-devel-0.9.8k-6.2.x86_64.rpm
 
tar zxvf httpd-2.2.17.tar.gz
cd /usr/local/src/httpd-2.2.17/srclib/apr
./configure --prefix=/usr/local/apr
make;make install
 
cd /usr/local/src/httpd-2.2.17/srclib/apr-util/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make;make install
 
cd /usr/local/src/httpd-2.2.17/
 
./configure --prefix=/usr/local/httpd --enable-so --enable-deflate --enable-expires --enable-rewrite --enable-authn-dbm=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --with-mpm=worker --disable-userdir --enable-ssl --with-ssl --disable-cgid --disable-cgi --enable-static-support --enable-static-checkgid --enable-lib64 -libdir=/usr/lib64 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/bin
make;make install
/usr/local/httpd/bin/apachectl start
 
开启防火墙
vi /etc/sysconfig/SuSEfirewall2
开放80以及8080端口
FW_SERVICES_EXT_TCP="22 80 8080"
保存退出
重启让配置生效
rcSuSEfirewall2 restart
 
测试
在浏览器中访问本机IP192.168.0.1测试。
出现下面的页面则apache安装成功。
It works! 添加apache开机自动启动 echo /usr/local/httpd/bin/apachectl start >> /etc/init.d/after.local
Tomcat安装
cd /usr/local/src
tar -zxvf apache-tomcat-6.0.29.tar.gz
mv apache-tomcat-6.0.29 /usr/local/tomcat
添加tomcat开机自动启动
echo /usr/local/tomcat/bin/startup.sh >> /etc/init.d/after.local
保存退出
添加tomcat快速启动。
vi /etc/init.d/tomcat
# !/bin/bash
# Description:  start or stop the tomcat
# Usage:        tomcat [start|stop|reload|restart]
# Author:       Zong Guofeng
# Date:         Thu May 17, 2010
#
export PATH=$PATH:$HOME/bin
export BASH_ENV=$HOME/.bashrc
export USERNAME="root"
    case "$1" in
    start)
    #startup the tomcat
       echo -n "tomcat start: "
     cd /usr/local/tomcat/bin/
     ./startup.sh
       echo " Tomcat start finished"
    ;;
    stop)
    # stop tomcat
       echo -n "tomcat stop:"
       ps -ef | grep "java" | grep -v grep | sed 's/ [ ]*/:/g'|cut -d: -f2| kill -9 `cat`
 cd /usr/local/tomcat/bin/
 rm -rf Catalina
       echo "finished"
    ;;
    reload|restart)
        $0 stop
        $0 start
    ;;
    *)
       echo "Usage: tomcat [start|stop|reload|restart]"
       exit 1
    esac
exit 0
 
chmod 755 /etc/init.d/tomcat
ln -s /etc/init.d/tomcat /usr/bin
tomcat start
 
 
http://192.168.0.1:8080/
访问测试。
 
 
Tomcatapache整合
tar -zxvf tomcat-connectors-1.2.31-src.tar.gz
cd /usr/local/src/tomcat-connectors-1.2.31-src/native
./configure --with-apxs=/usr/local/httpd/bin/apxs --with-java-home=/usr/java/jdk1.6.0_22/
make;make install
此源码包会自动将编译的mod_jk.so拷贝到apachemodules目录。
检测是否拷贝mod_jk.so
ls /usr/local/httpd/modules/mod_jk.so
如果文件存在则不需要做操作,如不存在则拷贝一个至apachemodules目录。
cp apache-2.0/mod_jk.so /usr/local/httpd/modules
 
编辑apache的配置文件:
vi /usr/local/httpd/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.html index.jsp
</IfModule>
LoadModule jk_module modules/mod_jk.so
Include /usr/local/httpd/conf/mod_jk.conf
保存退出
 
vi /usr/local/httpd/conf/mod_jk.conf
 
JkWorkersFile /usr/local/httpd/conf/workers.properties
 
# Where to put jk logs
JkLogFile /usr/local/httpd/logs/mod_jk.log
 
# Set the jk log level [debug/error/info]
JkLogLevel info
 
# 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"
 
JkMount /servlet/*  worker1
JkMount /*.jsp worker1
保存退出。
 
vi /usr/local/httpd/conf/workers.properties
 
# Set properties for worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost 
worker.worker1.port=8009
worker.worker1.lbfactor=50 
worker.worker1.cachesize=10 
worker.worker1.cache_timeout=600 
worker.worker1.socket_keepalive=1 
worker.worker1.socket_timeout=300
worker.list=worker1
worker.worker1.socket_keepalive=1
worker.worker1.lbfactor=1
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr
保存退出。
 
vi /usr/local/tomcat/conf/server.xml
 
</Host>中加入以下配置
<Context path="" docBase="/usr/local/httpd/htdocs"
      debug="0" reloadable="true" crossContext="true"/>
保存退出
重启apache以及tomcat
/usr/local/httpd/bin/apachectl restart
tomcat restart
 
测试
vi /usr/local/httpd/htdocs/test.jsp
<html>
<body>
<h1>JSP Test</h1>
<%=new java.util.Date()%>
</body>
</html>
访问http://192.168.1.1/test.jsp/
http://192.168.0.1:8080/test.jsp/
页面显示主机时间说明整合成功。