一、所需软件
jdk-6u22-linux-x64.bin、apache-tomcat-6.0.26.tar.gz
二、安装1、安装JDK./jdk-6u22-linux-i586.binmv jdk1.6.0_22/ /usr/local/2、安装tomcattar zxvf apache-tomcat-6.0.26.tar.gzmv apache-tomcat-6.0.26 /usr/local/cd /usr/local/mv apache-tomcat-6.0.26/ tomcat13、配置环境变量vi /etc/profileJAVA_HOME=/usr/local/jdk1.6.0_22CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarPATH=$JAVA_HOME/bin:$PATHexport JAVA_HOME CLASSPATH PATHsource /etc/profile4、测试java -versionjava 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、用普通用户启动tomcatcd /usr/local/tomcat1/bintar zxvf jsvc.tar.gzcd jsvc-srcchmod +x configure./configure --with-java=/usr/local/jdk1.6.0_22make6、创建用户useradd tomcat7、修改配置文件vi server.xml(修改如下内容)<Engine name="Catalina" defaultHost="localhost" jvmRoute="a"><Host name="your domain" appBase="webapps" unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"><Context path="" docBase="/webroot/" workDir="" /></Host>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_22export CATALINA_HOME=//usr/local/tomcat1DAEMON_HOME=$CATALINA_HOME/binTOMCAT_USER=tomcat# for multi instances adapt those lines.TMP_DIR=/var/tmpPID_FILE=/var/run/jsvc.pidCATALINA_BASE=$CATALINA_HOMECATALINA_OPTS=CLASSPATH=\$JAVA_HOME/lib/tools.jar:\$CATALINA_HOME/bin/commons-daemon.jar:\$CATALINA_HOME/bin/bootstrap.jarcase "$1" instart)## 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.Bootstrapexit $?;;*)echo "Usage tomcat.sh start/stop"exit 1;;esacchmod a+x /etc/init.d/tomcat19、启动|关闭su - tomcat/etc/init.d/tomcat1 start|stop三、安装第二个tomcatcp –r /usr/local/tomcat1 /usr/local/tomcat2cp /etc/init.d/tomcat1 /etc/init.d/tomcat2vi server.xml(修改如下内容)<Server port="8105" shutdown="SHUTDOWN"><Connector port="8180" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="9443"URIEncoding="UTF-8" /><Connector port="8109" protocol="AJP/1.3" redirectPort="9443" /><Engine name="Catalina" defaultHost="localhost" jvmRoute="b">vi /etc/init.d/tomcat2(修改如下内容)export CATALINA_HOME=//usr/local/tomcat2启动|关闭su - tomcat/etc/init.d/tomcat2 start|stop四、配置调度器nginxvi 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