系统为64位,centos5

1、下载,安装jdk,tomcat软件

mkdir /soft

cd /soft

wget http://download.oracle.com/otn-pub/java/jdk/6u32-b05/jdk-6u32-linux-x64.bin

wget http://tomcat.apache.org/download-70.cgi/apache-tomcat-7.0.27.tar.gz 

./jdk-6u32-linux-x64.bin

tar xvf  apache-tomcat-7.0.27.tar.gz 

mv jdk1.6.0_26/ /usr/local/jave/

mv apache-tomcat-7.0.27 /usr/local/tomcat

cd /usr/local/tomcat/

vim bin/catalina.sh

export JAVA_HOME="/usr/local/java"  //加在最后一行

/usr/local/tomcat/bin/startup.sh   //启动tomcat,正常的话可以看到tomcat界面

 

2、实现不同端口访问不同网站目录,修改配置文件

vim conf/server.xml   //改为以下配置

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
    <Service name="Catalina">
    <Connector port="9090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="9443" />
    <Connector port="9009" protocol="AJP/1.3" redirectPort="9443" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps2"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server> 

重启tomcat

/usr/local/tomcat/bin/shutdown.sh

/usr/local/tomcat/bin/startup.sh

 //在默认配置上增加了一个server name,只改了端口(我是全部加1了,另8080改为了9090,方便记)和路径(增加了一个webapps2,我是直接把webapps的内容复制到webapps2里面,如果是网站目录,直接放到这里面就可以访问了)。

3、测试

http://192.168.2.2:8080 访问的是webapps

http://192.168.2.2:9090 访问的是webapps2