tc Server Webinar Series Large Scale Tomcat Deployments Filip Hanik SpringSource 2009 Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Agenda Basic Installation Prelude Flexible Directory Layout Configuration Templates Environment variables Demos Installation Upgrade Create a test instance from template 2
Tomcat Folder Structure Folder structure overview apache-tomcat-6.0.x/ - bin - conf - lib - logs - temp - webapps - work 3
Tomcat Folder Structure Folder structure overview apache-tomcat-6.0.x/ - bin - used during startup t - conf - CATALINA_BASE - lib - CATALINA_HOME - logs - logging.properties - temp - CATALINA_TMPDIR - webapps server.xml (<Host>) - work - server.xml (<Host>) 4
How Tomcat reads directories bin directory Only storage space for scripts and bootstrap libraries Never used during runtime All other directories are 'configurable' There are some slight exceptions We can take advantage of this Tomcat upgrades/downgrades JVM upgrades/downgrades 5
Starting up Tomcat bin/ startup.(sh bat) shutdown.(sh bat) <start> <stop> catalina.(sh bat) Startup Scripts 6
Starting up Tomcat catalina.(sh bat) <invokes> <invokes> setclasspath.(sh bat) setenv.(sh bat) JVM Launch Startup Scripts 7
Setting custom options setenv.sh s - Any ycustom options opto here ee JAVA_HOME JAVA_OPTS CATALINA_OPTS CATALINA_HOME CATALINA_ BASE CATALINA_TMPDIR CATALINA_PID All these are read by catalina.sh If no value exists, defaults are assigned 8
Setting Custom Options setenv.sh s doesn't ship with Tomcat Upgrading Tomcat Simply copy setenv.sh No need to modify Tomcat scripts, or keep track of changes inside Tomcat scripts 9
Up/Down-grading JVM setenv.sh sh /development/tomcatx/example/ / / p / - apache-tomcat-6.0.18/ - apache-tomcat-6.0.20/ - jdk1.5.0_19/ - jdk1.6.0_14/ 14/ - myapplications JAVA_HOME points to 1.5 or 1.6 Easy to switch back and forth No need to modify any Tomcat scripts 10
Tomcat Folder Structure /development/tomcatx/example/ / / p / - apache-tomcat-6.0.18/ - apache-tomcat-6.0.20/ - jdk1.5.0_19/ - jdk1.6.0_14/ 14/ - tomcat-instance-01/ - bin - conf - logs - webapps - work - temp Instance data can be separated out 11
So far setenv.sh s CATALINA_HOME=/usr/local/apache-tomcat-6.0.18 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 Modify CATALINA_HOME to change Tomcat 12
Tomcat upgrades Most important t thing during a production 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 13
Going further So far 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 14
Creating the layout apache-tomcat-6.0.x/ * A regular Tomcat install run.sh * Control script shared/ * Shared instance data instance_1/ * An instance of a Tomcat server instance_2/ instance_n/ 15
Creating the layout shared/ - conf/ logging.properties server.xml tomcat-users.xml - logs/ * Instances can share configuration files! 16
Creating the layout instance_1/ - bin/ setenv.sh * Instance specific JVM options - conf/ * Instances configuration catalina.properties - logs/ * catalina.out goes here - webapps/ * Instance applications - work/ * Instance work directory - temp/ * Instance temp directory 17
Creating the layout instance_2/ - 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/ * Instance work directory - temp/ * Instance temp directory 18
Configuration shared/conf/server.xml <Server port="${shutdown.port}" shutdown="shutdown"> <Connector port="${http.port}" protocol="http/1.1" connectiontimeout="20000" /> run.sh * uses -config to denote configuration file 19
Configuration instance_1/conf/catalina.properties shutdown.port=8005 http.port=8080 * Anything in here gets read into System.getProperties(...) * Useful for application options -Dxxx=yyy 20
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. instance} * Single configuration file Unique log files per instance 21
Configuration instane_1/bin/setenv.sh CATALINA_OPTS= -Xmx512m -Xss192k * Unique JVM options per instance 22
The Script run.sh 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 23
tc Server tc Server e Tomcat on steroids 100% application compatibility with Apache Tomcat Leverages Apache Tomcat layout features Built in management/monitoring 24
tc Server Installation at Same concept unzip and run Comes with a command line installer Or a zip file in format for.sfx.jar #Platform independent install >java -jar tcserver-6.0.20.a.sfx.jar >ls tcserver-6.0.20 25
tc Server Folder ode Layout Same concept binaries and instances #Platform independent install >ls tcserver-6.0.20 instance1 instance3 instance2 tcserver-ctl ctl.sh tcserver-ctl.bat tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.a tomcat-6.0.19.a tomcat-6.0.20.at tijars 26
tc Server Folder ode Layout Binaries always complete versions of Tomcat #Platform independent install >ls tcserver-6.0.20 instance1 instance3 instance2 tcserver-ctl ctl.sh tcserver-ctl.bat tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.a tomcat-6.0.19.a tomcat-6.0.20.at tijars 27
tc Server Folder ode Layout Multiple instances #Platform independent install >ls tcserver-6.0.20 instance1 instance3 instance2 tcserver-ctl ctl.sh tcserver-ctl.bat tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.a tomcat-6.0.19.a tomcat-6.0.20.at tijars 28
tc Server Folder ode Layout Creating instances #Platform independent install >ls tcserver-6.0.20 instance1 instance3 instance2 tcserver-ctl ctl.sh tcserver-ctl.bat tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.a tomcat-6.0.19.a tomcat-6.0.20.at tijars 29
tc Server Folder ode Layout Controlling run time instances #Platform independent install >ls tcserver-6.0.20 instance1 instance3 instance2 tcserver-ctl ctl.sh tcserver-ctl.bat tcserver-instance.sh tcserver-instance.bat tomcat-6.0.18.a tomcat-6.0.19.a tomcat-6.0.20.at tijars 30
tc Server Folder ode Layout And it gets better, lets do some demos 31
Summary Large agescaedepoy scale deployments e tsaepossbe are possible Can be very large Our customers have thousands of managed instances Tomcat doesn't provide the infrastructure Provides flexibility no other container does Automate your own environment 32
tc Server Summary Script based so it can be automated Unix looks like Windows 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 Always have a record of my tested configs 33
SpringOne Americas 2009 www.springone2gx.com Premier Java Event of 2009 Keynote by Rod Johnson, Adrian Colyer Technical Sessions, Case Studies, Best Practices, Hands-on Code Examples, Cutting- Edge Tools Americas 2009 Session covering: Spring technologies Groovy & Grails Hyperic Management Tools Apache Projects like Tomcat, httpd and ActiveMQ Get the skills and knowledge you need to help you build, run and manage software solutions 34