一、所需软件
jdk-6u22-linux-x64.bin、 apache-tomcat-6.0.26.tar.gz
 
二、安装
1、安装 JDK
./jdk-6u22-linux-i586.bin
mv jdk1.6.0_22/ /usr/local/
 
2、安装 tomcat
tar zxvf apache-tomcat-6.0.26.tar.gz
mv apache-tomcat-6.0.26 /usr/local/
cd /usr/local/
mv apache-tomcat-6.0.26/ tomcat1
 
3、配置环境变量
vi /etc/profile
JAVA_HOME=/usr/local/jdk1.6.0_22
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
 
source /etc/profile
 
4、测试
java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
 
5、用普通用户启动 tomcat
cd /usr/local/tomcat1/bin
tar zxvf jsvc.tar.gz
cd jsvc-src
chmod +x configure
./configure --with-java=/usr/local/jdk1.6.0_22
make
 
6、创建用户
useradd tomcat
 
7、修改配置文件
vi server.xml(修改如下内容)
           
 
8、创建启动脚本
vi /etc/init.d/tomcat1
#!/bin/sh
# Startup Script for Tomcat6
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
 
. /etc/rc.d/init.d/functions 
export JAVA_HOME=/usr/local/jdk1.6.0_22
export CATALINA_HOME=//usr/local/tomcat1
 
DAEMON_HOME=$CATALINA_HOME/bin
 
TOMCAT_USER=tomcat
 
# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=$CATALINA_HOME
 
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
 
case "$1" in
  start)
    #
    # Start Tomcat
    #
    $DAEMON_HOME/jsvc-src/jsvc \
    -user $TOMCAT_USER \
    -home $JAVA_HOME \
    -Dcatalina.home=$CATALINA_HOME \
    -Dcatalina.base=$CATALINA_BASE \
    -Djava.io.tmpdir=$TMP_DIR \
    -wait 10 \
    -pidfile $PID_FILE \
    -outfile $CATALINA_HOME/logs/catalina.out \
    -errfile '&1' \
    $CATALINA_OPTS \
    -cp $CLASSPATH \
    org.apache.catalina.startup.Bootstrap
    #
    # To get a verbose JVM
    #-verbose \
    # To get a debug of jsvc.
    #-debug \
    exit $?
    ;;
 
  stop)
    #
    # Stop Tomcat
    #
    $DAEMON_HOME/jsvc-src/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
    exit $?
    ;;
 
  *)
    echo "Usage tomcat.sh start/stop"
    exit 1;;
esac
 
chmod a+x /etc/init.d/tomcat1
 
9、启动 |关闭
su - tomcat
/etc/init.d/tomcat1 start|stop
 
三、安装第二个 tomcat
cp –r /usr/local/tomcat1 /usr/local/tomcat2
cp /etc/init.d/tomcat1 /etc/init.d/tomcat2
 
vi server.xml(修改如下内容)
               connectionTimeout="20000"
               redirectPort="9443"
               URIEncoding="UTF-8" />
 
vi /etc/init.d/tomcat2(修改如下内容)
export CATALINA_HOME=//usr/local/tomcat2
 
启动 |关闭
su - tomcat
/etc/init.d/tomcat2 start|stop
 
四、配置调度器 nginx
vi nginx.conf(增加以下内容)
   upstream tomcatserver {
      server 127.0.0.1:8080 srun_id=a weight=5 max_fails=2 fail_timeout=600s;
      server 127.0.0.1:8180 srun_id=b weight=5 max_fails=2 fail_timeout=600s;
      jvm_route $cookie_JSESSIONID|sessionid reverse;
   }
 
server {
   listen 80;
   server_name your domain;
 
   location / {
      root /webroot;
      index index.jsp index.do index.html index.htm;
      rewrite "^/([0-9]+)\.html$" /a.jsp?id=$1 last;
   }
 
   location ~ ^/WEB-INF/* {
      deny all;
   }
 
   location ~ .*\.(jsp|do)?$ {
      proxy_pass http://tomcatserver;
      include proxy.conf;
   }
 
   log_format mainlogs '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
 
   access_log /var/log/nginx/oa.log mainlogs;
 
   location ~ /\..+ {
      deny all;
   }
}
 
重启 nginx
/usr/local/nginx/sbin/nginx -t
/etc/init.d/nginx reload