Tomcat 负载均衡配置win8版.docx
《Tomcat 负载均衡配置win8版.docx》由会员分享,可在线阅读,更多相关《Tomcat 负载均衡配置win8版.docx(17页珍藏版)》请在冰豆网上搜索。
![Tomcat 负载均衡配置win8版.docx](https://file1.bdocx.com/fileroot1/2023-1/29/555c220b-b5b5-464b-b69f-06fe56db7713/555c220b-b5b5-464b-b69f-06fe56db77131.gif)
Tomcat负载均衡配置win8版
Tomcat负载均衡配置win8版
Author朱立超QQ892863218请转载说明来源,如需中的所有资料可以联系我。
致谢:
司丙茂老师,关亚博同学。
当服务器性能较差时,或者服务器访问量较大时,就需要tomcat均衡配置以便于分解服务器压力。
有时可能为了安全起见(我们不能保证我门唯一的tomcat能够保持永不宕机)需要备用tomcat来保证服务器在一个tomcat故障时继续正常运行。
当我们要均衡多个tomcat协调运行时就需要一个controller来做为控制调节器,这个controller就是Aphache服务器。
目前拥有两种方式配置tomcat均衡负载现在列举如下:
方式一:
非jk_mod方式,步骤如下:
1)安装apache服务器:
我这里将服务器安装在:
C:
\ProgramFiles(x86)\ApacheSoftwareFoundation\Apache2.2
注意安装时:
在域名输入框(NetworkDomain、SercverName)请输入你的电脑当前ip,邮箱随意输入合法的即可以,选择框默认:
现异常(25032502)请参见附1)
2)拷贝两份解压版tomcat到本地磁盘,我的拷贝到E:
\,并且命名tomcat1、tomcat2
Tomcat无法启动请参见附2)
配置tomcat内存请参照附3)
3)配置两个tomcat的server.xml参数
Tomcat1配置如下(E:
\tomcat1\conf\server.xml):
xmlversion='1.0'encoding='utf-8'?
>
--
LicesedtotheApacheSoftwareFoundation(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
-->
--APRlibraryloader.Documentationat/docs/apr.html-->
--InitializeJasperpriortowebappsareloaded.Documentationat/docs/jasper-howto.html-->
--Preventmemoryleaksduetouseofparticularjava/javaxAPIs-->
--JMXSupportfortheTomcatserver.Documentationat/docs/non-existent.html-->
--GlobalJNDIresources
Documentationat/docs/jndi-resources-howto.html
-->
--Editableuserdatabasethatcanalsobeusedby
UserDatabaseRealmtoauthenticateusers
-->
type="org.apache.catalina.UserDatabase"
description="Userdatabasethatcanbeupdatedandsaved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml"/>
--A"Service"isacollectionofoneormore"Connectors"thatshare
asingle"Container"Note:
A"Service"isnotitselfa"Container",
soyoumaynotdefinesubcomponentssuchas"Valves"atthislevel.
Documentationat/docs/config/service.html
-->
--Theconnectorscanuseasharedexecutor,youcandefineoneormorenamedthreadpools-->
--
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
-->
--下面是配置连接属性,如果不用连接池请删除executor="tomcatThreadPool"属性当然你可以对照原始server.xml文件删除连接中的多余属性,那些多余属性只是影响连接性能(是否保持最大最小线程数是否压缩等)-->
redirectPort="8443"compression="no"mpressionMinSize="2048"
noCompressionUserAgents="gozilla,traviata"
compressableMimeType="text/html,text/xml,text/css,text/javascript,text/plain"
URIEncoding="utf-8"
enableLookups="false"/>
--A"Connector"usingthesharedthreadpool-->
--下面是配置连接池可以不用下面连接池,但是请删除上面连接的executor="tomcatThreadPool"属性-->
namePrefix="catalina-exec-"
maxThreads="500"
minSpareThreads="30"
maxSpareThreads="50"
maxIdleTime="60000"
keepAliveTimeout="15000"
maxKeepAliveTimeout="200"/>
--DefineaSSLHTTP/1.1Connectoronport8443
ThisconnectorusestheJSSEconfiguration,whenusingAPR,the
connectorshouldbeusingtheOpenSSLstyleconfiguration
describedintheAPRdocumentation-->
--下面配置安全访问协议https这不是必须的,你可以注释掉,当然倘若你注释了它,当浏览器访问安全协议网站时(https)就会出现问题,不过当你打算采用时,你需要配置个人加密安全证书mykey.keystore配置该安全证书请XX搜索,或者参见注释4)-->
protocol="HTTP/1.1"
SSLEnabled="true"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="100"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="conf/mykey.keystore"
keystorePass="111111"/>
--DefineanAJP1.3Connectoronport8009-->
--下面配置的连接用于apache控制器需要连接到该tomcat的地址-->
--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesses
everyrequest.TheEngineimplementationforTomcatstandalone
analyzestheHTTPheadersincludedwiththerequest,andpassesthem
ontotheappropriateHost(virtualhost).
Documentationat/docs/config/engine.html-->
--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:
-->
--下面这行是必须的注意jvmRoute属性请填写我门拷贝改名的tomcat服务器文件夹-->
--Forclustering,pleasetakealookatdocumentationat:
/docs/cluster-howto.html(simplehowto)
/docs/config/cluster.html(referencedocumentation)-->
--下面这行也是必须的用于集成服务,我们采用apache服务器的目的就是集成服务-->
--Therequestdumpervalvedumpsusefuldebugginginformationabout
therequestandresponsedatareceivedandsentbyTomcat.
Documentationat:
/docs/config/valve.html-->
--
-->
--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDI
resourcesunderthekey"UserDatabase".Anyedits
thatareperformedagainstthisUserDatabaseareimmediately
availableforusebytheRealm.-->
--下面这行请保持默认或者打开注释-->
resourceName="UserDatabase"/>
--Definethedefaultvirtualhost
Note:
XMLSchemavalidationwillnotworkwithXerces2.2.
-->
--下面这行请保持默认或者打开注释-->
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
--SingleSignOnvalve,shareauthenticationbetweenwebapplications
Documentationat:
/docs/config/valve.html-->
--
-->
--Accesslogprocessesallexample.
Documentationat:
/docs/config/valve.html-->
--下面这行必须的但是更改他可以提高tomcat日志效率-->
注意:
蓝色部分中的端口配置,tomcat1和tomcat2的配置不同,如果需要可以将本置拷贝到server.xml文件中拷贝时请删除中文注释。
Tomcat1配置如下(E:
\tomcat2\onf\server.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
-->
--APRlibraryloader.Documentationat/docs/apr.html-->
--InitializeJasperpriortowebappsareloaded.Documentationat/docs/jasper-howto.html-->
--Preventmemoryleaksduetouseofparticularjava/javaxAPIs-->
--JMXSupportfortheTomcatserver.Documentationat/docs/non-existent.html-->
--GlobalJNDIresources
Documentationat/docs/jndi-resources-howto.html
-->
--Editableuserdatabasethatcanalsobeusedby
UserDatabaseRealmtoauthenticateusers
-->
type="org.apach