tc Server Webinar Series
Large Scale Tomcat
Large Scale Tomcat
Deployments
Filip Hanik
SpringSource
2009
2009
Agenda
• Basic Installation Prelude
• Basic Installation Prelude
• Flexible Directory Layout
• Configuration Templates
• Configuration Templates
• Environment variables
D
• Demos
– Installation
– Upgrade
Tomcat Folder Structure
Folder structure overview
Folder structure overview
apache-tomcat-6.0.x/ bi - bin - conf - lib - logs - temp - webapps - work
Tomcat Folder Structure
Folder structure overview
Folder structure overview
apache-tomcat-6.0.x/
bi d d i t t
- bin - used during startup - conf - CATALINA_BASE
- lib - CATALINA_HOME
- logs - logging.properties - temp - CATALINA_TMPDIR
- webapps – server.xml (<Host>) - work - server.xml (<Host>)
How Tomcat reads directories
• bin directory
y
– Only storage space for scripts and bootstrap libraries
– Never used during runtime
• All other directories are 'configurable'
There are some slight exceptions
– There are some slight exceptions
• We can take advantage of this
– Tomcat upgrades/downgrades
– JVM upgrades/downgrades
Starting up Tomcat
bin/
startup.(sh|bat)
shutdown.(sh|bat)
<start>
<stop>
Starting up Tomcat
catalina.(sh|bat)
setclasspath.(sh|bat)
setenv.(sh|bat)
<invokes>
<invokes>
Startup ScriptsJVM Launch
Setting custom options
z
setenv.sh - Any custom options here
sete
s
y custo
opt o s e e
zJAVA_HOME
zJAVA_OPTS
zCATALINA_OPTS
zCATALINA_HOME
zCATALINA BASE
_
zCATALINA_TMPDIR
zCATALINA_PID
•All these are read by catalina.sh
Setting Custom Options
z
setenv.sh doesn't ship with Tomcat
sete
s does t s p
t
o cat
zUpgrading Tomcat
z
Simply copy setenv.sh
z
No need to modify Tomcat scripts, or keep track
of changes inside Tomcat scripts
Up/Down-grading JVM
/development/tomcatx/example/ / p / / p / - apache-tomcat-6.0.18/ - apache-tomcat-6.0.20/ - jdk1.5.0_19/ jdk1 6 0 14/ - jdk1.6.0_14/ - myapplications zsetenv sh
zsetenv.sh
zJAVA_HOME points to 1.5 or 1.6
zEasy to switch back and forth
Easy to switch back and forth
Tomcat Folder Structure
/development/tomcatx/example/ / p / / p / - apache-tomcat-6.0.18/ - apache-tomcat-6.0.20/ - jdk1.5.0_19/ jdk1 6 0 14/ - jdk1.6.0_14/ - tomcat-instance-01/ - bin - conf - logs - webapps - work - temptempSo far
setenv.sh
sete
s
CATALINA_HOME=/usr/local/apache-tomcat-6.0.18 CATALINA BASE=/usr/local/tomcat instance 01 CATALINA_BASE=/usr/local/tomcat-instance-01 JAVA_HOME=/usr/local/jdk1.6.0_14
CATALINA_PID=$CATALINA_BASE/logs/tomcat.pid
Modify JAVA_HOME to change JVM
Tomcat upgrades
• Most important thing during a production
ost
po ta t t
g du
g a p oduct o
upgrade:
– How to downgrade/roll back if something goes wrong
• With Tomcat, that's easy, keep multiple
installations
• With JVM, that's easy, keep multiple
installations
Going further
• So far
So a
– Understanding setenv.sh
– Understanding file/directory structure
• Lets take it to the next step
• Lets create a setup that will make all this seem
so much more intuitive
Creating the layout
apache-tomcat-6.0.x/
* A l T t i t ll
* A regular Tomcat install
run.sh
* Control script
shared/
* Shared instance data
instance_1/
* An instance of a Tomcat server
instance 2/ instance_2/ instance_n/
Creating the layout
shared/ f/ - conf/ logging.properties server.xml tomcat-users.xml - logs/Creating the layout
instance_1/ bi / - bin/
setenv.sh * Instance specific JVM options
- conf/ * Instances configuration
catalina.properties
- logs/ * catalina.out goes here
- webapps/ * Instance applications
- work/ * Instance work directory
Creating the layout
instance_2/ bi / - bin/
setenv.sh * Instance specific JVM options
- conf/ * Instances configuration
catalina.properties
server.xml * non shared config
- logs/ * catalina.out goes here
- webapps/ * Instance applications
- work/work/ * Instance work directory Instance work directory
Configuration
shared/conf/server.xml
<Server port="${shutdown.port}" shutdown="SHUTDOWN">
<Connector port="${http.port}" protocol="HTTP/1.1"
connectionTimeout="20000" /> run.sh
Configuration
instance_1/conf/catalina.properties
shutdown.port=8005 http.port=8080
* Anything in here gets read into System.getProperties(...)
Configuration
shared/conf/logging.properties 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/../shared/logs 1catalina.org.apache.juli.FileHandler.prefix =${catalina instance} catalina
${catalina.instance}.catalina.
* Single configuration file
Configuration
instane_1/bin/setenv.sh
CATALINA_OPTS=”-Xmx512m -Xss192k”
The Script
• run.sh
u s
– The script that does it all
– Takes advantage of configuration options in Tomcat
– Creates a simple, flexible and yet powerful layout
structure
– Provides ability to switch JVM and Tomcat versions
without changing any configuration
tc Server
• tc Server
tc Se e
– Tomcat on steroids
– 100% application compatibility with Apache Tomcat
– Leverages Apache Tomcat layout features
tc Server
• Installation
sta at o
– Same concept – unzip and run
– Comes with a command line installer
– Or a zip file in format for .sfx.jar
#Platform independent installp
>java -jar tcServer-6.0.20.A.sfx.jar >ls
tcServer 6 0 20 tcServer-6.0.20
tc Server
• Folder Layout
o de
ayout
– Same concept – binaries and instances
#Platform independent install
>ls tcServer-6.0.20
instance1 instance3 instance2 tcserver-ctl sh tcserver-ctl bat tcserver ctl.sh tcserver ctl.bat
tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.A tomcat-6.0.19.A t t 6 0 20 A tomcat-6.0.20.A tijars
tc Server
• Folder Layout
o de
ayout
– Binaries – always complete versions of Tomcat
#Platform independent install
>ls tcServer-6.0.20
instance1 instance3 instance2 tcserver-ctl sh tcserver-ctl bat tcserver ctl.sh tcserver ctl.bat
tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.A tomcat-6.0.19.A t t 6 0 20 A tomcat-6.0.20.A tijars
tc Server
• Folder Layout
o de
ayout
– Multiple instances
#Platform independent install
>ls tcServer-6.0.20
instance1 instance3 instance2 tcserver-ctl sh tcserver-ctl bat tcserver ctl.sh tcserver ctl.bat
tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.A tomcat-6.0.19.A t t 6 0 20 A tomcat-6.0.20.A tijars
tc Server
• Folder Layout
o de
ayout
– Creating instances
#Platform independent install
>ls tcServer-6.0.20
instance1 instance3 instance2 tcserver-ctl sh tcserver-ctl bat tcserver ctl.sh tcserver ctl.bat
tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.A tomcat-6.0.19.A t t 6 0 20 A tomcat-6.0.20.A tijars
tc Server
• Folder Layout
o de
ayout
– Controlling run time instances
#Platform independent install
>ls tcServer-6.0.20
instance1 instance3 instance2 tcserver-ctl sh tcserver-ctl bat tcserver ctl.sh tcserver ctl.bat
tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.A tomcat-6.0.19.A t t 6 0 20 A tomcat-6.0.20.A tijars
tc Server
• Folder Layout
o de
ayout
Summary
• Large scale deployments are possible
a ge sca e dep oy e ts a e poss b e
• Can be very large
– Our customers have thousands of managed instances
• Tomcat doesn't provide the infrastructure
Tomcat doesn t provide the infrastructure
– Provides flexibility no other container does
– Automate your own environment
tc Server
• Summary
Su
a y
– Script based so it can be automated
– Unix looks like Windows
E t f i d i il
• Except wrapper.conf cause windows is evil • But wrapper.conf is file based, not registry
– Upgrade/downgrade/copy
• Everything you need
– Useful for both developers and operations
• I create instances to test different configurations I create instances to test different configurations • Always have a record of my tested configs
SpringOne Americas 2009
www.springone2gx.com
Americas 2009
• Premier Java Event of 2009
• Keynote by Rod Johnson, Adrian Colyer • Technical Sessions Case Studies Best
Americas 2009
• Technical Sessions, Case Studies, BestPractices, Hands-on Code Examples, Cutting-Edge Tools
• Session covering:
• Spring technologies • Groovy & Grails
• Hyperic Management Tools
• Apache Projects like Tomcat, httpd and ActiveMQ