Java is different from PHP, a single site update maintenance will affect other sites, will generally put several sites under one instance. Today's full name demonstrates how a single server configures multiple Tomcat instances.
Environment
tomcat:/usr/local/tomcat-7.0.50
A.ttlsa.com
Site Program:/data/site/a.ttlsa.com
Port: 8080
B.ttlsa.com
Site Program:/data/site/b.ttlsa.com
Port: 8081
1. Tomcat Installation
Installation is simple, configure the JDK and decompression Tomcat, about the Tomcat installation I will not repeat the side.
If the connection fails, please copy http://www.ttlsa.com/web/install-tomcat7-on-linux/
2. Configure multiple instance Directories
Create A.ttlsa.com, b.ttlsa.com under the Tomcat installation directory, and copy the Conf, logs, WebApp, temp, work directories to both directories, and then the Tomcat installation directory only needs to leave bin, a.ttlsa.com , B.ttlsa.com, lib these 4 directory can. The configured directory structure is as follows:
# pwd
/usr/local/tomcat-7.0.50
# tree-d-L 2
├──bin
├──a.ttlsa.com
│├──conf
│├──logs
│├──target
│├──temp
│├──webapp
│└──work
├──lib
└──b.ttlsa.com
├──conf
├──logs
├──temp
├──webapp
└──work
3. Configure site Server.xml
3.1 Configuration A.ttlsa.com
# Vim/usr/local/tomcat-7.0.50/a.ttlsa.com/conf/server.xml
Annotation AJP
<!--<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>-->
Server port 8005 changed to 8001
<server port= "8001" shutdown= "Shutdown" >
In <engine name= "Catalina" defaulthost= "localhost" > Add host Configuration, as follows
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "" docbase= "" reloadable= "true" >
<valve classname= "Org.apache.catalina.valves.RemoteAddrValve"/>
</Context>
</Host>
3.2 Configuration b.ttlsa.com
# Vim/usr/local/tomcat-7.0.50/a.ttlsa.com/conf/server.xml
Annotation AJP
<!--<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>-->
Server port 8005 changed to 8002
<server port= "8002" shutdown= "Shutdown" >
In <engine name= "Catalina" defaulthost= "localhost" > Add host Configuration, as follows
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "" docbase= "" reloadable= "true" >
<valve classname= "Org.apache.catalina.valves.RemoteAddrValve"/>
</Context>
</Host>
4. Multi-instance startup script
Create a startup script in the a.ttlsa.com, b.ttlsa.com directory, respectively tomcat.sh
4.1 Script Content Tomcat.sh
#!/bin/sh
# AuthName: Lang Baikai
# website:http://www.ttlsa.com
# datetime:2014-05-04
# Description: Start tomcat multiple instances.
. /etc/init.d/functions
Retval=$?
# Tomcat Instance Directory
Export catalina_base= "$PWD"
# Tomcat installation directory
Export Catalina_home= "/usr/local/tomcat-7.0.50"
# Optional
Export jvm_options= "-xms128m-xmx1024m-xx:permsize=128m-xx:maxpermsize=512m"
Case "$" in
Start
If [f $CATALINA _home/bin/startup.sh];then
echo $ "Start Tomcat"
$CATALINA _home/bin/startup.sh
Fi
;;
Stop
If [f $CATALINA _home/bin/shutdown.sh];then
echo $ "Stop Tomcat"
$CATALINA _home/bin/shutdown.sh
Fi
;;
*)
echo $ "Usage: $ {start|stop}"
Exit 1
;;
Esac
Exit $RETVAL
4.2 Boot Script Assignment permissions
# chmod A+x tomcat.sh
5. Start test
5.1 Start/Close a.ttlsa.com
Start
# cd/usr/local/tomcat-7.0.50/a.ttlsa.com/
#./tomcat.sh Start
Shut down
# cd/usr/local/tomcat-7.0.50/a.ttlsa.com/
#./tomcat.sh Stop
5.2 Start/Close b.ttlsa.com
Start
# cd/usr/local/tomcat-7.0.50/a.ttlsa.com/
#./tomcat.sh Start
Shut down
# cd/usr/local/tomcat-7.0.50/a.ttlsa.com/
#./tomcat.sh Stop
Note: The CD must be executed in the current directory of the tomcat.sh to
6. End
Configuration to this end, if you need to operate more than one instance of the trouble, you can write a unified script.