Upload
pascal-louis
View
216
Download
0
Embed Size (px)
Citation preview
8/12/2019 Tomcat Admin Electronic Handouts
1/653
2010 SpringSource, A division of VMware. All rights reserved
Introduction to Tomcat 6
8/12/2019 Tomcat Admin Electronic Handouts
2/653
22
Topics in this Session
What is Tomcat?
History
Tomcat Versions
Development Life Cycle
Release rocess
8/12/2019 Tomcat Admin Electronic Handouts
3/653
33
What is Tomcat?
!n open source servlet container
Implements Java Servlet and Java Server Pages specifications
Pure Java HTTP web server environment for Java code to run
"m#edded in many $ava "" application servers
JBoss, Geronimo, ebsp!ere"""
!pache Soft%are &oundation
Top #evel Pro$ect
Community effort
%& core developers from various companies
SpringSource '()ware*, JBoss '+ed!at*"""
8/12/2019 Tomcat Admin Electronic Handouts
4/653
Tomcat community
In avera'e ( release)month
(*+++*+++, do%nloads)month
Including mirrors
8/12/2019 Tomcat Admin Electronic Handouts
5/653
--
!pache Soft%are &oundation
-on.profit corporation
Based in t!e .S
rovides a #asis for open* colla#orative soft%are development
/any famous pro0ects
/pac!e eb Server '!ttpd*, tomcat, /nt, )aven, #ogJ, Struts % 0 2"""
!ll soft%are is released under the !pache License
version 2"&
!ttp1www"apac!e"org
8/12/2019 Tomcat Admin Electronic Handouts
6/653
History
Started out as a reference implementation #y Sun /icrosystems
1no% 2racle3
Donated to !S& 4 Tomcat 5 1rou'hly (3
Tomcat 7
4irst rewrite 5 6odename 6atalina
Tomcat 89+ 1:++:3
+educed garbage collection, improved performance and scalabilit7
4aster JSP parsing
8/12/2019 Tomcat Admin Electronic Handouts
7/653
88
History
Tomcat 898 1:++73
Second rewrite 5 performance
Tomcat 69+ 1:++63
4arm deplo7ment
Tomcat ;9+ 1:+(+3
4eatures
9 Simplified :mbedding
9 )emor7 #ea; Prevention and 2&%%
9 T!is course focuses on Tomcat "& and introduces t!e new concepts from Tomcat 8"&
8/12/2019 Tomcat Admin Electronic Handouts
8/653
??
Versions
Tomcatversion
Servlet $S $D< version
8"&"= 3"& 2"2 J
8/12/2019 Tomcat Admin Electronic Handouts
9/653
CC
Development Life Cycle
Development mainly driven #y
JS+ Specifications
9 Servlet
9 JSP
9 :=pression #anguage
6ompetitor features
6ommitter ideas
.ser ideas
8/12/2019 Tomcat Admin Electronic Handouts
10/653
%&%&
Development Life Cycle
/ost committers are sponsored #y their employer to %or= on
Tomcat
Some committers are independent* %or=in' on Tomcat in their o%ntime
Committers are e>pected to put the interests of the pro0ect #efore
the interests of their employers and)or clients
+eferred to as Dwearing t!eir /S4 !atE :mplo7ers understand and respect t!is
8/12/2019 Tomcat Admin Electronic Handouts
11/653
%%%%
Development Life Cycle
Commit.Then.Revie%
%Es to appl7 t!e patc! to t!e repositor7
8/12/2019 Tomcat Admin Electronic Handouts
12/653
%2%2
Development Life Cycle
Rarely are time lines for features discussed
Lar'er chan'es are discussed on mailin' list until consensus has
#een reached
Very fe% commits directly on a release #ranch
fi=ing a bro;en build
legal 'usuall7 licensing* issues
8/12/2019 Tomcat Admin Electronic Handouts
13/653
%3%3
Release process
!vera'e ( release per month
/cross all versions
Release schedule %hen
Denoug!E !as been done
Important securit7 issues are discovered and fi=ed
8/12/2019 Tomcat Admin Electronic Handouts
14/653
%%
Release process
What dictates sta#le@ release
/ll T6@ tests pass '*
9 /round %&&& test cases
6andidate binaries !ave been tested b7 communit7 in various environments and
feedbac; !as been received
3= A% votes during a stabilit7 vote
'* T6@1 Tec!nolog7 6ompatibilit7 @itsuite of tests t!at c!ec;s implementation of a Java Specification+eFuest for compliance
8/12/2019 Tomcat Admin Electronic Handouts
15/653
%-%-
Summary
What is Tomcat?
History
Tomcat Versions
Development Life Cycle
Release rocess
8/12/2019 Tomcat Admin Electronic Handouts
16/653
%%
Auestions?
8/12/2019 Tomcat Admin Electronic Handouts
17/653
11
Installing Apache TomcatInstalling an ASF Distribution of Apache Tomcat
8/12/2019 Tomcat Admin Electronic Handouts
18/653
22
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download?
inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
8/12/2019 Tomcat Admin Electronic Handouts
19/653
,,
Downloading Tomcat
Tomcatversion
Link
-./.0 http%%tomcat.apache.org%download-/.cgi
3./.0 http%%tomcat.apache.org%download3/.cgi
4.4.0 http%%tomcat.apache.org%download44.cgi
http://tomcat.apache.org/download-70.cgihttp://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/download-55.cgihttp://tomcat.apache.org/download-55.cgihttp://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/download-70.cgi8/12/2019 Tomcat Admin Electronic Handouts
20/653
55
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download?
inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
8/12/2019 Tomcat Admin Electronic Handouts
21/653
44
Different distributions for different platforms
.tar.gz
A+ailable for 6ni0 systems
7eware of faulty tar on old Solaris systems
.zip
A+ailable for any systems where tar is not a+ailable
tar doesn8t wor9 well on Windows :long file paths;
Doesn8t maintain file permissions
.ee
Windows installer < not recommended
Scripts such as startup.bat are currently not included
=ot customi>able
8/12/2019 Tomcat Admin Electronic Handouts
22/653
33
Topics in this Session
Downloading Tomcat
Distribution Types
!hich Download"
inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
8/12/2019 Tomcat Admin Electronic Handouts
23/653
--
!hich Download"
Tomcat # has reduced the downloads
4.4 and older had separate downloads for different components
3./ only has core and deployer downloads
core download package
ontains e+erything you need
For production systems@ remo+e sample web applications
!emo+e manager%hostmanager if not needed
8/12/2019 Tomcat Admin Electronic Handouts
24/653
!hich Download"
deployer download package
ontains A=T scripts and libraries to script remote application deployment and
remote start%stop
$revious versions
&+en installing an older +ersion@ use core download
8/12/2019 Tomcat Admin Electronic Handouts
25/653
BB
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download? %inimum &e'uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
8/12/2019 Tomcat Admin Electronic Handouts
26/653
1/1/
%inimum &e'uirements
Tomcat # re'uires
(D)*(&+ ,.-
6se the latest #a+a 4%3 from your preferred +endor
1.4 re"uirement comes from Ser+let Spec
an8t run on 1.5 or older
(D) or (&+
Tomcat wor9s with either
Cre+iously re"uired a #D$ for #SC compilation
=ow uses the &clipse compiler which wor9s with a #D$ or a #!&
&ecommendation/ 0se the (D)
ontains useful tools that are omitted in the #!&
8/12/2019 Tomcat Admin Electronic Handouts
27/653
1111
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download? inimum !e"uirements
(D)*(&+ Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
8/12/2019 Tomcat Admin Electronic Handouts
28/653
1212
(D)*(&+ Installation
(D)*(&+ usually comes in two forms
Self e0tracting files < 6ni0
*S pac9ages < 6ni0
Windows Installer Windows
Self etracting files
!ecommended to use
7ecomes portable right after installation
1S packages
omes in *S specific form such as
rpm@ fin9@ deb@ p9gadd
8/12/2019 Tomcat Admin Electronic Handouts
29/653
1,1,
(D)*(&+ Installation
!indows Installer
an install both #!& and #D$
reates registry entries
#D$ installation location can be selected
8/12/2019 Tomcat Admin Electronic Handouts
30/653
1515
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download? inimum !e"uirements
#D$%#!& Installation
(A2A341%+ vs (&+341%+"
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
(A2A 41%+ (&+ 41%+"
8/12/2019 Tomcat Admin Electronic Handouts
31/653
1414
(A2A341%+ vs (&+341%+"
Tomcat can use both
First chec9s if #A'A()*& is set
If not set@ then chec9s #!&()*&
If neither is found@ e0its
(A2A341%+ re'uired if running with debugging capabilities 56db7
&ecommended/ (A2A341%+
Implies that it points to a #D$ installation
Tools li9e stac9@ map@ console etc
8/12/2019 Tomcat Admin Electronic Handouts
32/653
1313
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download? inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
T t I t ll ti
8/12/2019 Tomcat Admin Electronic Handouts
33/653
1-1-
Tomcat Installation
8ased on .tar.gz or .zip distributions
!ecommended o+er Win installer or 6ni0 pac9ages
While installers and pac9ages are nice@ they create in+isible problems :registryentries etc;
Installation is simple99
Download apachetomcat3./.0.>ip
6n>ip it DoneE
T t I t ll ti
8/12/2019 Tomcat Admin Electronic Handouts
34/653
11
Tomcat Installation
8ased on .tar.gz or .zip distributions
!ecommended o+er Win installer or 6ni0 pac9ages
While installers and pac9ages are nice@ they create in+isible problems :registryentries etc;
Installation is simple99
Download apachetomcat3./.0.>ip
6n>ip it DoneE
Is it really that simple"
T t I t ll ti
8/12/2019 Tomcat Admin Electronic Handouts
35/653
1B1B
apache:tomcat:#.;.*: bin: conf
: lib: logs: temp: webapps: work
Tomcat Installation
8/12/2019 Tomcat Admin Electronic Handouts
36/653
2/2/
Tomcat Installation
$ortable"
esE the Tomcat installation is portable@ e+en across platforms
&+en after configuration changes@ ust >ip bac9 up and redistribute
Gi9ewise@ the #D$ distribution can be >ipped and used as a portable copy
H This portable copy would wor9 only on the same platform
8ase directory
Tomcat bases e+erything on the apachetomcat3./.0 directory
The name of the directory is not important
H m+ apachetomcat3./.0 mytomcat will wor9 ust fine
Two properties set
H catalina.home
H catalina.base
H 7oth point to the base directory
8/12/2019 Tomcat Admin Electronic Handouts
37/653
2121
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download?
inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Ser+ice
Starting up Tomcat
8/12/2019 Tomcat Admin Electronic Handouts
38/653
2222
Startup Scripts
Starting up Tomcat
JstartK JstopK
bin*
catalina.5sh=bat7
startup.:shLbat; shutdown.:shLbat;
Starting up Tomcat
8/12/2019 Tomcat Admin Electronic Handouts
39/653
2,2,
Startup Scripts
Starting up Tomcat
Jin+o9esK Jin+o9esK
catalina.5sh=bat7
(2% Launch
setclasspath.:shLbat; seten+.:shLbat;
setenv 5sh=bat7
8/12/2019 Tomcat Admin Electronic Handouts
40/653
2525
setATAGI=A(*CTSMNm0412m
8/12/2019 Tomcat Admin Electronic Handouts
41/653
2424
setclasspath.5sh=bat7
This is a +ery old script
6sed to set classpath
Today its used to
'alidate #A'A()*& or #!&()*&
Depending on which is set
Starting up Tomcat
8/12/2019 Tomcat Admin Electronic Handouts
42/653
2323
Starting up Tomcat
Demo
>ind out launch command for (2%
opy catalina.bat script to test.bat
Input a QechoQ command in front of launch
+ecute ? test.bat run
Analyze (2% launch command
Starting up Tomcat
8/12/2019 Tomcat Admin Electronic Handouts
43/653
2-2-
a+a Nm0412m Nms12m NNa0CermSi>eM12m Da+a.util.logging.managerMorg.apache.uli.lassGoaderGoganager
Da+a.util.logging.config.fileMRtmpRmytomcat3./.0RconfRlogging.properties
Da+a.endorsed.dirsMRtmpRmytomcat3./.0Rendorsedclasspath RtmpRmytomcat3./.0RbinRbootstrap.arDcatalina.baseMRtmpRmytomcat3./.0Dcatalina.homeMRtmpRmytomcat3./.0Da+a.io.tmpdirMRtmpRmytomcat3./.0Rtemporg.apache.catalina.startup.7ootstrap start
Starting up Tomcat
Tomcat launch command
CATALINA_OPTS
JAVA Application
8/12/2019 Tomcat Admin Electronic Handouts
44/653
22
Topics in this Session
Downloading Tomcat
Distribution Types
Which Download?
inimum !e"uirements
#D$%#!& Installation
#A'A()*& +s #!&()*&?
Tomcat Installation
Starting up Tomcat
Tomcat as a Service
Service !rapper
8/12/2019 Tomcat Admin Electronic Handouts
45/653
2B2B
Service !rapper
(ust another program * eecutable
+nables other programs to be installed and run in the background
1ften started automatically at boot time
&un as Windows Servicesor Unix Daemons
Tomcat as a Service
8/12/2019 Tomcat Admin Electronic Handouts
46/653
,/,/
Tomcat as a Service
Default Tomcat Service !rapper
6ses Apache ommons Daemon
1n !indows
bin%ser+ice.bat installLuninstall s+cname
opy tomcat3w.e0e to s+cnameW.e0e
@onfigure
bin%s+cnameW.e0e
!indows/ Tomcat as a Service
8/12/2019 Tomcat Admin Electronic Handouts
47/653
,1,1
!indows/ Tomcat as a Service
&ecommended to run as a service in production
(ava Service !rapper
Alternati+e to the default Tomcat Ser+ice wrapper
Setup similar to seten+.bat@ but in a wrapper.conf file
http%%people.apache.org%fhani9%wrapper.html
$ortable"
es@ all that is re"uired is the installation of the Ser+ice@ once copied to anothermachine
That can be scripted
Debuggable"
es@ contains batch file that simulates ser+ice startup
0ni/ Tomcat as a Daemon
http://people.apache.org/~fhanik/wrapper.htmlhttp://people.apache.org/~fhanik/wrapper.html8/12/2019 Tomcat Admin Electronic Handouts
48/653
,2,2
0ni/ Tomcat as a Daemon
&uns as a background process
reate your own scripts that wrap
H startup.shH shutdown.sh
H catalina.sh
Depending on system@ create scripts for start on boot
$ortable"
Any scripts you create can be copied as well@ they are ust scripts
Debuggable"
es@ it8s ust a shell script
8/12/2019 Tomcat Admin Electronic Handouts
49/653
,,,,
Labs
8/12/2019 Tomcat Admin Electronic Handouts
50/653
,5,5
Advanced
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
51/653
,4,4
0ni/ Tomcat as a Daemon Advanced scripts
&uns on top of the shell scripts in @ATALIBA341%+*bin
Supplied linu0etcinitdtomcat.sh
opy linu0etcinitdtomcat.sh to %etc%init.d
!ename linu0etcinitdtomcat.sh to apachetomcat.sh
The following three slides illustrate apachetomcat.sh
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
52/653
,3,3
0ni/ Tomcat as a Daemon Advanced scripts
C9*bin*sh
C Apache Tomcat start*stop Daemon
C chkconfig/ EF- G; ;
C description/ +nable service provided by Apache Tomcat daemon.
CCC 8+HIB IBIT IB>1C $rovides/ apache:tomcat
C &e'uired:Start/ local3fs
C &e'uired:Stop/ local3fs
C Default:Start/ E F -
C Default:Stop/ ; , #
C Short:Description/ Start*Stop Apache Tomcat daemon.
C Description/ +nable service provided by Apache Tomcat daemon.
CCC +BD IBIT IB>1
C9*bin*sh
C Apache Tomcat start*stop Daemon
C chkconfig/ EF- G; ;
C description/ +nable service provided by Apache Tomcat daemon.
CCC 8+HIB IBIT IB>1C $rovides/ apache:tomcat
C &e'uired:Start/ local3fs
C &e'uired:Stop/ local3fs
C Default:Start/ E F -
C Default:Stop/ ; , #
C Short:Description/ Start*Stop Apache Tomcat daemon.
C Description/ +nable service provided by Apache Tomcat daemon.
CCC +BD IBIT IB>1
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
53/653
,-,-
0ni/ Tomcat as a Daemon Advanced scripts
T1%@AT30S+&tomcat
S@&I$T3BA%+apache:tomcat
eport @ATALIBA341%+J*usr*local*tomcatJeport @ATALIBA38AS+J*usr*local*tomcatJ
eport (A2A341%+J*usr*local*6avaJ
eport S0J*bin*suJ
C D1 B1T +DIT 8+
8/12/2019 Tomcat Admin Electronic Handouts
54/653
,,
0 o cat as a ae o d a ced sc pts
status57 K
if N :e J@ATALIBA3$IDJ O then
echo J&unningJ
else
echo JBot runningJ
fi
M
status57 K
if N :e J@ATALIBA3$IDJ O then
echo J&unningJ
else
echo JBot runningJ
fi
M
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
55/653
,B,B
p
stop57 K
echo :n JStopping S@&I$T3BA%+ ...J
shutdown3portPgrep shutdown @ATALIBA341%+*conf*server.ml Q
= awk RKprint substr57MRP
if N shutdown3port 9 J:,J O then
S0 T1%@AT30S+& @ATALIBA341%+*bin*shutdown.sh
else
T1%@AT3$IDPps :ef = grep 6ava = grep @ATALIBA341%+ Q
= awk RKprint MRP kill :U T1%@AT3$ID
rm :rf @ATALIBA3$ID
fi
C &emove lock for &ed4at * SuS+
if test :w *var*lock*subsys
then
rm :rf *var*lock*subsys*S@&I$T3BA%+
fi
M
stop57 K
echo :n JStopping S@&I$T3BA%+ ...J
shutdown3portPgrep shutdown @ATALIBA341%+*conf*server.ml Q
= awk RKprint substr57MRP
if N shutdown3port 9 J:,J O then
S0 T1%@AT30S+& @ATALIBA341%+*bin*shutdown.sh
else
T1%@AT3$IDPps :ef = grep 6ava = grep @ATALIBA341%+ Q
= awk RKprint MRP kill :U T1%@AT3$ID
rm :rf @ATALIBA3$ID
fi
C &emove lock for &ed4at * SuS+
if test :w *var*lock*subsys
then
rm :rf *var*lock*subsys*S@&I$T3BA%+
fi
M
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
56/653
5/5/
p
case J,J in
start7
start
stop7
stop
restart7
stop
start
status7
status
V7 echo J0sage/ ; Kstart=stop=restart=statusMJ
eit ,
esac
case J,J in
start7
start
stop7
stop
restart7
stop
start
status7
status
V7 echo J0sage/ ; Kstart=stop=restart=statusMJ
eit ,
esac
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
57/653
5151
p
LetRs now eplain the key parts of the apache:tomcat.sh init script
Supplied apachetomcat.sh
The following three slides illustrate apachetomcat.shQ
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
58/653
5252
p
C9*bin*sh
C chkconfig EF- G; ;C description/ Apache Tomcat start*stop Daemon
C9*bin*sh
C chkconfig EF- G; ;C description/ Apache Tomcat start*stop Daemon
ch9config section indicates the default run le+els.This script is enabled at run le+els 2@,@5 and 4. /
indicates the start priority le+el@ while 2/ is the stoppriority le+el.
ch9config is standard on!ed )at and +ariants.
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
59/653
5,5,
p
CCC 8+HIB IBIT IB>1
C $rovides/ tomcat
C &e'uired:Start/ local3fsC &e'uired:Stop/ local3fs
C Default:Start/ E F -
C Default:Stop/ ; , #
C Short:Description/ Start*Stop Apache Tomcat daemon.
C Description/ +nable service provided by Apache Tomcat daemon.
CCC +BD IBIT IB>1
CCC 8+HIB IBIT IB>1
C $rovides/ tomcat
C &e'uired:Start/ local3fsC &e'uired:Stop/ local3fs
C Default:Start/ E F -
C Default:Stop/ ; , #
C Short:Description/ Start*Stop Apache Tomcat daemon.
C Description/ +nable service provided by Apache Tomcat daemon.
CCC +BD IBIT IB>1
This section is related to Debian
Init scripts.
The following links contains detailed information about Delbian init
scripts. http%%wi9i.debian.org%GS7InitScripts
http%%refspecs.freestandards.org%GS7(,.1./%GS7oregeneric%GS7oregeneric%iniscrptact.html
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
60/653
5555
T1%@AT30S+&tomcat
eport @ATALIBA341%+J*usr*local*tomcatJ
eport @ATALIBA38AS+J*usr*local*tomcatJ
eport (A2A341%+J*usr*local*6avaJeport S0J*bin*suJ
C D1 B1T +DIT 8+
8/12/2019 Tomcat Admin Electronic Handouts
61/653
5454
eport @ATALIBA3$ID@ATALIBA38AS+*logs*tomcat.pid
start57 K
echo :n JStarting S@&I$T3BA%+ ...J S0 T1%@AT30S+& @ATALIBA341%+*bin*startup.sh
C %ake lock for &ed4at * SuS+
if test :w *var*lock*subsys
then
touch *var*lock*subsys*S@&I$T3BA%+
fi
M
eport @ATALIBA3$ID@ATALIBA38AS+*logs*tomcat.pid
start57 K
echo :n JStarting S@&I$T3BA%+ ...J S0 T1%@AT30S+& @ATALIBA341%+*bin*startup.sh
C %ake lock for &ed4at * SuS+
if test :w *var*lock*subsys
then
touch *var*lock*subsys*S@&I$T3BA%+
fi
M
start57 is invoked during the boot process
startup.sh located in UATAGI=A()*&%bin gets in+o9ed
startup.sh is run using the user specified in the UT*AT +ariable
Apache Tomcat is started under the tomcat user in this instance
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
62/653
5353
stop57 K
echo :n JStopping S@&I$T3BA%+ ...J
shutdown3portPgrep shutdown
@ATALIBA341%+*conf*server.ml Q = awk RKprint substr57MRP
if N shutdown3port 9 J:,J O then
S0 T1%@AT30S+& @ATALIBA341%+*bin*shutdown.sh
else
T1%@AT3$IDPps :ef = grep 6ava = grep @ATALIBA341%+ Q
= awk RKprint MRP
kill :U T1%@AT3$ID
rm :rf @ATALIBA3$ID
fi
C &emove lock for &ed4at * SuS+
if test :w *var*lock*subsys then
rm :rf *var*lock*subsys*S@&I$T3BA%+
fi
M
stop57 K
echo :n JStopping S@&I$T3BA%+ ...J
shutdown3portPgrep shutdown
@ATALIBA341%+*conf*server.ml Q = awk RKprint substr57MRP
if N shutdown3port 9 J:,J O then
S0 T1%@AT30S+& @ATALIBA341%+*bin*shutdown.sh
else
T1%@AT3$IDPps :ef = grep 6ava = grep @ATALIBA341%+ Q
= awk RKprint MRP kill :U T1%@AT3$ID
rm :rf @ATALIBA3$ID
fi
C &emove lock for &ed4at * SuS+
if test :w *var*lock*subsys then
rm :rf *var*lock*subsys*S@&I$T3BA%+
fi
M
1; In+o9ed during the shutdown process.
2; Is the shutdown portdisabled in ser+er.0ml?
,; shutdown port is notdisabled
call shutdown.sh.
5; shutdown port disabled. DetermineCrocess id of tomcat. $ill the tomcat
and remo+e file containing tomcat pid.
0ni/ Tomcat as a Daemon Advanced scripts
8/12/2019 Tomcat Admin Electronic Handouts
63/653
5-5-
case J,J in
start7
start
stop7
stop
restart7
stop
start
status7
status
V7 echo J0sage/ ; Kstart=stop=restart=statusMJ
eit ,
esac
case J,J in
start7
start
stop7
stop
restart7
stop
start
status7
status
V7 echo J0sage/ ; Kstart=stop=restart=statusMJ
eit ,
esac
ser+ice apachetomcat startor
%etc%init.d%apachetomcat start
ser+ice apachetomcat stopor
%etc%init.d%apachetomcat stop
Summary
8/12/2019 Tomcat Admin Electronic Handouts
64/653
55
Downloading Tomcat
Distribution Types
!hich Download is &ight for %e"
%inimum &e'uirements
(D)*(&+ Installation
(A2A341%+ vs (&+341%+"
Tomcat Installation
Starting up Tomcat
Tomcat as a Service
8/12/2019 Tomcat Admin Electronic Handouts
65/653
5B5B
Wuestions"
8/12/2019 Tomcat Admin Electronic Handouts
66/653
11
Apache Tomcat Installation Lab
Windows Instructions
8/12/2019 Tomcat Admin Electronic Handouts
67/653
2CONFIDENTIAL 2CONFIDENTIAL
Installing the JDK
Verifying JDK install
Installing Apache Tomcat
Verifying Tomcat install
Identifying the Java command line
Adding JV and application parameters
Installing the Apache Tomcat instance as a Windows !ervice
Linu" Instructions
8/12/2019 Tomcat Admin Electronic Handouts
68/653
3CONFIDENTIAL 3CONFIDENTIAL
Installing the JDK
Verifying JDK install
Installing Apache Tomcat
Verifying Tomcat Install
Identifying the Java command line
Adding JV and application parameters
Installing the Apache Tomcat instance as a Linu" Daemon
8/12/2019 Tomcat Admin Electronic Handouts
69/653
11
Configuring TomcatTomcat Configuration - Part 1
8/12/2019 Tomcat Admin Electronic Handouts
70/653
22
Topics in this Session
Tomcat folder structure
High level overview of configuration files
Tomcat Folder Structure
8/12/2019 Tomcat Admin Electronic Handouts
71/653
33
Folder structure overview
apache-tomcat-6.0.x/- bin- conf- lib- logs- temp- webapps- wor
Tomcat Folder Structure ! bin
8/12/2019 Tomcat Admin Electronic Handouts
72/653
44
bin folder
startup/shutdown scripts
bootstrap libraries ant scripts !ust tas" definitions
e#e files for Tomcat$s %indows service wrapper
tomcat native &'P( wrapper) source code
*f +ou used the ,ip version
. ma"e +our ,sh scripts runnable e,g,chmod 0# bin/,sh
. fi# line endings in script files
,/apache-tomcat-,,#/bin
Tomcat Folder Structure ! bin
8/12/2019 Tomcat Admin Electronic Handouts
73/653
startup/shutdown scripts
startup,sh5bat invo"es catalina,sh5bat with parameter 6start$
shutdown,sh5bat invo"es catalina,sh5bat with parameter 6stop$
catalina,sh5bat
. *nvo"es setclasspath,bat5sh does ver+ little
. *nvo"es setenv,bat5sh put +our custom settings in here for a clean configuration
service.bat
7sed to install and remove the Tomcat service &windows onl+)
,/apache-tomcat-,,#/bin
Tomcat Folder Structure ! bin
8/12/2019 Tomcat Admin Electronic Handouts
74/653
bootstrap libraries
bootstrap,!ar contains startup classes
tomcat-!uli,!ar Tomcat$s logging framewor". 8ased on !ava,util,logging
This is all that is needed for Tomcat to start up
Startup classpath
setclasspath adds tools,!ar &from 9:;) catalina adds bootstrap,!ar< tomcat-!uli,!ar
,/apache-tomcat-,,#/bin
Tomcat Folder Structure ! bin
8/12/2019 Tomcat Admin Electronic Handouts
75/653
==
exe files for "indows service wrapper
tomcat,e#e the wrapper running Tomcat
tomcatw,e#e monitors and configures the service
Tomcat native source code
tomcat-native,tar,g
>ource code to compile Tomcat to use 'P( for networ" *?
@or %indows< download alread+ compiled :AA
,/apache-tomcat-,,#/bin
Tomcat Folder Structure ! conf
8/12/2019 Tomcat Admin Electronic Handouts
76/653
BB
conf director#
Contains all Tomcat$s configuration files
ood to "now there is nowhere else to loo" for configuration options
Subdirectories to the conf director#
Can be used for deplo+ment of web applications using DEA files
,/apache-tomcat-,,#/conf
Tomcat Folder Structure ! conf
8/12/2019 Tomcat Admin Electronic Handouts
77/653
FF
conf director# contents
server,#ml
catalina,properties
logging,properties
conte#t,#ml
web,#ml
tomcat-users,#ml catalina,polic+
,/apache-tomcat-,,#/conf
Tomcat Folder Structure ! lib
8/12/2019 Tomcat Admin Electronic Handouts
78/653
11
lib director#
Contains all libraries Tomcat uses during runtime
Tomcat$s class loader points to. GC'T'A*'I8'>J/libGC'T'A*'I8'>J/lib/,!ar
GC'T'A*'IH?EJ/libGC'T'A*'IH?EJ/lib/,!ar
The folder can contain 9'( files< and ,class files in their pac"age structure
Jas+ wa+ to put in patched ,class files is to put the ,class file in lib< it will be
loaded before the same file in the 9'( This director+ is not static< it is referenced from
conf/catalina,properties - common,loaderK,,,
,/apache-tomcat-,,#/lib
Tomcat Folder Structure ! logs
8/12/2019 Tomcat Admin Electronic Handouts
79/653
1111
logs director#
Tomcat$s logs information to files in here
$pplication log files ood idea for applications to log to the same director+
>ome applications log inside their own webapp
. generall+ a bad practice since logs will disappear if application is removed
,/apache-tomcat-,,#/logs
Tomcat Folder Structure ! temp
8/12/2019 Tomcat Admin Electronic Handouts
80/653
1212
temp director#
>+stem propert+ 6!ava,io,tmpdir$ points here
'llows applications to have a space for temporar+ file creation >+stem propert+ set in catalina,bat5sh
:onLt delete this director+
,/apache-tomcat-,,#/temp
Tomcat Folder Structure ! webapps
8/12/2019 Tomcat Admin Electronic Handouts
81/653
1313
webapps director#
default director+ for web application deplo+ments
. ,war files
. directories
Configured in server.xml
MHost app8aseKNwebappsO Q
,/apache-tomcat-,,#/webapps
Tomcat Folder Structure ! wor
8/12/2019 Tomcat Admin Electronic Handouts
82/653
1414
wor director#
Tomcat$s director+ for temporar+ file creation during runtime
>tores generated 9>P classes. ,!ava files generated !ava source code
. ,class files servlets that represent the 9>P
Sub director# structure
directories organied b+ component names defined in server,#ml
wor"/MJngine nameQ/MHost nameQ/
wor"/Catalina/localhost/
,/apache-tomcat-,,#/wor"
8/12/2019 Tomcat Admin Electronic Handouts
83/653
11
Topics in this Session Tomcat folder structure
%igh level overview of configuration files
Configuration Files ! server.xml
8/12/2019 Tomcat Admin Electronic Handouts
84/653
11
server.xml
Tomcat$s main configuration file
6builds$ the Tomcat runtime engine during DEA parsing Parsed using commons-digester
Hard coded rulesets for each DEA element
%ell formed DEA no :T: nor schema
conf/server,#mlconf/server,#ml
Configuration Files ! server.xml
8/12/2019 Tomcat Admin Electronic Handouts
85/653
1=1=
server.xml
J#tremel+ e#tensible< ever+ component can be swapped out using theclassame attribute
class&ame attribute omitted means Tomcat will use the default
M>erverportKNBO
classameKNm+,own,>erver*mplementationOQ
M/>erverQ
conf/server,#mlconf/server,#ml
Configuration Files ! server.xml
8/12/2019 Tomcat Admin Electronic Handouts
86/653
1B1B
server.xml
Eisspelt or misplaced elements will be reported
'gnored
"$(&'&)* &o rules found matching +Server/,#wnlement+
M>erverportKNBO
classameKNm+,own,>erver*mplementationOQ
ME+?wnJlementtomcatKNguruO/Q
M/>erverQ
conf/server,#mlconf/server,#ml
Configuration Files ! server.xml
8/12/2019 Tomcat Admin Electronic Handouts
87/653
1F1F
server.xml
Eisspelled or invalid attributes will normall+ be reported
M>erversportKNBO
classameKNm+,own,>erver*mplementationOQ
M/>erverQ
"$(&'&)* Setroperties(ule12Server3 Setting propert# +sport+ to4500+ did not find a matching propert#.
7' %TT Connector is the exception
conf/server,#mlconf/server,#ml
Configuration Files ! catalina.properties
8/12/2019 Tomcat Admin Electronic Handouts
88/653
22
catalina.properties
Class loaders setup
server,#ml substitution variables
Rserver shutdown port in conf/catalina,properties
shutdown,portKB
Rshutdown port specified in conf/server,#ml
M>erverportKNGSshutdown,portOQ
M/>erverQ
conf/catalina,propertiesconf/catalina,properties
Configuration Files ! logging.properties
8/12/2019 Tomcat Admin Electronic Handouts
89/653
2121
logging.properties
Tomcat$s internal logging setup
Preconfigured for good production level logging @ormat defined b+ !ava,util,logging
9avadoc of !ava,util,logging
http//download,oracle,com/!avase//docs/technotes/guides/logging/overview,html
conf/logging,propertiesconf/logging,properties
Configuration Files ! Change the name of a log file
8/12/2019 Tomcat Admin Electronic Handouts
90/653
2222
%andlers for root logger are defined using .handlers propert#.
7# default8 the root logger is defined to go to*
1)The console
2)' file named catalina,++++-mm-dd,log in the logs director+,
conf/logging,propertiesconf/logging,properties
,handlers K 1catalina,org,apache,!uli,@ileHandler< !ava,util,logging,ConsoleHandler
1catalina,org,apache,!uli,@ileHandler,level K @*J
1catalina,org,apache,!uli,@ileHandler,director+ K GScatalina,base/logs
1catalina,org,apache,!uli,@ileHandler,prefi# K catalina,
Configuration Files ! Change the name of a log file
8/12/2019 Tomcat Admin Electronic Handouts
91/653
2323
To change the name of this file to tomcat.####-mm-dd.log find*
conf/logging,propertiesconf/logging,properties
and change it to*
1catalina,org,apache,!uli,@ileHandler,prefi# K catalina,
1catalina,org,apache,!uli,@ileHandler,prefi# K tomcat,
catalina,21-12-11,logcatalina,21-12-11,log
catalina,21-12-11,logtomcat,21-12-11,log
Configuration Files ! Changing the log level
8/12/2019 Tomcat Admin Electronic Handouts
92/653
2424
9ogging levels can be configured per class or per pacage
same wa+ as !ava,util,logging,
,aximum logging from the :startup; classes*
,aximum logging for startup and runtime*
org,apache,catalina,startup,levelK'AA
org,apache,levelK'AA
>uch a high level of logging in production will lead to poor performance
conf/logging.properties
conf/logging.properties
Configuration Files ! (emove redundant logging
8/12/2019 Tomcat Admin Electronic Handouts
93/653
22
Tomcat+s catch-all logger logs to two different locations
The .handlers is the +catch-all+ logger8 which logs entries to*
1catalina,org,apache,!uli,@ileHandler &a file) !ava,util,logging,ConsoleHandler &standard out)
,handlers K 1catalina,org,apache,!uli,@ileHandler< !ava,util,logging,ConsoleHandler
conf/logging.properties
Configuration Files ! (emove redundant logging
8/12/2019 Tomcat Admin Electronic Handouts
94/653
22
9ogging to the console is often considered as unnecessar#
'n that case8
8/12/2019 Tomcat Admin Electronic Handouts
95/653
2=2=
web.xml
lobal defaults that appl+ to each deplo+ed web application
Eerged with application$s own web,#ml file :efined b+ the servlet specification
conf/web,#mlconf/web,#ml
Configuration Files ! context.xml
8/12/2019 Tomcat Admin Electronic Handouts
96/653
2B2B
context.xml
lobal defaults that appl+ to each deplo+ed web application
Tomcat specific< defined b+ the MConte#tQ element
conf/conte#t,#mlconf/conte#t,#ml
Configuration Files ! catalina.polic#
8/12/2019 Tomcat Admin Electronic Handouts
97/653
2F2F
catalina.polic#
7sed when running the 9UE with a >ecurit+ Eanager
Contains predefined permissions for Tomcat to run Eust be edited to accommodate code for web applications
conf/catalina,polic+conf/catalina,polic+
Configuration Files ! tomcat-users.xml
8/12/2019 Tomcat Admin Electronic Handouts
98/653
33
tomcat-users.xml
>imple username/password file for the default securit+ realm
conf/tomcat-users,#mlconf/tomcat-users,#ml
Summar#
8/12/2019 Tomcat Admin Electronic Handouts
99/653
3131
Tomcat folder structure
bin
conf lib
logs
temp
webapps
wor
%igh level overview of configuration files
server,#ml
web,#ml
catalina,properties< logging,properties< catalina,polic+
tomcat-users,#ml
8/12/2019 Tomcat Admin Electronic Handouts
100/653
3232
=uestions>
8/12/2019 Tomcat Admin Electronic Handouts
101/653
11
Configuring Tomcat LabPart 1
Windows Instructions
Sh tti A h T t ith th h td t
8/12/2019 Tomcat Admin Electronic Handouts
102/653
22
Shutting Apache Tomcat with the shutdown port
Verify visually
Using catalina.properties
Changing Apache Tomcat's logging configuration
Remove the old log files
Change the name of a log file
Changing the log level
Maing mistaes in ser!er."ml
Linu" Instructions
Sh tti A h T t ith th h td t
8/12/2019 Tomcat Admin Electronic Handouts
103/653
33
Shutting Apache Tomcat with the shutdown port
Verify using telnet
Using catalina.properties
Changing Apache Tomcat's logging configuration
Remove the old log files
Change the name of a log file
Changing the log level
Maing mistaes in ser!er."ml
8/12/2019 Tomcat Admin Electronic Handouts
104/653
11
Servlet, JSP & Web applicationsA brief overview of the specifications that make Tomcat a Servlet/JSP
container
8/12/2019 Tomcat Admin Electronic Handouts
105/653
22
Topics in this Session What is the JCP?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP
Packa#in# $ormats
Web application folder la%o!t
&onfi#!ration $iles
web'(ml overview
What's JCP?
J C it P
8/12/2019 Tomcat Admin Electronic Handouts
106/653
))
Java Community Process
Formalized process that deines uture speciications o the Java
platorm Java Speciication !e"uest #JS!$
Proposed specifications
Servlet * JSR+)1, - Servlet )'.
JSP * JSR 2, - JSP 2'2 / 0 2'2
8/12/2019 Tomcat Admin Electronic Handouts
107/653
Topics in this Session What is the J&P?
Tomcat and Java speciications
What is a Servlet?
Re!est/Response AP"s
What is a JSP
Packa#in# $ormats
Web application folder la%o!t
&onfi#!ration $iles
web'(ml overview
Tomcat and JS!s
8/12/2019 Tomcat Admin Electronic Handouts
108/653
,,
Servlet % JSP speciications
Tomcat
version J version
)'. 2'2 '.'( J34 1'56
2', 2'1 5'.'( J34 1',6
2' 2'. ,','(7 ,'.'( J34 1'6
2') 1'2 '1'(7 '.'( J34 1')6
2'2 1'1 )'('( J34 1'26 8?9
8/12/2019 Tomcat Admin Electronic Handouts
109/653
55
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP
Packa#in# $ormats
Web application folder la%o!t
&onfi#!ration $iles
web'(ml overview
What's a Servlet?
Class to implement re"uest%response pro(rammin( model
8/12/2019 Tomcat Admin Electronic Handouts
110/653
Class to implement re"uest%response pro(rammin( model
)ost commonly used or *TTP
+mplemented by application developer-
eployed into a Servlet container
ike Tomcat
%% main method or a Servlet
public voidservice #Servlet!e"uest re"uest, Servlet!esponseresponse$ thro.s / 0
1
8/12/2019 Tomcat Admin Electronic Handouts
111/653
::
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
!e"uest%!esponse 2P+s
What is a JSP
Packa#in# $ormats
Web application folder la%o!t
&onfi#!ration $iles
web'(ml overview
!e"uest%!esponse 2P+
*TTP is a client%server protocol
8/12/2019 Tomcat Admin Electronic Handouts
112/653
;;
*TTP is a client%server protocol
$or each Re!est7 there is a Response
8/12/2019 Tomcat Admin Electronic Handouts
113/653
1.1.
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP?
Packa#in# $ormats
Web application folder la%o!t
&onfi#!ration $iles
web'(ml overview
What's a JSP?
Te3t based document
8/12/2019 Tomcat Admin Electronic Handouts
114/653
1111
Te3t based document
&ontains static data 8te(t9
3irect Java s%nta( JSP elements and ta# libraries
What's a JSP?
JSP .ith J242 snippets #scriptlet$
8/12/2019 Tomcat Admin Electronic Handouts
115/653
1212
>@ pa#e importBCava'!til'D7E%ocalesB F>@ pa#e contentT%peBte(t/htmlG charset"SH+::,;+,B F
>htmlF >headF>titleFocaliIed 3ates>/titleF>/headF>bod% b#colorBwhiteBF>Csp!seform nameBlocale$ormB actionBinde('CspB methodBpostBF
>bFocale>/bF >select namelocaleF>
Strin# selectedocale re!est'#etParameter8BlocaleB9G
"terator i locales'#etocaleKames89'iterator89Gwhile 8i'hasKe(t899 L Strin# locale 8Strin#9i'ne(t89G
if 8selectedocale M n!ll NN selectedocale'e!als8locale99 LF
>option selectedF>localeF>/optionF> O else L F
>optionF>localeF>/optionF
> O O F>/selectF >inp!t t%peBs!bmitB nameBS!bmitB val!eBet 3ateBF>/formF>Cspincl!de pa#eBdate'CspB/F>/bod%F >/htmlF
>@ pa#e importBCava'!til'D7E%ocalesB F>@ pa#e contentT%peBte(t/htmlG charset"SH+::,;+,B F
>htmlF >headF>titleFocaliIed 3ates>/titleF>/headF>bod% b#colorBwhiteBF>Csp!seform nameBlocale$ormB actionBinde('CspB methodBpostBF
>bFocale>/bF >select namelocaleF>
Strin# selectedocale re!est'#etParameter8BlocaleB9G
"terator i locales'#etocaleKames89'iterator89Gwhile 8i'hasKe(t899 L Strin# locale 8Strin#9i'ne(t89G
if 8selectedocale M n!ll NN selectedocale'e!als8locale99 LF
>option selectedF>localeF>/optionF> O else LF
>optionF>localeF>/optionF
> O OF>/selectF >inp!t t%peBs!bmitB nameBS!bmitB val!eBet 3ateBF>/formF>Cspincl!de pa#eBdate'CspB/F>/bod%F >/htmlF
JSP elements
Static content
Java s%nta(
JSP .ith J242 snippets #scriptlet$
What is a JSP?
JSP .ith ta(lib and 53pression 6an(ua(e
8/12/2019 Tomcat Admin Electronic Handouts
116/653
1)1)
JSP .ith ta(lib and 53pression 6an(ua(e
>@ ta#lib !riBhttp//Cava's!n'com/Cstl/coreB prefi(BcB F
>htmlF>headF>titleF0(pression an#!a#e !sed in JST>/titleF>/headF
>bod% b#colorBwhiteBF
>cfor0ach varBiB be#inB1B endB1.B stepB1BF >co!t val!eBQLiOB /F
>br /F >/cfor0achF
>pFo!r total cost is QLp!rchase 6 ta(O >/pF
>pFo!r total cost is >co!t val!eQLp!rchase 6 ta(O/F >/pF>/bod%F
>/htmlF
>@ ta#lib !riBhttp//Cava's!n'com/Cstl/coreB prefi(BcB F
>htmlF>headF>titleF0(pression an#!a#e !sed in JST>/titleF>/headF
>bod% b#colorBwhiteBF
>cfor0ach varBiB be#inB1B endB1.B stepB1BF >co!t val!eBQLiOB /F
>br /F >/cfor0achF
>pFo!r total cost is QLp!rchase 6 ta(O >/pF
>pFo!r total cost is >co!t val!eQLp!rchase 6 ta(O/F >/pF>/bod%F
>/htmlF
Ta# librar%
Accessin#parameter
s
JST forloop
What's a JSP?
Compiled durin( runtime
8/12/2019 Tomcat Admin Electronic Handouts
117/653
11
Compiled durin( runtime
s!all% d!rin# first invocation
Compilation steps Parse 'Csp file into 'Cava
'Cava file implements Cava('servlet'Servlet interface
&ompile 'Cava file into 'class file
'class loaded and mapped to R"
See or yoursel in Tomcat-s .or7 directory
Servlets are controllers
)4C 2rchitecture
8/12/2019 Tomcat Admin Electronic Handouts
118/653
1,1,
Servlets are controllers
8/12/2019 Tomcat Admin Electronic Handouts
119/653
1515
Front controller is the entry point
8/12/2019 Tomcat Admin Electronic Handouts
120/653
11
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP?
Pac7a(in( Formats
Web application folder la%o!t &onfi#!ration $iles
web'(ml overview
Pac7a(in( Formats
J2!
8/12/2019 Tomcat Admin Electronic Handouts
121/653
1:1:
J2!
Java 2rchive
V"P archive of reso!rces 'class files
'properties files
An%thin# %o! wish to access thro!#h class loaders
3irector% str!ct!re follows Java packa#e namespace conventions
J contains :;ar< binary
same commands as tar7 b!t manip!lates V"P files
Pac7a(in( Formats
W2!
8/12/2019 Tomcat Admin Electronic Handouts
122/653
1;1;
W2!
Web 2rchive
V"P file containin# a web application 3oes not contain the conte(t folder
The name of the file is the conte(t name
Can be vie.ed usin( :;ar< binary
8/12/2019 Tomcat Admin Electronic Handouts
123/653
2.2.
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP?
Packa#in# $ormats
Web application older layout &onfi#!ration $iles
web'(ml overview
W2! Folders
8/12/2019 Tomcat Admin Electronic Handouts
124/653
2121
webapps/ m%webapp/
abo!t'htm m%webapp'css inde('Csp ima#es/
photo'Cp#
E0TA+"K$/ conte(t'(ml 8Tomcat Specific9
W0
8/12/2019 Tomcat Admin Electronic Handouts
125/653
2222
//#o into the director% of the web application
cd webapps/m%webapp/
//create the Iip fileCar cvfE ''/m%webapp'war D
//note that the root folder is not part of the archive
8/12/2019 Tomcat Admin Electronic Handouts
126/653
2)2)
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP?
Packa#in# $ormats
Web application folder la%o!t Coni(uration Files
web'(ml overview
Coni(uration Files
.eb93ml
8/12/2019 Tomcat Admin Electronic Handouts
127/653
22
3efined b% specification
http//Cava's!n'com/(ml/ns/Cavaee/web+appX2X,'(sd
Prior to Tomcat 57 ever% web application had to have a web'(ml incl!ded
ocation * W0
8/12/2019 Tomcat Admin Electronic Handouts
128/653
2,2,
Topics in this Session What is the J&P?
Tomcat and Java specifications
What is a Servlet?
Re!est/Response AP"s
What is a JSP?
Packa#in# $ormats
Web application folder la%o!t &onfi#!ration $iles
.eb93ml overvie.
W5=>+F%.eb93ml
The .eb93ml ta7es this (eneralized orm
8/12/2019 Tomcat Admin Electronic Handouts
129/653
2525
Schema defined athttp//Cava's!n'com/(ml/ns/Cavaee/web+appX2X,'(sd
W5=>+F%.eb93ml
@.eb>appA
8/12/2019 Tomcat Admin Electronic Handouts
130/653
22
Root element of the web'(ml' All other YE elements reside inside it
@iconA ocation of the ima#e files that ma% be !sed b% a tool to vis!all% represent the
web app
>iconF
>small+iconF/ima#es/icons/m%app+small'#if>/small+iconF >lar#e+iconF/ima#es/icons'm%app+lar#e'#if>/lar#e+iconF
>/iconF
W5=>+F%.eb93ml #continued$
@display>nameA
8/12/2019 Tomcat Admin Electronic Handouts
131/653
2:2:
A name that can be !sed for displa% in a " interface
>displa%+nameFE% Web Application>/displa%+nameF
@descriptionA
3escription of the web app
@distributableA
3escribes a web app that is desi#ned to be distrib!table for load balancin# andfailover'
3efa!lt is false7 as web apps re!ire additional s!pport for s!ch architect!re
W5=>+F%.eb93ml #continued$
@conte3t>paramA
8/12/2019 Tomcat Admin Electronic Handouts
132/653
2;2;
sed for settin# application initialiIation parameters
>conte(t+paramF>param+nameF#reetin#>/param+nameF>param+val!eFWelcome to m% appM>param+val!eF
>/conte(t+paramF
W5=>+F%.eb93ml #continued$
@ilterA
8/12/2019 Tomcat Admin Electronic Handouts
133/653
).).
Re!sable components that intercept the re!est and response and appl% somet%pe of processin# to them
0(amples
Z compress the content of the response
Z Transform YE to =TE
Z o##in# of reso!rce !sa#e
$ilters can be mapped to R patterns
W5=>+F%.eb93ml #continued$
53ample o deinin( a ilterB
8/12/2019 Tomcat Admin Electronic Handouts
134/653
)1)1
>filterF>iconF/ima#es/icons/filter'Cp#>/iconF
>filter+nameF&ompressor>/filter+nameF>descriptionFThis filter compresses>/descriptionF>filter+classFcom'm%compan%'!tils'&ompressor>/filter+classF>init+paramF
>param+nameFcompressionXt%pe>/param+nameF>param+val!eF#Iip>/param+val!eF
>/init+paramF>/filterF
)appin( the Filter a(ainst !6 patternsB
W5=>+F%.eb93ml #continued$
8/12/2019 Tomcat Admin Electronic Handouts
135/653
)2)2
>filter+mappin#F>filter+nameF&ompressor>/filter+nameF
>!rl+patternFD>/!rl+patternF>/filter+mappin#F
Compressor ilter .ill be applied to every !6
&orrect mappin# wo!ld have been to onl% [te(t\ content
W5=>+F%.eb93ml #continued$
@listenerA
8/12/2019 Tomcat Admin Electronic Handouts
136/653
))))
isteners respond to events in an application
e'#'7 a JavalistenerF>listener+classF
com'm%compan%'listeners'0mailistener
>/listener+classF>/listenerF
W5=>+F%.eb93ml #continued$
@servletA
8/12/2019 Tomcat Admin Electronic Handouts
137/653
))
Servlet+specific declarations>servletF
>iconF/ima#es/icons/servlet1'Cp#>/iconF>servlet+nameF3ownloadServlet>/servlet+nameF>servlet+classF
com'm%compan%'servlets'3ownloadServlet >/servlet+classF
>init+paramF>param+nameFre!ireXtc>/param+nameF>param+val!eFtr!e>/param+nameF
>/init+paramF>load+on+start!pF,>/load+on+start!pF>r!n+asF
>role+nameFadmin>/role+nameF>/r!n+asF
>/servletF
oad+on+start!p means servlet m!st be loaded when Tomcat starts 8rather than
wait till it is re!ested9 lower inte#er val!e load earlier than other Servlets
W5=>+F%.eb93ml #continued$
@session>coni(A
8/12/2019 Tomcat Admin Electronic Handouts
138/653
),),
Allows sessions to be confi#!red for ever% application
>session+confi#F>session+timeo!tF.>/session+timeo!tF
>/session+confi#F
+ the value is D or less, session never e3pires
W5=>+F%.eb93ml #continued$
@mime>mappin(A
8/12/2019 Tomcat Admin Electronic Handouts
139/653
)5)5
Web app ma% want to force the mime+t%pe
>mime+mappin#F>e(tensionFcsv>/e(tensionF>mime+t%peFapplication/(+mse(cel>/mime+t%peF
>/mime+mappin#F
eines the Content>Type- response header
$or static content served b% the application
W5=>+F%.eb93ml #continued$
@.elcome>ile>listA
8/12/2019 Tomcat Admin Electronic Handouts
140/653
))
&an over+ride the ones defined in the #lobal web'(ml
>welcome+file+listF>welcome+fileFwhatsnew'Csp>/welcome+fileF
>/welcome+file+listF
httpB%%serverBEDED%my.ebapp%.ill serve
httpB%%serverBEDED%my.ebapp%.hatsne.9;sp
W5=>+F%.eb93ml #continued$
@error>pa(eA
http://server:8080/mywebapp/http://server:8080/mywebapp/whatsnew.jsphttp://server:8080/mywebapp/whatsnew.jsphttp://server:8080/mywebapp/8/12/2019 Tomcat Admin Electronic Handouts
141/653
):):
&!stomiIed handlin# for =TTP errors and Java e(ceptions
>error+pa#eF>error+codeF.>/error+codeF>locationF/errors/oops'Csp>/locationF
>/error+pa#eF
>error+pa#eF>e(ception+t%peF
Cava'lan#'K!llPointer0(ception >/e(ception+t%peF>locationF/errors/badl%codedpa#e'Csp>/locationF
>/error+pa#eF
W5=>+F%.eb93ml #continued$
@ta(libA
8/12/2019 Tomcat Admin Electronic Handouts
142/653
););
&reatin# convenient aliases for 'tld files
>Csp+confi#F
>ta#libF>ta#lib+!riFapplicationta#s'tld>/ta#lib+!riF>ta#lib+locationF/W0
8/12/2019 Tomcat Admin Electronic Handouts
143/653
..
References to e(ternal reso!rces
Z J3
8/12/2019 Tomcat Admin Electronic Handouts
144/653
11
Sec!rit% constraints for web reso!rces7 accordin# to !ser roles7 SStransmission etc'
>sec!rit%+constraintF >web+reso!rce+collectionF >web+reso!rce+nameFProtected Area>/web+reso!rce+nameF
>M++ 3efine the conte(t+relative R8s9 to be protected ++F >!rl+patternF/Csp/sec!rit%/protected/D>/!rl+patternF
>M++ "f %o! list http methods7 onl% those methods are protected ++F >http+methodF0T>/http+methodF >http+methodFPHST>/http+methodF
>/web+reso!rce+collectionF >a!th+constraintF >M++ An%one with one of the listed roles ma% access this area ++F >role+nameFtomcat>/role+nameF
>role+nameFrole1>/role+nameF >/a!th+constraintF
>/sec!rit%+constraintF
@lo(in>coni(A
W5=>+F%.eb93ml #continued$
8/12/2019 Tomcat Admin Electronic Handouts
145/653
22
3efine the lo#in a!thentication mechanism $orm7 /form+lo#in+pa#eF>form+error+pa#eF
notA!thenticated'Csp
>/form+error+pa#eF>/form+lo#in+pa#eF
>/lo#in+confi#F
W5=>+F%.eb93ml #continued$
@security>roleA
8/12/2019 Tomcat Admin Electronic Handouts
146/653
))
Allows roles to be defined to#ether with optional description
>sec!rit%+roleF>descriptionF Administrator of the application>/descriptionF>role+nameFadministrator>/role+nameF
>/sec!rit%+roleF
W5=>+F%.eb93ml #continued$
@env>entryA
8/12/2019 Tomcat Admin Electronic Handouts
147/653
sed to declare environment entries
JK3" val!e parameters that can be !sed to confi#!re the application
0nv entr% m!st be t%ped to a Java data t%pe7 so it can be !sed within theapplication
>env+entr%F>descriptionFEinim!m allowable val!e>/descriptionF>env+entr%+nameFEinim!mUal!e>/env+entr%+nameF
>env+entr%+val!eF,>/env+entr%+val!eF>env+entr%+t%peFCava'lan#'"nte#er>/env+entr%+t%peF
>/env+entr%F
The val!e can then be accessed as8in an% Cava code9
&onte(t init&t( new "nitial&onte(t89G
&onte(t env&t( 8&onte(t9 init&t('look!p8Cavacomp/env9G"nte#er minUal!e 8"nte#er9env&t('look!p8Einim!mUal!e9G
.eb93ml
C2T26+2=2S5%con%.eb93ml
R l li ti b l
8/12/2019 Tomcat Admin Electronic Handouts
148/653
,,
Re#!lar application web'(ml
3efines #lobal defa!lts
0ach val!e can be overridden b% the application\s web'(ml
Summary
What is the JCP?
8/12/2019 Tomcat Admin Electronic Handouts
149/653
55
Tomcat and Java speciications
What is a Servlet?
!e"uest%!esponse 2P+s
What is a JSP
Pac7a(in( Formats
Web application older layout
Coni(uration Files
.eb93ml overvie.
8/12/2019 Tomcat Admin Electronic Handouts
150/653
Guestions?
8/12/2019 Tomcat Admin Electronic Handouts
151/653
11
Servlet, JSP & Web applications Lab
Windows Instructions
Inspecting a WAR file
Th JAR tilit d th i t l
8/12/2019 Tomcat Admin Electronic Handouts
152/653
22
The JAR utility and other zip tools
Examining a WAR file (7-ip! "ar#! $eploying a WAR file
Adding a JSP to a WAR
Expand the WAR
Write the J%&
&a'aging the WAR Modifying web!"l
)hanging the *R+ path for a %er,let
#nabling access to t$e "anager application
Linu! Instructions
Inspecting a WAR file
Th JAR tilit d th i t l
8/12/2019 Tomcat Admin Electronic Handouts
153/653
The JAR utility and other zip tools
Examining a WAR file (.ile /anager! "ar#! $eploying a WAR file
Adding a JSP to a WAR
Expand the WAR
Write the J%&
&a'aging the WAR Modifying web!"l
)hanging the *R+ path for a %er,let
#nabling access to t$e "anager application
8/12/2019 Tomcat Admin Electronic Handouts
154/653
11
Configuring TomcatTomcat Configuration - Part 2
8/12/2019 Tomcat Admin Electronic Handouts
155/653
22
Topics in this Session
Working with Threads
Connectors
SSL
Hosts
web.xml defaults
JSP defaults
Working with threads
Tomcat will create one instance of each servlet
ccessed b! multi"le t#reads
8/12/2019 Tomcat Admin Electronic Handouts
156/653
33
ccessed b! multi"le t#reads
$ac# user re%uest is bound to a dedicated t#read
&nitiali'ation(Load )esources*
Ser+ice(cce"t )e%uests*
,estruction(nload )esources*
)e%uest (t#read 2*
)e%uest (t#read 3*
)e%uest (t#read 1*
)e%uest (t#read n*
Servlet
Thread Pools
Each request is served by a thread
&f a t#read is initiated and destro!ed for eac# re%uest t#is "uts needless burden
8/12/2019 Tomcat Admin Electronic Handouts
157/653
&f a t#read is initiated and destro!ed for eac# re%uest/ t#is "uts needless burden
on t#e o"erating s!stem and J0
A Thread pool alleviates this issue by allowing eisting threads to
be reused
#en needed/ t#reads are retrie+ed from t#e "ool
fter being used/ eac# t#read is "ut bac into t#e "ool
T#e abo+e describes t#e wa! T#read "ooling generall! wors wit#tomcat. ,e"ending on t#e connector !ou4re using/ t#reads can bemanaged in a slig#tl! different wa!
Thread Pools
8/12/2019 Tomcat Admin Electronic Handouts
158/653
55
)e%uest
)e%uest
)e%uest
Tomcat
Ser+let
T#read Pool
Thread Pool! "asic Configuration
#aThreads
aximum number of acti+e t#reads in t#is "ool
8/12/2019 Tomcat Admin Electronic Handouts
159/653
66
aximum number of acti+e t#reads in t#is "ool
aximum number of concurrent re%uests in "rogress
,efault is 277
#inSpareThreads
inimum number of t#reads alwa!s e"t ali+e
,efault is 25
$Service %%%&
$Eecutor name'(tomcatThreadPool( namePrefi'(catalina)eec)(
maThreads'(*+,( minSpareThreads'(-(.&
/
$.Service&
$Service %%%&
$Eecutor name'(tomcatThreadPool(namePrefi'(catalina)eec)(
maThreads'(*+,(minSpareThreads'(-(.&
/
$.Service&
conf8ser+er.xmlconf8ser+er.xml
Thread Pool! Advanced Configuration
#a0dleTime! number of milliseconds before an idle thread is
shutdown
8/12/2019 Tomcat Admin Electronic Handouts
160/653
99
unless t#e number of acti+e t#reads is less or e%ual to minS"areT#reads
default +alue is 67777 ms (1 minute*
$Service %%%&
$1)) ma0dleTime is set to + minutes ))&
$Eecutor name'(tomcatThreadPool( namePrefi'(catalina)eec)(
maThreads'(+,,( minSpareThreads'(*,,(
ma0dleTime'(2,,,,,(.&
/
/
%%%$.Service&
$Service %%%&
$1)) ma0dleTime is set to + minutes ))&
$Eecutor name'(tomcatThreadPool(namePrefi'(catalina)eec)(
maThreads'(+,,(minSpareThreads'(*,,(
ma0dleTime'(2,,,,,(.&
/
/
%%%$.Service&
conf8ser+er.xmlconf8ser+er.xml
8/12/2019 Tomcat Admin Electronic Handouts
161/653
::
Topics in this Session
oring wit# T#reads
Connectors
SSL
Hosts
web.xml defaults
JSP defaults
d+anced
;&
8/12/2019 Tomcat Admin Electronic Handouts
162/653
>>
Communication between tomcat and its client
Client Tomcat
Request
Response
Request
Response
"ac#e#tt"d
Connector
Client Tomcat
Request
Response
Connector
T#e current module focuses on t#e second case (communication wit#t#e web ser+er will be seen later in t#is course*
Connectors! default behavior
Tomcat by default listens on port 4,4,
8/12/2019 Tomcat Admin Electronic Handouts
163/653
1717
$Server %%%&
$Service %%%& /
$Connector port'(4,4,( protocol'(5TTP.*%*(
ConnectionTimeout'(3,,,,( redirectPort'(4--2( .&
/
/
$.Service&
$.Server&
$Server %%%&
$Service %%%& /
$Connectorport'(4,4,(protocol'(5TTP.*%*(
ConnectionTimeout'(3,,,,(redirectPort'(4--2(.&
/
/
$.Service&
$.Server&
conf8ser+er.xmlconf8ser+er.xml
d+anced features about connectors suc# as t#e difference betweenP)/ =&< and ;&< connectors are s#own in t#e ad+anced sectionat t#e end of t#is module
C#ange t#e "ort number #ere if !ouwis# to use a different +alue
8/12/2019 Tomcat Admin Electronic Handouts
164/653
1111
Topics in this Session
oring wit# T#reads
Connectors
SS6
Hosts
web.xml defaults
JSP defaults
d+anced
;&
8/12/2019 Tomcat Admin Electronic Handouts
165/653
1212
The browser will send requests encrypted with SS6 directly to
Tomcat
Client Tomcathttps (encrypted) Request
https (encrypted) Response
http (cleartext) Request
http (cleartext) Response
SS6! keystore
0n order for a browser and Tomcat to communicate via SS67authentication is needed
8/12/2019 Tomcat Admin Electronic Handouts
166/653
1313
Tomcat will "resent t#e browser wit# a certificate as "roof of w#o it
claims to be
What is a keystore8
contains trusted certificates and combinations of "ri+ate e!s wit# t#eircorres"onding certificates
suall! stored in a file
SS6! truststore
A truststore is a keystore which is used when making decisions
about what to trust%
8/12/2019 Tomcat Admin Electronic Handouts
167/653
11
0f you receive some data from an entity that is already trusted
+erif! t#at t#e entit! is t#e one it claims to be
!ou can assume t#at t#e data reall! came from t#at entit!
0f the user makes a decision to trust an entity
an entr! s#ould onl! be added to a truststore
9enerating a keystore
A keystore maybe generated on the command)line using keytool
keytool is part of the :;?nknown@! 9"
Enter key password for $tomcat&
=ET?= if same as keystore passwordD! $:ust press =ET?=&
.usr.local.tomcat.keytool )genkey )alias tomcat )keyalg =SA )keystore %keystore
Enter keystore password! $Enter changeit&
=e)enter new password! $Enter changeit&
What is your first and last name8
>?nknown@! $:ust press =ET?=&
What is the name of your organiBational unit8
%%%
What is the two)letter country code for this unit8
>?nknown@! 9"
Enter key password for $tomcat&
=ET?= if same as keystore passwordD! $:ust press =ET?=&
SS6! sample configuration
""lication can be accessed using an urlsuc# as #tt"sA88local#ostA:38m!""
8/12/2019 Tomcat Admin Electronic Handouts
169/653
1616
$Server %%%&
$Service %%%&
/
$Connector port'(4--2( SS6Enabled'(true( scheme'(https( secure'(true(
keystoreile'(conf.%keystore( keystorePass'(changeit(.&
%%%
$.Service&
$.Server&
$Server %%%&
$Service %%%&
/
$Connectorport'(4--2(SS6Enabled'(true( scheme'(https(secure'(true(
keystoreile'(conf.%keystore(keystorePass'(changeit(.&
%%%
$.Service&
$.Server&
conf8ser+er.xmlconf8ser+er.xml
suc# as #tt"sA88local#ostA:38m!""
Tomcat is #andling encr!"tion (as o""osedto "ac#e #tt"d or an! ot#er front-end ser+er*
SS6! aking connection
Tricking deployed application into thinking it is still communicating
via https%
8/12/2019 Tomcat Admin Electronic Handouts
170/653
1919
seful in re+erse "rox! situations w#en SSL is terminated at t#e "rox!/ but t#e
a""lication re%uires SSLlso useful in a de+elo"ment en+ironment w#ere t#e certificate from a C is not
"ossible
$Connector port'(4--2( protocol'(5TTP.*%*(
SS6Enabled'(false( secure'(true( clientAuth'(false(.&
$Connectorport'(4--2(protocol'(5TTP.*%*(
SS6Enabled'(false( secure'(true(clientAuth'(false(.&
""lication can be accessed using an urlsuc# as httpA88local#ostA:38m!""
- Trust store is not used- web.xml does not #a+e CL&$;T-C$)T
as an aut#entication constraint
Tomcat is ;
8/12/2019 Tomcat Admin Electronic Handouts
171/653
1:1:
Topics in this Session
oring wit# T#reads
Connectors
SSL
5osts
web.xml defaults
JSP defaults
d+anced
;&
8/12/2019 Tomcat Admin Electronic Handouts
172/653
1>1>
$Server %%%&
$Service %%%&
$Engine name'(Catalina( default5ost'(localhost(&
$5ost name'GbartG %%%& %%% $.5ost&
$5ost name'GlisaG %%%& %%% $.5ost&
$.Engine& $.Service&
$.Server&
$Server %%%&
$Service %%%&
$Engine name'(Catalina( default5ost'(localhost(&
$5ost name'GbartG%%%& %%% $.5ost&
$5ost name'GlisaG%%%& %%% $.5ost&
$.Engine& $.Service&
$.Server&
&n t#is exam"le/ bot# #tt"A88bartA:7:7and #tt"A88lisaA:7:7refer to t#esame tomcat instance
conf8ser+er.xmlconf8ser+er.xml
Engine)5ost =elationship
http://bart:8080/http://lisa:8080/http://lisa:8080/http://bart:8080/8/12/2019 Tomcat Admin Electronic Handouts
173/653
2727
B$nginedefaultDwww.bar.com
BHostwww.foo.com
BHostwww.bar.com
1HTTP )e%uest
HostAwww.bar.comC#ec Host
Send to default
2
C#ec Host
HostAwww.foo.com
3
Firtual hosting
0n order for the virtual hosts bart and lisa to be resolved7 they need
to be added to the .etc.hosts file on 6inu%
8/12/2019 Tomcat Admin Electronic Handouts
174/653
2121
Hn Windows7 corresponding hosts file is inside
C!IW0;HWSIsystem23IdriversIetcI directory%
/etc/hosts
*3J%,%,%* bart
*3J%,%,%* lisa
*3J%,%,%* bart
*3J%,%,%* lisa
/etc/hosts
C:\WINDOWS\system32\drivers\etc\hosts
*3J%,%,%* bart
*3J%,%,%* lisa
*3J%,%,%* bart
*3J%,%,%* lisa
Linux
indows
5osts! $5ost& Element
#anages deployment of all web applications
Supports virtual hosts
8/12/2019 Tomcat Admin Electronic Handouts
175/653
2222
Supports virtual hosts
Hnly one K.G rootD contet per host
Each host has a name
$5ost name'KmyhostGapp"ase'KwebappsG
deployHnStartup'KtrueG
auto;eploy'KtrueG
unpackWA=S'KtrueG
.&
$5ost name'KmyhostGapp"ase'KwebappsG
deployHnStartup'KtrueG
auto;eploy'KtrueG
unpackWA=S'KtrueG
.&
conf8ser+er.xmlconf8ser+er.xml
5osts! $5ost& Element
The 5ost LnameM is used for virtual host matching
8/12/2019 Tomcat Admin Electronic Handouts
176/653
2323
$5ost name'Kwww%foo%comG
app"ase'K.opt.applications.webappsG
deployHnStartup'KtrueG
auto;eploy'KtrueG
unpackWA=S'KtrueG
.&
$5ost name'Kwww%foo%comG
app"ase'K.opt.applications.webappsG
deployHnStartup'KtrueG
auto;eploy'KtrueG
unpackWA=S'KtrueG
.&
conf8ser+er.xmlconf8ser+er.xml
5osts! Alias
An alias is another name given to a host
#ost can #a+e more t#an one lias
8/12/2019 Tomcat Admin Electronic Handouts
177/653
22
;o wild card matc#ing at t#is "oint
$5ost name'Kwww%foo%comG
app"ase'K.opt.applications.webappsG &
$Alias&foo%com $.Alias&$Alias&subdomain%foo%com $.Alias&
$.5ost&
$5ost name'Kwww%foo%comG
app"ase'K.opt.applications.webappsG &
$Alias&foo%com$.Alias&$Alias&subdomain%foo%com$.Alias&
$.5ost&
conf8ser+er.xmlconf8ser+er.xml
8/12/2019 Tomcat Admin Electronic Handouts
178/653
2525
Topics in this Session
oring wit# T#reads
Connectors
SSL
Hosts
web%ml defaults
JSP defaults
d+anced
;&
8/12/2019 Tomcat Admin Electronic Handouts
179/653
2626
;efault mappings can be updated by modifying conf.web%ml
"ehavior can be added at the application level
inside $=-&;E8web.xml file
&n most cases it won4t o+erride w#at #as been declared inside
CTL&;F=S$8conf8web.xml
&t will rat#er merge t#e 2 configurations toget#er
web%ml defaults! Servlets
Tomcat deploys two servlets into every web application
,efaultSer+let
8/12/2019 Tomcat Admin Electronic Handouts
180/653
2929
Js"Ser+let
web%ml defaults! ;efault Servlet
;efaultServlet O handles static content delivery
Eamples of static content would be html files7 style sheets and
8/12/2019 Tomcat Admin Electronic Handouts
181/653
2:2:
$web)app %%%&
/
$servlet&
$servlet)name&default$.servlet)name&
$servlet)class&org%apache%catalina%servlets%;efaultServlet$.servlet)class&
$init)param& $param)name&debug$.param)name&
$param)value&,$.param)value&
$.init)param&
%%%
$.servlet&
/
$.web)app&
$web)app %%%&
/
$servlet&
$servlet)name&default$.servlet)name&
$servlet)class&org%apache%catalina%servlets%;efaultServlet$.servlet)class&
$init)param& $param)name&debug$.param)name&
$param)value&,$.param)value&
$.init)param&
%%%
$.servlet&
/
$.web)app&
images
conf8web.xmlconf8web.xmlconf8web.xmlconf8web.xml
,ebuggingdetail le+el formessageslogged b! t#isser+let
,ebuggingdetail le+el formessageslogged b! t#isser+let
web%ml defaults! :spServlet
$web)app %%%&
$web)app %%%&
:spServlet O manages :SP compilation
8/12/2019 Tomcat Admin Electronic Handouts
182/653
2>2>
/
$servlet& $servlet)name&sp$.servlet)name&
$servlet)class&org%apache%asper%servlet%:spServlet$.servlet)class&
%%%
$init)param&
$param)name&development$.param)name&
$param)value&true$.param)value& $.init)param&
$init)param&
$param)name&modificationTest0nval$.param)name&
$param)value&-$.param)value&
$.init)param&
$.servlet&
%%%
$.web)app&Q
/
$servlet& $servlet)name&sp$.servlet)name&
$servlet)class&org%apache%asper%servlet%:spServlet$.servlet)class&
%%%
$init)param&
$param)name&development$.param)name&
$param)value&true$.param)value& $.init)param&
$init)param&
$param)name&modificationTest0nval$.param)name&
$param)value&-$.param)value&
$.init)param&
$.servlet& %%%
$.web)app&Q
conf8web.xmlconf8web.xml
&f Jas"er used inde+elo"ment mode/fre%uenc! at w#ic# JSPsare c#eced formodification ma! bes"ecified +ia t#emodificationTest&nter+al
"arameter
&f Jas"er used inde+elo"ment mode/fre%uenc! at w#ic# JSPsare c#eced formodification ma! bes"ecified +ia t#emodificationTest&nter+al
"arameter
web%ml defaults! Session timeout
Session timeout defaults to 2, minutes
8/12/2019 Tomcat Admin Electronic Handouts
183/653
3737
$web)app %%%&
/
$1)) '''''''''''''''''''' ;efault Session Configuration ''''''''''''''''' ))&
$1)) Rou can set the default session timeout in minutesD for all newly ))&
$1)) created sessions by modifying the value below% ))& $session)config&
$session)timeout&2,$.session)timeout&
$.session)config&
/
$.web)app&
$web)app %%%&
/
$1)) '''''''''''''''''''' ;efault Session Configuration ''''''''''''''''' ))&
$1)) Rou can set the default session timeout in minutesD for all newly ))&
$1)) created sessions by modifying the value below% ))& $session)config&
$session)timeout&2,$.session)timeout&
$.session)config&
/
$.web)app&
conf8web.xmlconf8web.xml
in minutes
web%ml defaults! #ime mappings
When serving static resources like stylesheets or html
GContent-T!"eG #eader is automaticall! generated based on t#e resource4s
fil t i
8/12/2019 Tomcat Admin Electronic Handouts
184/653
3131
filename extension
$web)app %%%&
/
$mime)mapping&
$etension&css$.etension&
$mime)type&tet.css$.mime)type&
$.mime)mapping&
$mime)mapping&
$etension&doc$.etension&
$mime)type&application.msword$.mime)type&
$.mime)mapping&
/
$.web)app&
$web)app %%%&
/
$mime)mapping&
$etension&css$.etension&
$mime)type&tet.css$.mime)type&
$.mime)mapping& $mime)mapping&
$etension&doc$.etension&
$mime)type&application.msword$.mime)type&
$.mime)mapping&
/
$.web)app&
conf8web.xmlconf8web.xml
web%ml defaults! Welcome file list
When a request ?=0 refers to a directory7 default servlet looks for a
(welcome file( within that directory%
&f t it ill di l )&
8/12/2019 Tomcat Admin Electronic Handouts
185/653
3232
&f "resent/ it will dis"la! resource )&.
&f no welcome file is "resent/ default ser+let eit#er ser+es a director! listing orreturns a 7 status/ de"ending on #ow it is configured.
$web)app %%%&
/ $welcome)file)list&
$welcome)file&inde%html$.welcome)file&
$welcome)file&inde%htm$.welcome)file&
$welcome)file&inde%sp$.welcome)file&
$.welcome)file)list&
$.web)app&
$web)app %%%&
/ $welcome)file)list&
$welcome)file&inde%html$.welcome)file&
$welcome)file&inde%htm$.welcome)file&
$welcome)file&inde%sp$.welcome)file&
$.welcome)file)list&
$.web)app&
conf8web.xmlconf8web.xml
T i i thi S i
8/12/2019 Tomcat Admin Electronic Handouts
186/653
3333
Topics in this Session
oring wit# T#reads
Connectors
SSL
Hosts
web.xml defaults
:SP defaults
d+anced
;&
8/12/2019 Tomcat Admin Electronic Handouts
187/653
33
All the :SP files related to web applications will be compiled in the
work.Catalina.localhost directory
:SP defaults! Compilation settings
Compilation settings are specified in the conf.web%ml file
discussed in "re+ious section.
8/12/2019 Tomcat Admin Electronic Handouts
188/653
3535
check0nterval! The time in seconds7 between checks to see if a :SP
page and its dependents need to be recompiled%
sed in de+elo"ment mode onl!.
modificationTest0nterval! The interval in seconds a :SP file and its
dependents are checked for modification
+alue of 7 will cause t#e JSP to be c#eced on e+er! access sed in de+elo"ment mode onl!.
:SP defaults! Changing compilation settings
Compilation settings are specified in the conf.web%ml file
6ocate the :spServlet section to change settings
8/12/2019 Tomcat Admin Electronic Handouts
189/653
3636
Eample! in a production environment7 (development( can be
disabled
Summary
Working with Threads
Connectors
8/12/2019 Tomcat Admin Electronic Handouts
190/653
3939
SS6
5osts
:SP defaults
web%ml defaults
8/12/2019 Tomcat Admin Electronic Handouts
191/653
3:3:
uestions8
Topics in this Session
8/12/2019 Tomcat Admin Electronic Handouts
192/653
3>3>
Topics in this Session
oring wit# T#reads
Connectors
SSL
Hosts
web.xml defaults
JSP defaults
Advanced
0H7 "0H and AP= connectors
6isteners
Connectors! "locking 0H
;efault connector is ("locking 0H( "0HD
)e%uires dedicating a t#read to eac# socet connection
8/12/2019 Tomcat Admin Electronic Handouts
193/653
77
Less t#reads a+ailable in an #ig# concurrenc! en+ironment =locing until data is a+ailable
$Server %%%&
$Service %%%& /
$Connector port'(4,4,( protocol'(5TTP.*%*(
ConnectionTimeout'(3,,,,( redirectPort'(4--2( .&
/
$.Service&$.Server&
$Server %%%&
$Service %%%& /
$Connectorport'(4,4,(protocol'(5TTP.*%*(
ConnectionTimeout'(3,,,,(redirectPort'(4--2(.&
/
$.Service&$.Server&
conf8ser+er.xmlconf8ser+er.xml
Can also be declared ex"licitl!protocol=org.apache.coyote.http11.Http11Protocol
Connectors! 0H
We can use Kon "lockingG or 0H connector instead
n &8< o"eration ne+er blocs
< ti t f f b t t# t d ( ti l d it *
8/12/2019 Tomcat Admin Electronic Handouts
194/653
11
8/12/2019 Tomcat Admin Electronic Handouts
195/653
22
;&< is more recent. +ailable as of Tomcat 6.x
ost content is d!namic
)elati+el! low concurrenc! en+ironment
?se 0H if!
sing SSL
Lots of static content
Hig# concurrenc! en+ironment
Connectors! AP=
Also a non)blocking connector like 0HD
When working with SS67 uses HpenSS6
8/12/2019 Tomcat Admin Electronic Handouts
196/653
33
g 7 p
9ood performance for keep)alive in a high concurrency environment
=equires registration of a dedicated listener
)e%uires dedicating a t#read to eac# socet connection$Server %%%& $Service %%%&
$6istener
classame'(org%apache%catalina%core%Apr6ifecycle6istener(
SS6Engine'(on( .&
/
$Connector port'(4,4,(
protocol'(org%apache%coyote%http**%5ttp**AprProtocol(
ConnectionTimeout'(3,,,,( redirectPort'(4--2( .& / $.Service&
$.Server&
$Server %%%&
$Service %%%&
$6istener
classame'(org%apache%catalina%core%Apr6ifecycle6istener(
SS6Engine'(on(.&
/
$Connectorport'(4,4,(
protocol'(org%apache%coyote%http**%5ttp**AprProtocol(
ConnectionTimeout'(3,,,,(redirectPort'(4--2(.& / $.Service&
$.Server&
conf8ser+er.xmlconf8ser+er.xml
6ifecycle6istener
$6ifecycle6istener& element
&nternal Tomcat com"onents
Listens to container e+ents suc# as ST)T ST
8/12/2019 Tomcat Admin Electronic Handouts
197/653
Listens to container e+ents suc# as ST)T/ ST
8/12/2019 Tomcat Admin Electronic Handouts
198/653
55
Enables usage of HpenSS6 instead of :SSE
$6istener classame'K/Apr6ifecycle6istenerG
SS6Engine'Konoffother commandG
SS6=andomSeed'Kbuiltin.dev.urandom/G.&
$6istener classame'K/Apr6ifecycle6istenerG
SS6Engine'Konoffother commandG
SS6=andomSeed'Kbuiltin.dev.urandom/G.&
conf8ser+er.xmlconf8ser+er.xml
:asper6istener
0nitialiBes :asper prior to any webapps are deployed
Put in to avoid class loading conflicts
8/12/2019 Tomcat Admin Electronic Handouts
199/653
66
o configurable parameters
$6istener classame'K/:asper6istenerG.&$6istenerclassame'K/:asper6istenerG.&
conf8ser+er.xmlconf8ser+er.xml
Server6ifecycle6istener
0nitialiBes :#U code for Tomcat
Creates mbeans for Tomcat obects
H
8/12/2019 Tomcat Admin Electronic Handouts
200/653
99
Hne parameter7 but no usage
$6istener classame'K/Server6ifecycle6istenerG descriptors'K! separated list of paths to find
mbeans)descriptors%mlG
.&
$6istener classame'K/Server6ifecycle6istenerG descriptors'K! separated list of paths to find
mbeans)descriptors%mlG
.&
conf8ser+er.xmlconf8ser+er.xml
8/12/2019 Tomcat Admin Electronic Handouts
201/653
11
Configuring Tomcat LabPart 2
Configuring connectors
Adding a standard HTTP connector
Adding a NIO HTTP connector
U i h d th d l
8/12/2019 Tomcat Admin Electronic Handouts
202/653
22
Using shared thread pool
Configuring SSL
Faing an SSL connection
Configuring multiple hosts
Configure the net!or
Creating a "irtual hosts