安装tomcat
1. 查看系统版本
[root@test src]# uname -a Linux test.server02 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
2.下载tomcat7和jdk1.6
[root@test src]# ls apache-tomcat-7.0.55.tar.gz jdk1.6.0_22.tgz
3.安装JDK配置java环境
[root@test src]# tar zxvf jdk1.6.0_22.tgz [root@test src]# ln -svf /usr/local/src/jdk1.6.0_22 /usr/local/jdk1.6.0_22 `/usr/local/jdk1.6.0_22' -> `/usr/local/src/jdk1.6.0_22' [root@test src]# vim ~/.bash_profile export JAVA_HOME=/usr/local/jdk1.6.0_22 export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar [root@test src]# source ~/.bash_profile [root@test src]# 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)
4.安装并启动tomcat
[root@test src]# tar zxvf apache-tomcat-7.0.55.tar.gz [root@test src]# ln -svf /usr/local/src/apache-tomcat-7.0.55 /usr/local/apache-tomcat-7.0.55 `/usr/local/apache-tomcat-7.0.55' -> `/usr/local/src/apache-tomcat-7.0.55' [root@test src]# vim ~/.bash_profile export CATALINA_HOME=/usr/local/apache-tomcat-7.0.55 [root@test ~]# /usr/local/apache-tomcat-7.0.55/bin/startup.sh Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.55 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.55 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.55/temp Using JRE_HOME: /usr/local/jdk1.6.0_22 Using CLASSPATH: /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar Tomcat started. [root@test ~]# ps -ef | grep java root 4460 1 52 19:21 pts/1 00:00:05 /usr/local/jdk1.6.0_22/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.55/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.55/endorsed -classpath /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.55 -Dcatalina.home=/usr/local/apache-tomcat-7.0.55 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.55/temp org.apache.catalina.startup.Bootstrap start root 4480 4028 0 19:22 pts/1 00:00:00 grep java
5.测试
配置单机多实例
1. 配置多实例目录
tomcat:/usr/local/apache-tomcat-7.0.55
a.tomcat-node1.com
站点程序:/data/site/a.tomcat-node1.com
端口:8180
b.tomcat-node2.com
站点程序:/data/site/a.tomcat-node1.com
端口:8280
在tomcat安装目录下创建tomcat-node1、tomcat-node2,并且将conf、logs、webapp、temp、work目录拷贝到 这两个目录,然后tomcat安装目录只需要留下bin、tomcat-node1、tomcat-node2、lib这4个目录即可。
[root@test apache-tomcat-7.0.55]# ls bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work [root@test apache-tomcat-7.0.55]# mkdir tomcat-node1 [root@test apache-tomcat-7.0.55]# mkdir tomcat-node2 [root@test apache-tomcat-7.0.55]# ls tomcat-node2 tomcat-node2 lib logs RELEASE-NOTES temp work bin conf LICENSE NOTICE RUNNING.txt webapps [root@test apache-tomcat-7.0.55]# cp -rvf {conf,logs,webapps,temp,work} tomcat-node2/ [root@test apache-tomcat-7.0.55]# cp -rvf {conf,logs,webapps,temp,work} tomcat-node1/
目录结构:
[root@test ~]# tree /usr/local/apache-tomcat-7.0.55/ -d -L 2 /usr/local/apache-tomcat-7.0.55/ ├── bin ├── lib ├── tomcat-node1 │ ├── conf │ ├── logs │ ├── temp │ ├── webapps │ └── work └── tomcat-node2 ├── conf ├── logs ├── temp ├── webapps └── work
2.配置站点server.xml
2.1 a.tomcat-node1.com
[root@test ~]# vim /usr/local/apache-tomcat-7.0.55/tomcat-node1/conf/server.xml //注释ajp <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> //server端口8005改为8001 <Server port="8001" shutdown="SHUTDOWN"> //在<Engine name="Catalina" defaultHost="localhost">增加host配置,如下 <Host name="a.ttlsa.com" appBase="/data/site/a.ttlsa.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="" reloadable="true"> <valve className="org.apache.catalina.valves.RemoteAddrValve" /> </Context> </Host>
2.2 b.tomcat-node2.com
[root@test ~]# vim /usr/local/apache-tomcat-7.0.55/tomcat-node2/conf/server.xml //注释ajp <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> //server端口8005改为8002 <Server port="8002" shutdown="SHUTDOWN"> //在<Engine name="Catalina" defaultHost="localhost">增加host配置,如下 <Host name="b.ttlsa.com" appBase="/data/site/b.ttlsa.com" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="" reloadable="true"> <valve className="org.apache.catalina.valves.RemoteAddrValve" /> </Context> </Host>
3.启动各实例
root@test tomcat-node1]# export CATALINA_BASE=$CATALINA_HOME/tomcat-node1 [root@test tomcat-node1]# sh $CATALINA_HOME/bin/startup.sh -Dcatalina.base Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.55/tomcat-node1 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.55 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.55/tomcat-node1/temp Using JRE_HOME: /usr/local/jdk1.6.0_22 Using CLASSPATH: /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar Tomcat started. [root@test tomcat-node1]# export CATALINA_BASE=$CATALINA_HOME/tomcat-node2 [root@test tomcat-node1]# sh $CATALINA_HOME/bin/startup.sh -Dcatalina.base Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.55/tomcat-node2 Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.55 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.55/tomcat-node2/temp Using JRE_HOME: /usr/local/jdk1.6.0_22 Using CLASSPATH: /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar Tomcat started. [root@test tomcat-node1]# ps -ef | grep java root 7861 1 8 22:39 pts/1 00:00:06 /usr/local/jdk1.6.0_22/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.55/tomcat-node1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.55/endorsed -classpath /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.55/tomcat-node1 -Dcatalina.home=/usr/local/apache-tomcat-7.0.55 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.55/tomcat-node1/temp org.apache.catalina.startup.Bootstrap -Dcatalina.base start root 7908 1 51 22:40 pts/1 00:00:03 /usr/local/jdk1.6.0_22/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.55/tomcat-node2/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.55/endorsed -classpath /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.55/tomcat-node2 -Dcatalina.home=/usr/local/apache-tomcat-7.0.55 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.55/tomcat-node2/temp org.apache.catalina.startup.Bootstrap -Dcatalina.base start root 7922 7536 0 22:40 pts/1 00:00:00 grep java [root@test ~]# ps -ef | grep java | grep -v "grep" root 9084 1 0 00:10 pts/0 00:00:09 /usr/local/jdk1.6.0_22/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.55/tomcat-node2/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.55/endorsed -classpath /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.55/tomcat-node2 -Dcatalina.home=/usr/local/apache-tomcat-7.0.55 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.55/tomcat-node2/temp org.apache.catalina.startup.Bootstrap -Dcatalina.base start root 9109 1 0 00:10 pts/0 00:00:08 /usr/local/jdk1.6.0_22/bin/java -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.55/tomcat-node1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.55/endorsed -classpath /usr/local/apache-tomcat-7.0.55/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.55/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/apache-tomcat-7.0.55/tomcat-node1 -Dcatalina.home=/usr/local/apache-tomcat-7.0.55 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.55/tomcat-node1/temp org.apache.catalina.startup.Bootstrap -Dcatalina.base start
访问测试:
node1节点
node2节点