Академический Документы
Профессиональный Документы
Культура Документы
Server
PostedJan7,2014108.1k
views
Introduction
ApacheTomcatisanapplicationserverthatcanbeusedtoserveJavaapplicationstowebusers.Itisan
openimplementationoftheJavaServletandJavaServerPagesspecsthatweredevelopedbySun
Microsystems.
IfyoudevelopJavaapplications,Tomcatisaquickandeasywaytoservetheminafullserverenvironment
specificallydesignedforthatpurpose.
Inthisguide,wewillinstallTomcatanddosomebasicconfigurationonaDebian7VPS.Tocompletethis
tutorial,youwillhavetohaveanormaluserwithsudoprivileges.Followthisguidetolearnhowtocreate
usersonaDebiansystem.
InstallApacheTomcat
Inthisguide,wewillinstallTomcatversion7anditsassociatedpackages.Luckily,theseareincludedinthe
defaultDebianrepositories.
Togetthebasicpackage,wecanupdateourpackagesourcelistandtheninstallthemainpackage:
sudoaptgetupdate
sudoaptgetinstalltomcat7
ThisisallweneedtodotogettothedefaultTomcatpage.Ourinstallationisnotcompleteyet,butyoucan
takealookatthedefaultTomcatpagebygoingtoyourIPaddressordomainfollowedby:8080inyourweb
browser:
your_domain_or_ip:8080
InordertotakeadvantageofmoreofTomcat'sfeatures,wewillinstallsomeadditionalTomcatpackages.
ThesewillallowustouseawebinterfacetocontrolTomcat.Itwillinstallsomedocumentationandexamples
thatwecanalsoaccessthroughthewebinterfaceaswell.
sudoaptgetinstalltomcat7admintomcat7examplestomcat7docs
InstallJavaDevelopmentTools
InordertouseTomcattodevelopJavaapplicationsonyourserver,youwillneedtodownloadandinstalla
fewthings.
ThefirstthingweneedtodoisinstallacompatibleJavaDevelopmentKit.Wecaninstalltheonethat
Debianselectedasdefaultwiththefollowingcommand:
sudoaptgetinstalldefaultjdk
Thiswillinstallopenjdk6jdkwhichwillworkwellinourenvironment.
TheTomcatdocumentationalsosuggeststhatyouinstallApacheAnt,whichisabuildtoolforJava
applications,andaversioncontrolsystemofsomesort.Wewillchoosegit:
sudoaptgetinstallantgit
ThesewillhelpyoubuildyourJavaapplicationsandkeepthecodeorganized.
ConfigureTomcatWebInterface
Beforewecanbeginusingsomeofthefeaturesweinstalled,weneedtoconfigureourserverwithauser
andpassword.Tomcatdoesnotdothisbydefaultforsecurityreasons.
Theconfigurationisverysimple.Weneedtoeditafilecalledtomcatusers.xml.Openitwithaneditorlike
this:
sudonano/etc/tomcat7/tomcatusers.xml
Inside,youwillfindaheavilycommenteduserconfigurationfile.Infact,theonlyportionsofthefilethatare
notcommentsare:
<tomcatusers>
</tomcatusers>
Asyoumightexpect,weneedtodefineauserbetweenthesetwolines.Wewillgivethisuseraccesstothe
webinterfaces.Wecandefineauserlikethis:
<tomcatusers>
<userusername="admin"password="password"roles="managergui,admingui"/>
</tomcatusers>
Choosewhateverusernameandpasswordyouwouldlike.Thiswillprovideyouwithlogincredentialsthat
allowyoutoaccessthemanagementpanels.
Saveandclosethefilewhenyouarefinished.
WeshouldrestartTomcatinordertoimplementourchanges:
sudoservicetomcat7restart
TesttheWebInterface
OnceyouhaveinstalledTomcatandconfiguredtheuserlogin,youcanaccessthemainpagebygoingto
yourserverIPaddressordomainnamefollowedby:8080likethis:
your_domain_or_ip:8080
YouwillseethesamedefaultTomcatpagethatyousawearlier(ifyouchecked):
Becausewehaveinstalledandconfiguredmorecomponents,however,wewillhaveaccesstomore
functionality.
YoucanaccesstheTomcatdocumentationinthebrowserbyclickingthelinkyouseeonthepageor
accessingthispage:
your_domain_or_ip:8080/docs
ThisshouldbeyourfirststopwhenyouhavequestionsabouthowtodosomethingwithTomcat.
Wealsonowhaveaccesstosomeexampleapplicationsthatareimplementedusingafewdifferent
technologies.Thesecanbereachedfromalinkonthesameinitiallandingpage,orbyvisiting:
your_domain_or_ip:8080/examples
Clickingthroughtheseitemsgivesusanideaofhowdifferentfunctionalitycanbeimplementedinthis
environment.Mostexamplesincludethesourcecodethatyoucanuseforreference.
Themainfunctionalitiesthatyouwillwantaccesstoarethemanagerwebappandthehostmanager
webapp.
Again,youcanaccessthosefromtheinitiallandingpage,orbyvisiting:
your_domain_or_ip:8080/manager/html
And:
your_domain_or_ip:8080/hostmanager/html
ThefirstsitewillallowyoutomanageyourJavaapplications.Itwillletyoustart,stop,deploy,andreload
yourappseasily.Itcanalsofindmemoryleakscausedbyyourrunningapplications:
Fromtheotherpage,youcantest,adjust,andaddvirtualhostsinordertoserveryourapplications.This
allowsyoutosetupaccesstoyourdeployedappseasily:
Conclusion
Asyoucansee,TomcatprovidesaniceplatformforcontrollingandservingyourJavaapplicationsinaweb
environment.Youcaneasilydeploy.warfilesandhavethemupandrunninginverylittletime.
ByJustinEllingwood