xiaoxin0 2011-08-22
集群:
1.集群背景介紹
術語定義
服務軟體是b/s或c/s結構的s部分,是為b或c提供服務的服務性軟件系統。
服務硬體指提供計算服務的硬件、比如pc機、pc服務器。
服務實體通指服務軟體和服務硬體。
客戶端指接受服務實體服務的軟件或硬件。
2.兩大關鍵特性
集群是一組協同工作的服務實體,用以提供比單一服務實體更具擴展性與可用性的服務平臺。在
客戶端看來,一個集群就像是一個服務實體,但事實上集群由一組服務實體組成。
與單一服務實體相比較,集群提供了以下兩個關鍵特性:
可擴展性--集群的性能不限于單一的服務實體,新的服務實體可以動態地加入到集群,從而增強集群的性能。
高可用性--集群通過服務實體冗餘使客戶端免于輕易遇到outofservice的警告。
在集群中,同樣的服務可以由多個服務實體提供。如果一個服務實體失敗了,另一個服務實體會接管失敗的服務實體。
集群提供的從一個出錯的服務實體恢復到另一個服務實體的功能增強了應用的可用性。
3.兩大能力
為了具有可擴展性和高可用性特點,集群的必須具備以下兩大能力:
負載均衡--負載均衡能把任務比較均衡地分布到集群環境下的計算和網絡資源。
錯誤恢復--由于某種原因,執行某個任務的資源出現故障,另一服務實體中執行同一任務的資源接著完成任務。
這種由于一個實體中的資源不能工作,另一個實體中的資源透明的繼續完成任務的過程叫錯誤恢復。
負載均衡和錯誤恢復都要求各服務實體中有執行同一任務的資源存在,而且對于同一任務的各個資源來說,執行任務所需的信息視圖(信息上下文)必須是一樣的。
4.兩大技術
集群地址--集群由多個服務實體組成,集群客戶端通過訪問集群的集群地址獲取集群內部各服務實體的功能。
具有單一集群地址(也叫單一影像)是集群的一個基本特徵。維護集群地址的設置被稱為負載均衡器。
負載均衡器內部負責管理各個服務實體的加入和退出,外部負責集群地址向內部服務實體地址的轉換。
有的負載均衡器實現真正的負載均衡算法,有的只支持任務的轉換。
只實現任務轉換的負載均衡器適用于支持ACTIVE-STANDBY的集群環境,在那裏,集群中只有一個服務實體工作,
當正在工作的服務實體發生故障時,負載均衡器把後來的任務轉向另外一個服務實體。
內部通信--為了能協同工作、實現負載均衡和錯誤恢復,集群各實體間必須時常通信,比如負載均衡器對服務實體心跳測試信息、服務實體間任務執行上下文信息的通信。
5.集群配置
從上圖可知,由服務實體1、服務實體2和負載均衡器組成了一個集群。服務實體1和服務實體2參與對客戶端的服務支持工作,均衡負載器為客戶端維護集群的單一影像。
集群實體間通過內部的通信網交流信息,這種交流機制一般采用組播協議。負載均衡器通過內部通信網探測各服務實體的心跳信息,服
務實體間通過內部通信網完成任務資源的傳播。可以看出,配置集群主要由配置服務實體和配置負載均衡器兩部分組成。本文使用tomcat6、apache2.2配置集群環境。
6.準備軟件
tomcat是開源服務器,本文使用的apache-tomcat-6.0.18.zip;
apache是開源的www服務器,本文使用的是apache_2.2.14-win32-x86-openssl-0.9.8k.msi;
jk,它是Tomcat-Apache插件,處理Tomcat和Apache之間的通信,在集群配置中充當負載均衡器的作用,本文使用的是mod_jk-1.2.28-httpd-2.2.3.so。
7.安裝apache服務器
選擇默認配置即可,安裝完成后,輸入http://ip:80,打開頁面顯示Itworks表示安裝成功,不成功,有時可能80端口被其他應用占用,
可修改apache安裝目錄\conf\httpd.conf文件端口配置,如下文件修改端口配置為81(ip為apache服務器安裝的主機ip地址)
如果端口為80,訪問時可不輸入端口,非80端口時,訪問需要輸入端口,如端口為80訪問時,訪問地址為:http://ip,端口非80端口,如為81,訪問地址:http://ip:81
8.安裝Tomcat
安裝兩個Tomat(tomcat1,tomcat2),如果兩個tomcat在同一臺電腦上,需要修改conf/server.xml配置文件相關端口,使其不重復;
Server默認端口8005:如tomcat1修改為8105,tomcat2修改為8205;
Connect(Http協議)默認端口8080,如修改為8180,8280;
Connect(Ajp協議)默認端口8009,如修改為8109,8209。
安裝后tomcat修改完配置文件啟動Tomcat,可分別訪問兩個Tomcat,測試是否訪問正常。
9.配置jk(1)
復制jk文件到apache安裝目錄的modules目錄下,重命名為
mod-jk.so;
在apache安裝目錄找到conf/httpd.conf文件,添加jk的配置
#(httpd.conf)
LoadModulejk_modulemodules/mod_jk.so
JkWorkersFileconf/workers.properties
JkMountFileconf/uriworkermap.properties
JkLogFilelogs/mod_jk.log
JkLogLevelwarn
10配置jk(2)
workers.properties轉發服務器配置,配置可以轉發的主機
worker.list=DLOG4J,status
worker.tomcat1.port=8109
worker.tomcat1.host=192.168.4.37
worker.tomcat1.type=ajp13
worker.tomcat2.port=8209
worker.tomcat2.host=192.168.4.37
worker.tomcat2.type=ajp13
worker.DLOG4J.type=lb
worker.retries=3
worker.DLOG4J.balanced_workers=tomcat1,tomcat2
worker.status.type=status
11配置jk(3)
uriworkermap.properties轉發規則配置,配置那些請求需要轉發到服務器。
/*=DLOG4J
/jkstatus=status
!/*.gif=DLOG4J
!/*.jpg=DLOG4J
!/*.png=DLOG4J
!/*.css=DLOG4J
!/*.js=DLOG4J
!/*.htm=DLOG4J
!/*.html=DLOG4J
jk的詳細參數信息及配置請參考jk的文檔
12.測試
所有安裝與配置完成后,在兩個tomat下分別部署一個工程名相同的工程,工程可不同,啟動tomcat與apache服務,
訪問http://ip:81/projectname(81改為apache端口,projectname對應工程名),可發現不同電腦訪問到了不同的tomcat服務器。
上面的配置還不完善,在使用session的工程里,測試時發現會出現session丟失,那是因為一個客戶端的請求被發送到不同的tomcat去了,所以還需要在tomcat中配置session復制。
13.session復制(1)
在tomcat安裝目錄找到conf/server.xml,找到
<Enginename=“Catalina”defaultHost=“localhost”>修改為
<Enginename=“Catalina”defaultHost=“localhost”jvmRoute="tomcat1">
去掉server.xml<Cluster><\Cluster>的注釋符,進行配置,具體可參考tomcat說明文檔
http://ip/8080/docs/cluster-howto.html
http://ip/8080/docs/config/cluster.html
(注意如果兩個tomcat在同一電腦上時,需要修改4000端口,端口訪問為4000-4100)
確認兩個工程下部署的工程中web.xml有是相同的工程描述信息如<display-name>TomcatDemo</display-name>
如果都配置好了,重新啟動tomcat與apache,驗證是否session復制成功了。
14.session復制(2)
在tomcat安裝目錄找到conf/server.xml,找到
<Enginename=“Catalina”defaultHost=“localhost”>修改為
<Enginename=“Catalina”defaultHost=“localhost”jvmRoute=“tomcat1”>;
去掉server.xml<Cluster><\Cluster>的注釋符,進行配置,具體可參考tomcat說明文檔,下頁有一示例配置;
http://ip/8080/docs/cluster-howto.html
http://ip/8080/docs/config/cluster.html
確認兩個工程下部署的工程中web.xml有是相同的工程描述信息如<display-name>TomcatDemo</display-name>;
如果都配置好了,重新啟動tomcat與apache,驗證是否session復制成功了。
15tomcat文件server.xml<Cluster></Cluster>集群配置示例:
(注意如果兩個tomcat在同一電腦上時,需要修改4000端口,端口訪問為4000-4100),還需要修改其中的ip地址192.168.4.37為對應apache地址)
參見Add部分
16.QA
對部署工程的要求
session復制,session中屬性必須繼承序列化接口(java.io.Serializable)
文件等存放地址與tomcat服務器地址無關,最好放在FTP地址
Add:
1.Z:\ApacheSOA\Apache+Tomcat集群下:
1.1mod_jk.so
1.2uriworkermap.properties
/*=DLOG4J
/jkstatus=status
1.3workers.properties
#
#workers.properties
#
#listtheworkersbyname
worker.list=DLOG4J,status
#localhostserver1
#------------------------
worker.s1.port=8109
worker.s1.host=192.168.1.10
worker.s1.type=ajp13
#localhostserver2
#------------------------
worker.s2.port=8209
worker.s2.host=192.168.1.10
worker.s2.type=ajp13
worker.DLOG4J.type=lb
worker.retries=3
worker.DLOG4J.balanced_workers=s1,s2
worker.tomcatlb.sticky_session=1
worker.status.type=status
1.4httpd.conf
#
#ThisisthemainApacheHTTPserverconfigurationfile.Itcontainsthe
#configurationdirectivesthatgivetheserveritsinstructions.
#See<URL:http://httpd.apache.org/docs/2.2>fordetailedinformation.
#Inparticular,see
#<URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
#foradiscussionofeachconfigurationdirective.
#
#DoNOTsimplyreadtheinstructionsinherewithoutunderstanding
#whattheydo.They'rehereonlyashintsorreminders.Ifyouareunsure
#consulttheonlinedocs.Youhavebeenwarned.
#
#Configurationandlogfilenames:Ifthefilenamesyouspecifyformany
#oftheserver'scontrolfilesbeginwith"/"(or"drive:/"forWin32),the
#serverwillusethatexplicitpath.Ifthefilenamesdo*not*begin
#with"/",thevalueofServerRootisprepended--so"logs/foo.log"
#withServerRootsetto"C:/Apache/apache-http-server-2.2.14"willbeinterpretedbythe
#serveras"C:/Apache/apache-http-server-2.2.14/logs/foo.log".
#
#NOTE:Wherefilenamesarespecified,youmustuseforwardslashes
#insteadofbackslashes(e.g.,"c:/apache"insteadof"c:\apache").
#Ifadriveletterisomitted,thedriveonwhichhttpd.exeislocated
#willbeusedbydefault.Itisrecommendedthatyoualwayssupply
#anexplicitdriveletterinabsolutepathstoavoidconfusion.
#
#ServerRoot:Thetopofthedirectorytreeunderwhichtheserver's
#configuration,error,andlogfilesarekept.
#
#Donotaddaslashattheendofthedirectorypath.Ifyoupoint
#ServerRootatanon-localdisk,besuretopointtheLockFiledirective
#atalocaldisk.IfyouwishtosharethesameServerRootformultiple
#httpddaemons,youwillneedtochangeatleastLockFileandPidFile.
#
ServerRoot"C:/Apache/apache-http-server-2.2.14"
#
#Listen:AllowsyoutobindApachetospecificIPaddressesand/or
#ports,insteadofthedefault.Seealsothe<VirtualHost>
#directive.
#
#ChangethistoListenonspecificIPaddressesasshownbelowto
#preventApachefromglommingontoallboundIPaddresses.
#
#Listen12.34.56.78:80
Listen81
#
#DynamicSharedObject(DSO)Support
#
#TobeabletousethefunctionalityofamodulewhichwasbuiltasaDSOyou
#havetoplacecorresponding`LoadModule'linesatthislocationsothe
#directivescontainedinitareactuallyavailable_before_theyareused.
#Staticallycompiledmodules(thoselistedby`httpd-l')donotneed
#tobeloadedhere.
#
#Example:
#LoadModulefoo_modulemodules/mod_foo.so
#
LoadModuleactions_modulemodules/mod_actions.so
LoadModulealias_modulemodules/mod_alias.so
LoadModuleasis_modulemodules/mod_asis.so
LoadModuleauth_basic_modulemodules/mod_auth_basic.so
#LoadModuleauth_digest_modulemodules/mod_auth_digest.so
#LoadModuleauthn_alias_modulemodules/mod_authn_alias.so
#LoadModuleauthn_anon_modulemodules/mod_authn_anon.so
#LoadModuleauthn_dbd_modulemodules/mod_authn_dbd.so
#LoadModuleauthn_dbm_modulemodules/mod_authn_dbm.so
LoadModuleauthn_default_modulemodules/mod_authn_default.so
LoadModuleauthn_file_modulemodules/mod_authn_file.so
#LoadModuleauthnz_ldap_modulemodules/mod_authnz_ldap.so
#LoadModuleauthz_dbm_modulemodules/mod_authz_dbm.so
LoadModuleauthz_default_modulemodules/mod_authz_default.so
LoadModuleauthz_groupfile_modulemodules/mod_authz_groupfile.so
LoadModuleauthz_host_modulemodules/mod_authz_host.so
#LoadModuleauthz_owner_modulemodules/mod_authz_owner.so
LoadModuleauthz_user_modulemodules/mod_authz_user.so
LoadModuleautoindex_modulemodules/mod_autoindex.so
#LoadModulecache_modulemodules/mod_cache.so
#LoadModulecern_meta_modulemodules/mod_cern_meta.so
LoadModulecgi_modulemodules/mod_cgi.so
#LoadModulecharset_lite_modulemodules/mod_charset_lite.so
#LoadModuledav_modulemodules/mod_dav.so
#LoadModuledav_fs_modulemodules/mod_dav_fs.so
#LoadModuledav_lock_modulemodules/mod_dav_lock.so
#LoadModuledbd_modulemodules/mod_dbd.so
#LoadModuledeflate_modulemodules/mod_deflate.so
LoadModuledir_modulemodules/mod_dir.so
#LoadModuledisk_cache_modulemodules/mod_disk_cache.so
#LoadModuledumpio_modulemodules/mod_dumpio.so
LoadModuleenv_modulemodules/mod_env.so
#LoadModuleexpires_modulemodules/mod_expires.so
#LoadModuleext_filter_modulemodules/mod_ext_filter.so
#LoadModulefile_cache_modulemodules/mod_file_cache.so
#LoadModulefilter_modulemodules/mod_filter.so
#LoadModuleheaders_modulemodules/mod_headers.so
#LoadModuleident_modulemodules/mod_ident.so
#LoadModuleimagemap_modulemodules/mod_imagemap.so
LoadModuleinclude_modulemodules/mod_include.so
#LoadModuleinfo_modulemodules/mod_info.so
LoadModuleisapi_modulemodules/mod_isapi.so
#LoadModuleldap_modulemodules/mod_ldap.so
#LoadModulelogio_modulemodules/mod_logio.so
LoadModulelog_config_modulemodules/mod_log_config.so
#LoadModulelog_forensic_modulemodules/mod_log_forensic.so
#LoadModulemem_cache_modulemodules/mod_mem_cache.so
LoadModulemime_modulemodules/mod_mime.so
#LoadModulemime_magic_modulemodules/mod_mime_magic.so
LoadModulenegotiation_modulemodules/mod_negotiation.so
#LoadModuleproxy_modulemodules/mod_proxy.so
#LoadModuleproxy_ajp_modulemodules/mod_proxy_ajp.so
#LoadModuleproxy_balancer_modulemodules/mod_proxy_balancer.so
#LoadModuleproxy_connect_modulemodules/mod_proxy_connect.so
#LoadModuleproxy_ftp_modulemodules/mod_proxy_ftp.so
#LoadModuleproxy_http_modulemodules/mod_proxy_http.so
#LoadModulerewrite_modulemodules/mod_rewrite.so
LoadModulesetenvif_modulemodules/mod_setenvif.so
#LoadModulespeling_modulemodules/mod_speling.so
#LoadModulessl_modulemodules/mod_ssl.so
#LoadModulestatus_modulemodules/mod_status.so
#LoadModulesubstitute_modulemodules/mod_substitute.so
#LoadModuleunique_id_modulemodules/mod_unique_id.so
#LoadModuleuserdir_modulemodules/mod_userdir.so
#LoadModuleusertrack_modulemodules/mod_usertrack.so
#LoadModuleversion_modulemodules/mod_version.so
#LoadModulevhost_alias_modulemodules/mod_vhost_alias.so
<IfModule!mpm_netware_module>
<IfModule!mpm_winnt_module>
#
#Ifyouwishhttpdtorunasadifferentuserorgroup,youmustrun
#httpdasrootinitiallyanditwillswitch.
#
#User/Group:Thename(or#number)oftheuser/grouptorunhttpdas.
#Itisusuallygoodpracticetocreateadedicateduserandgroupfor
#runninghttpd,aswithmostsystemservices.
#
Userdaemon
Groupdaemon
</IfModule>
</IfModule>
#'Main'serverconfiguration
#
#Thedirectivesinthissectionsetupthevaluesusedbythe'main'
#server,whichrespondstoanyrequeststhataren'thandledbya
#<VirtualHost>definition.Thesevaluesalsoprovidedefaultsfor
#any<VirtualHost>containersyoumaydefinelaterinthefile.
#
#Allofthesedirectivesmayappearinside<VirtualHost>containers,
#inwhichcasethesedefaultsettingswillbeoverriddenforthe
#virtualhostbeingdefined.
#
#
#ServerAdmin:Youraddress,whereproblemswiththeservershouldbe
#e-mailed.Thisaddressappearsonsomeserver-generatedpages,such
#
#
#ServerNamegivesthenameandportthattheserverusestoidentifyitself.
#Thiscanoftenbedeterminedautomatically,butwerecommendyouspecify
#itexplicitlytopreventproblemsduringstartup.
#
#Ifyourhostdoesn'thavearegisteredDNSname,enteritsIPaddresshere.
#
#ServerNameFSC-TS-010.FSC.NJ.com:8080
#
#DocumentRoot:Thedirectoryoutofwhichyouwillserveyour
#documents.Bydefault,allrequestsaretakenfromthisdirectory,but
#symboliclinksandaliasesmaybeusedtopointtootherlocations.
#
DocumentRoot"C:/Apache/apache-http-server-2.2.14/htdocs"
#
#EachdirectorytowhichApachehasaccesscanbeconfiguredwithrespect
#towhichservicesandfeaturesareallowedand/ordisabledinthat
#directory(anditssubdirectories).
#
#First,weconfigurethe"default"tobeaveryrestrictivesetof
#features.
#
<Directory/>
OptionsFollowSymLinks
AllowOverrideNone
Orderdeny,allow
Denyfromall
</Directory>
#
#Notethatfromthispointforwardyoumustspecificallyallow
#particularfeaturestobeenabled-soifsomething'snotworkingas
#youmightexpect,makesurethatyouhavespecificallyenabledit
#below.
#
#
#ThisshouldbechangedtowhateveryousetDocumentRootto.
#
<Directory"C:/Apache/apache-http-server-2.2.14/htdocs">
#
#PossiblevaluesfortheOptionsdirectiveare"None","All",
#oranycombinationof:
#IndexesIncludesFollowSymLinksSymLinksifOwnerMatchExecCGIMultiViews
#
#Notethat"MultiViews"mustbenamed*explicitly*---"OptionsAll"
#doesn'tgiveittoyou.
#
#TheOptionsdirectiveisbothcomplicatedandimportant.Pleasesee
#http://httpd.apache.org/docs/2.2/mod/core.html#options
#formoreinformation.
#
OptionsIndexesFollowSymLinks
#
#AllowOverridecontrolswhatdirectivesmaybeplacedin.htaccessfiles.
#Itcanbe"All","None",oranycombinationofthekeywords:
#OptionsFileInfoAuthConfigLimit
#
AllowOverrideNone
#
#Controlswhocangetstufffromthisserver.
#
Orderallow,deny
Allowfromall
</Directory>
#
#DirectoryIndex:setsthefilethatApachewillserveifadirectory
#isrequested.
#
<IfModuledir_module>
DirectoryIndexindex.html
</IfModule>
#
#Thefollowinglinesprevent.htaccessand.htpasswdfilesfrombeing
#viewedbyWebclients.
#
<FilesMatch"^\.ht">
Orderallow,deny
Denyfromall
SatisfyAll
</FilesMatch>
#
#ErrorLog:Thelocationoftheerrorlogfile.
#IfyoudonotspecifyanErrorLogdirectivewithina<VirtualHost>
#container,errormessagesrelatingtothatvirtualhostwillbe
#loggedhere.Ifyou*do*defineanerrorlogfilefora<VirtualHost>
#container,thathost'serrorswillbeloggedthereandnothere.
#
ErrorLog"logs/error.log"
#
#LogLevel:Controlthenumberofmessagesloggedtotheerror_log.
#Possiblevaluesinclude:debug,info,notice,warn,error,crit,
#alert,emerg.
#
LogLevelwarn
<IfModulelog_config_module>
#
#Thefollowingdirectivesdefinesomeformatnicknamesforusewith
#aCustomLogdirective(seebelow).
#
LogFormat"%h%l%u%t\"%r\"%>s%b\"%{Referer}i\"\"%{User-Agent}i\""combined
LogFormat"%h%l%u%t\"%r\"%>s%b"common
<IfModulelogio_module>
#Youneedtoenablemod_logio.ctouse%Iand%O
LogFormat"%h%l%u%t\"%r\"%>s%b\"%{Referer}i\"\"%{User-Agent}i\"%I%O"combinedio
</IfModule>
#
#Thelocationandformatoftheaccesslogfile(CommonLogfileFormat).
#Ifyoudonotdefineanyaccesslogfileswithina<VirtualHost>
#container,theywillbeloggedhere.Contrariwise,ifyou*do*
#defineper-<VirtualHost>accesslogfiles,transactionswillbe
#loggedthereinand*not*inthisfile.
#
CustomLog"logs/access.log"common
#
#Ifyoupreferalogfilewithaccess,agent,andrefererinformation
#(CombinedLogfileFormat)youcanusethefollowingdirective.
#
#CustomLog"logs/access.log"combined
</IfModule>
<IfModulealias_module>
#
#Redirect:Allowsyoutotellclientsaboutdocumentsthatusedto
#existinyourserver'snamespace,butdonotanymore.Theclient
#willmakeanewrequestforthedocumentatitsnewlocation.
#Example:
#Redirectpermanent/foohttp://FSC-TS-010.FSC.NJ.com/bar
#
#Alias:Mapswebpathsintofilesystempathsandisusedto
#accesscontentthatdoesnotliveundertheDocumentRoot.
#Example:
#Alias/webpath/full/filesystem/path
#
#Ifyouincludeatrailing/on/webpaththentheserverwill
#requireittobepresentintheURL.Youwillalsolikely
#needtoprovidea<Directory>sectiontoallowaccessto
#thefilesystempath.
#
#ScriptAlias:Thiscontrolswhichdirectoriescontainserverscripts.
#ScriptAliasesareessentiallythesameasAliases,exceptthat
#documentsinthetargetdirectoryaretreatedasapplicationsand
#runbytheserverwhenrequestedratherthanasdocumentssenttothe
#client.Thesamerulesabouttrailing"/"applytoScriptAlias
#directivesastoAlias.
#
ScriptAlias/cgi-bin/"C:/Apache/apache-http-server-2.2.14/cgi-bin/"
</IfModule>
<IfModulecgid_module>
#
#ScriptSock:Onthreadedservers,designatethepathtotheUNIX
#socketusedtocommunicatewiththeCGIdaemonofmod_cgid.
#
#Scriptsocklogs/cgisock
</IfModule>
#
#"C:/Apache/apache-http-server-2.2.14/cgi-bin"shouldbechangedtowhateveryourScriptAliased
#CGIdirectoryexists,ifyouhavethatconfigured.
#
<Directory"C:/Apache/apache-http-server-2.2.14/cgi-bin">
AllowOverrideNone
OptionsNone
Orderallow,deny
Allowfromall
</Directory>
#
#DefaultType:thedefaultMIMEtypetheserverwilluseforadocument
#ifitcannototherwisedetermineone,suchasfromfilenameextensions.
#IfyourservercontainsmostlytextorHTMLdocuments,"text/plain"is
#agoodvalue.Ifmostofyourcontentisbinary,suchasapplications
#orimages,youmaywanttouse"application/octet-stream"insteadto
#keepbrowsersfromtryingtodisplaybinaryfilesasthoughtheyare
#text.
#
DefaultTypetext/plain
<IfModulemime_module>
#
#TypesConfigpointstothefilecontainingthelistofmappingsfrom
#filenameextensiontoMIME-type.
#
TypesConfigconf/mime.types
#
#AddTypeallowsyoutoaddtooroverridetheMIMEconfiguration
#filespecifiedinTypesConfigforspecificfiletypes.
#
#AddTypeapplication/x-gzip.tgz
#
#AddEncodingallowsyoutohavecertainbrowsersuncompress
#informationonthefly.Note:Notallbrowserssupportthis.
#
#AddEncodingx-compress.Z
#AddEncodingx-gzip.gz.tgz
#
#IftheAddEncodingdirectivesabovearecommented-out,thenyou
#probablyshoulddefinethoseextensionstoindicatemediatypes:
#
AddTypeapplication/x-compress.Z
AddTypeapplication/x-gzip.gz.tgz
#
#AddHandlerallowsyoutomapcertainfileextensionsto"handlers":
#actionsunrelatedtofiletype.Thesecanbeeitherbuiltintotheserver
#oraddedwiththeActiondirective(seebelow)
#
#TouseCGIscriptsoutsideofScriptAliaseddirectories:
#(Youwillalsoneedtoadd"ExecCGI"tothe"Options"directive.)
#
#AddHandlercgi-script.cgi
#Fortypemaps(negotiatedresources):
#AddHandlertype-mapvar
#
#Filtersallowyoutoprocesscontentbeforeitissenttotheclient.
#
#Toparse.shtmlfilesforserver-sideincludes(SSI):
#(Youwillalsoneedtoadd"Includes"tothe"Options"directive.)
#
#AddTypetext/html.shtml
#AddOutputFilterINCLUDES.shtml
</IfModule>
#
#Themod_mime_magicmoduleallowstheservertousevarioushintsfromthe
#contentsofthefileitselftodetermineitstype.TheMIMEMagicFile
#directivetellsthemodulewherethehintdefinitionsarelocated.
#
#MIMEMagicFileconf/magic
#
#Customizableerrorresponsescomeinthreeflavors:
#1)plaintext2)localredirects3)externalredirects
#
#Someexamples:
#ErrorDocument500"Theservermadeabooboo."
#ErrorDocument404/missing.html
#ErrorDocument404"/cgi-bin/missing_handler.pl"
#ErrorDocument402http://FSC-TS-010.FSC.NJ.com/subscription_info.html
#
#
#EnableMMAPandEnableSendfile:Onsystemsthatsupportit,
#memory-mappingorthesendfilesyscallisusedtodeliver
#files.Thisusuallyimprovesserverperformance,butmust
#beturnedoffwhenservingfromnetworked-mounted
#filesystemsorifsupportforthesefunctionsisotherwise
#brokenonyoursystem.
#
#EnableMMAPoff
#EnableSendfileoff
#Supplementalconfiguration
#
#Theconfigurationfilesintheconf/extra/directorycanbe
#includedtoaddextrafeaturesortomodifythedefaultconfigurationof
#theserver,oryoumaysimplycopytheircontentshereandchangeas
#necessary.
#Server-poolmanagement(MPMspecific)
#Includeconf/extra/httpd-mpm.conf
#Multi-languageerrormessages
#Includeconf/extra/httpd-multilang-errordoc.conf
#Fancydirectorylistings
#Includeconf/extra/httpd-autoindex.conf
#Languagesettings
#Includeconf/extra/httpd-languages.conf
#Userhomedirectories
#Includeconf/extra/httpd-userdir.conf
#Real-timeinfoonrequestsandconfiguration
#Includeconf/extra/httpd-info.conf
#Virtualhosts
#Includeconf/extra/httpd-vhosts.conf
#LocalaccesstotheApacheHTTPServerManual
#Includeconf/extra/httpd-manual.conf
#Distributedauthoringandversioning(WebDAV)
#Includeconf/extra/httpd-dav.conf
#Variousdefaultsettings
#Includeconf/extra/httpd-default.conf
#Secure(SSL/TLS)connections
#Includeconf/extra/httpd-ssl.conf
#
#Note:Thefollowingmustmustbepresenttosupport
#startingwithoutSSLonplatformswithno/dev/randomequivalent
#butastaticallycompiled-inmod_ssl.
#
<IfModulessl_module>
SSLRandomSeedstartupbuiltin
SSLRandomSeedconnectbuiltin
</IfModule>
#(httpd.conf)
#Configuremod_jk
LoadModulejk_modulemodules/mod_jk.so
JkWorkersFileconf/workers.properties
JkMountFileconf/uriworkermap.properties
JkLogFilelogs/mod_jk.log
JkLogLevelwarn
2Tomcat1下:
2.1server.xml
<?xmlversion='1.0'encoding='utf-8'?>
<!--
LicensedtotheApacheSoftwareFoundation(ASF)underoneormore
contributorlicenseagreements.SeetheNOTICEfiledistributedwith
thisworkforadditionalinformationregardingcopyrightownership.
TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0
(the"License");youmaynotusethisfileexceptincompliancewith
theLicense.YoumayobtainacopyoftheLicenseat
http://www.apache.org/licenses/LICENSE-2.0
Unlessrequiredbyapplicablelaworagreedtoinwriting,software
distributedundertheLicenseisdistributedonan"ASIS"BASIS,
WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
SeetheLicenseforthespecificlanguagegoverningpermissionsand
limitationsundertheLicense.
-->
<!--Note:A"Server"isnotitselfa"Container",soyoumaynot
definesubcomponentssuchas"Valves"atthislevel.
Documentationat/docs/config/server.html
-->
<Serverport="8105"shutdown="SHUTDOWN">
<!--APRlibraryloader.Documentationat/docs/apr.html-->
<Listenerclassname="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on"/>
<!--InitializeJasperpriortowebappsareloaded.Documentationat/docs/jasper-howto.html-->
<Listenerclassname="org.apache.catalina.core.JasperListener"/>
<!--JMXSupportfortheTomcatserver.Documentationat/docs/non-existent.html-->
<Listenerclassname="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listenerclassname="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<!--GlobalJNDIresources
Documentationat/docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!--Editableuserdatabasethatcanalsobeusedby
UserDatabaseRealmtoauthenticateusers
-->
<Resourcename="UserDatabase"auth="Container"
type="org.apache.catalina.UserDatabase"
description="Userdatabasethatcanbeupdatedandsaved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
<!--A"Service"isacollectionofoneormore"Connectors"thatshare
asingle"Container"Note:A"Service"isnotitselfa"Container",
soyoumaynotdefinesubcomponentssuchas"Valves"atthislevel.
Documentationat/docs/config/service.html
-->
<Servicename="Catalina">
<!--Theconnectorscanuseasharedexecutor,youcandefineoneormorenamedthreadpools-->
<!--
<Executorname="tomcatThreadPool"namePrefix="catalina-exec-"
maxThreads="150"minSpareThreads="4"/>
-->
<!--A"Connector"representsanendpointbywhichrequestsarereceived
andresponsesarereturned.Documentationat:
JavaHTTPConnector:/docs/config/http.html(blocking&non-blocking)
JavaAJPConnector:/docs/config/ajp.html
APR(HTTP/AJP)Connector:/docs/apr.html
Defineanon-SSLHTTP/1.1Connectoronport8080
-->
<Connectorport="8180"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<!--A"Connector"usingthesharedthreadpool-->
<!--
<Connectorexecutor="tomcatThreadPool"
port="8080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
-->
<!--DefineaSSLHTTP/1.1Connectoronport8443
ThisconnectorusestheJSSEconfiguration,whenusingAPR,the
connectorshouldbeusingtheOpenSSLstyleconfiguration
describedintheAPRdocumentation-->
<!--
<Connectorport="8443"protocol="HTTP/1.1"SSLEnabled="true"
maxThreads="150"scheme="https"secure="true"
clientAuth="false"sslProtocol="TLS"/>
-->
<!--DefineanAJP1.3Connectoronport8009-->
<Connectorport="8109"protocol="AJP/1.3"redirectPort="8443"/>
<!--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesses
everyrequest.TheEngineimplementationforTomcatstandalone
analyzestheHTTPheadersincludedwiththerequest,andpassesthem
ontotheappropriateHost(virtualhost).
Documentationat/docs/config/engine.html-->
<!--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:
<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm1">
-->
<Enginename="Catalina"defaultHost="localhost"jvmRoute="s1">
<!--Forclustering,pleasetakealookatdocumentationat:
/docs/cluster-howto.html(simplehowto)
/docs/config/cluster.html(referencedocumentation)-->
<!--
<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Managerclassname="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channelclassname="org.apache.catalina.tribes.group.GroupChannel">
<Membershipclassname="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiverclassname="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="192.168.1.10"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Senderclassname="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transportclassname="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valveclassname="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valveclassname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployerclassname="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListenerclassname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListenerclassname="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<!--Therequestdumpervalvedumpsusefuldebugginginformationabout
therequestandresponsedatareceivedandsentbyTomcat.
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDI
resourcesunderthekey"UserDatabase".Anyedits
thatareperformedagainstthisUserDatabaseareimmediately
availableforusebytheRealm.-->
<Realmclassname="org.apache.catalina.realm.UserDatabaseRealm"
resourcename="UserDatabase"/>
<!--Definethedefaultvirtualhost
Note:XMLSchemavalidationwillnotworkwithXerces2.2.
-->
<Hostname="localhost"appBase="webapps"
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<!--SingleSignOnvalve,shareauthenticationbetweenwebapplications
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.authenticator.SingleSignOn"/>
-->
<!--Accesslogprocessesallexample.
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.valves.AccessLogValve"directory="logs"
prefix="localhost_access_log."suffix=".txt"pattern="common"resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
2.2tomcat-users.xml
<?xmlversion='1.0'encoding='utf-8'?>
<tomcat-users>
<rolerolename="manager"/>
<userusername="tomcat"password="tomcat"roles="manager"/>
</tomcat-users>
2.3Z:\ApacheSOA\Apache+Tomcat集群\AT5\ApcheTomcat下:
index.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="BIG5"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<%
System.out.println("===============A5============");
System.out.println("session:"+session.getAttribute("test"));
System.out.println("nowDate:"+newDate());
System.out.println();
%>
<body>
<h1style="color:red">
JSP2.0Examples-HelloWorldSimpleTagHandler
</h1>
</body>
</html>
web.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name>ApacheTomcat</display-name>
<distributable/>
</web-app>
3.Tomcat2下:
3.1server.xml
<?xmlversion='1.0'encoding='utf-8'?>
<!--
LicensedtotheApacheSoftwareFoundation(ASF)underoneormore
contributorlicenseagreements.SeetheNOTICEfiledistributedwith
thisworkforadditionalinformationregardingcopyrightownership.
TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0
(the"License");youmaynotusethisfileexceptincompliancewith
theLicense.YoumayobtainacopyoftheLicenseat
http://www.apache.org/licenses/LICENSE-2.0
Unlessrequiredbyapplicablelaworagreedtoinwriting,software
distributedundertheLicenseisdistributedonan"ASIS"BASIS,
WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
SeetheLicenseforthespecificlanguagegoverningpermissionsand
limitationsundertheLicense.
-->
<!--Note:A"Server"isnotitselfa"Container",soyoumaynot
definesubcomponentssuchas"Valves"atthislevel.
Documentationat/docs/config/server.html
-->
<Serverport="8205"shutdown="SHUTDOWN">
<!--APRlibraryloader.Documentationat/docs/apr.html-->
<Listenerclassname="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on"/>
<!--InitializeJasperpriortowebappsareloaded.Documentationat/docs/jasper-howto.html-->
<Listenerclassname="org.apache.catalina.core.JasperListener"/>
<!--JMXSupportfortheTomcatserver.Documentationat/docs/non-existent.html-->
<Listenerclassname="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listenerclassname="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<!--GlobalJNDIresources
Documentationat/docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!--Editableuserdatabasethatcanalsobeusedby
UserDatabaseRealmtoauthenticateusers
-->
<Resourcename="UserDatabase"auth="Container"
type="org.apache.catalina.UserDatabase"
description="Userdatabasethatcanbeupdatedandsaved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
<!--A"Service"isacollectionofoneormore"Connectors"thatshare
asingle"Container"Note:A"Service"isnotitselfa"Container",
soyoumaynotdefinesubcomponentssuchas"Valves"atthislevel.
Documentationat/docs/config/service.html
-->
<Servicename="Catalina">
<!--Theconnectorscanuseasharedexecutor,youcandefineoneormorenamedthreadpools-->
<!--
<Executorname="tomcatThreadPool"namePrefix="catalina-exec-"
maxThreads="150"minSpareThreads="4"/>
-->
<!--A"Connector"representsanendpointbywhichrequestsarereceived
andresponsesarereturned.Documentationat:
JavaHTTPConnector:/docs/config/http.html(blocking&non-blocking)
JavaAJPConnector:/docs/config/ajp.html
APR(HTTP/AJP)Connector:/docs/apr.html
Defineanon-SSLHTTP/1.1Connectoronport8080
-->
<Connectorport="8280"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
<!--A"Connector"usingthesharedthreadpool-->
<!--
<Connectorexecutor="tomcatThreadPool"
port="8080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
-->
<!--DefineaSSLHTTP/1.1Connectoronport8443
ThisconnectorusestheJSSEconfiguration,whenusingAPR,the
connectorshouldbeusingtheOpenSSLstyleconfiguration
describedintheAPRdocumentation-->
<!--
<Connectorport="8443"protocol="HTTP/1.1"SSLEnabled="true"
maxThreads="150"scheme="https"secure="true"
clientAuth="false"sslProtocol="TLS"/>
-->
<!--DefineanAJP1.3Connectoronport8009-->
<Connectorport="8209"protocol="AJP/1.3"redirectPort="8443"/>
<!--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesses
everyrequest.TheEngineimplementationforTomcatstandalone
analyzestheHTTPheadersincludedwiththerequest,andpassesthem
ontotheappropriateHost(virtualhost).
Documentationat/docs/config/engine.html-->
<!--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:
<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm1">
-->
<Enginename="Catalina"defaultHost="localhost"jvmRoute="s1">
<!--Forclustering,pleasetakealookatdocumentationat:
/docs/cluster-howto.html(simplehowto)
/docs/config/cluster.html(referencedocumentation)-->
<!--
<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<Clusterclassname="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Managerclassname="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channelclassname="org.apache.catalina.tribes.group.GroupChannel">
<Membershipclassname="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiverclassname="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="192.168.1.10"
port="4001"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Senderclassname="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transportclassname="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptorclassname="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valveclassname="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valveclassname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployerclassname="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListenerclassname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListenerclassname="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
<!--Therequestdumpervalvedumpsusefuldebugginginformationabout
therequestandresponsedatareceivedandsentbyTomcat.
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDI
resourcesunderthekey"UserDatabase".Anyedits
thatareperformedagainstthisUserDatabaseareimmediately
availableforusebytheRealm.-->
<Realmclassname="org.apache.catalina.realm.UserDatabaseRealm"
resourcename="UserDatabase"/>
<!--Definethedefaultvirtualhost
Note:XMLSchemavalidationwillnotworkwithXerces2.2.
-->
<Hostname="localhost"appBase="webapps"
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
<!--SingleSignOnvalve,shareauthenticationbetweenwebapplications
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.authenticator.SingleSignOn"/>
-->
<!--Accesslogprocessesallexample.
Documentationat:/docs/config/valve.html-->
<!--
<Valveclassname="org.apache.catalina.valves.AccessLogValve"directory="logs"
prefix="localhost_access_log."suffix=".txt"pattern="common"resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
3.2tomcat-users.xml
<?xmlversion='1.0'encoding='utf-8'?>
<tomcat-users>
<rolerolename="manager"/>
<userusername="tomcat"password="tomcat"roles="manager"/>
</tomcat-users>
3.3Z:\ApacheSOA\Apache+Tomcat集群\AT6\ApcheTomcat下:
3.3.1index.jsp
<%@pagelanguage="java"import="java.util.*"pageEncoding="BIG5"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<%
System.out.println("===============A5============");
System.out.println("session:"+session.getAttribute("test"));
session.setAttribute("test","session");
System.out.println("nowDate:"+newDate());
System.out.println();
%>
<body>
<h1style="color:blue">
JSP2.0Examples-HelloWorldSimpleTagHandler
</h1>
</body>
</html>
3.3.2web.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name>ApacheTomcat</display-name>
<distributable/>
</web-app>