开发者社区> 问答> 正文

apache tomcat mod_jk集群配置负载均衡,没有负载?报错

先说问题

我看了很多博客,也看了jk的官网设置

配置成功,启动没报错。当启动3个tomcat的时候,远程或者本地访问都是访问tomcat1  2、3只有在1关闭的情况才会去访问

我2、3的lbfactor的权重配置都比1高。不知道为啥。

apache2.4  jk也是官网下载的。求高手帮忙,找出问题

我的项目中Tomcat7/conf/Catalina/中配置了多个host指向Root.xml

也用了druid数据库连接池

求兄弟们帮忙看下为啥


worker.properties配置

worker.list=controller,status 
#========apache-tomcat-1========
worker.tomcat1.port=9009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#========apache-tomcat-2========
worker.tomcat2.port=11009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=2
#========apache-tomcat-3========
worker.tomcat3.port=11009
worker.tomcat3.host=192.168.2.227
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor=10
#========controller========
worker.controller.type=lb
worker.controller.balance_workers=tomcat1,tomcat2,tomcat3
worker.status.type=status
#worker.controller.sticky_session=true
#worker.controller.sticky_session_force=false


展开
收起
爱吃鱼的程序员 2020-06-14 15:49:19 689 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    apache的httpd.conf


    <VirtualHost127.0.0.1:80>DocumentRoot"G:\apac he-tomcat-7.0.57\webapps"ServerNamewww.mysite.comJkMount/*/servlet/*controllerJkMount/*/openapi/*controllerJkMount/*.jspcontrollerJkMount/*.docontrollerJkMount/*controller</VirtualHost>


    #connecttomcat-7LoadModulejk_modulemodules/mod_jk.soJkWorkersFile"G:/apache-tomcat-7.0.57/conf/workers.properties"JkLogFile"G:/wamp/bin/apache/apache2.4.9/logs/mod_jk.log"


    G:/apache-tomcat-7.0.57/conf/workers.properties


    #serverworker.list=controller#========tomcat1========worker.tomcat2.port=8009worker.tomcat2.host=localhostworker.tomcat2.type=ajp13worker.tomcat2.lbfactor=1#========tomcat2========worker.tomcat1.port=9990worker.tomcat1.host=localhostworker.tomcat1.type=ajp13worker.tomcat1.lbfactor=1#========controller,负载均衡控制器========worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2worker.controller.sticky_session=falseworker.controller.sticky_session_force=1#worker.controller.sticky_session=1

    G:/apache-tomcat-7.0.57/conf/server.xml

    <?xmlversion='1.0'encoding='utf-8'?><!--LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements.SeetheNOTICEfiledistributedwiththisworkforadditionalinformationregardingcopyrightownership.TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththeLicense.YoumayobtainacopyoftheLicenseathttp://www.apache.org/licenses/LICENSE-2.0Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense.--><!--Note:A"Server"isnotitselfa"Container",soyoumaynotdefinesubcomponentssuchas"Valves"atthislevel.Documentationat/docs/config/server.html--><Serverport="8005"shutdown="SHUTDOWN"><ListenerclassName="org.apache.catalina.startup.VersionLoggerListener"/><!--Securitylistener.Documentationat/docs/config/listeners.html<ListenerclassName="org.apache.catalina.security.SecurityListener"/>--><!--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"/><!--Preventmemoryleaksduetouseofparticularjava/javaxAPIs--><ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener"/><ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/><ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/><!--GlobalJNDIresourcesDocumentationat/docs/jndi-resources-howto.html--><GlobalNamingResources><!--EditableuserdatabasethatcanalsobeusedbyUserDatabaseRealmtoauthenticateusers--><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"thatshareasingle"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"representsanendpointbywhichrequestsarereceivedandresponsesarereturned.Documentationat:JavaHTTPConnector:/docs/config/http.html(blocking&non-blocking)JavaAJPConnector:/docs/config/ajp.htmlAPR(HTTP/AJP)Connector:/docs/apr.htmlDefineanon-SSLHTTP/1.1Connectoronport8080--><Connectorport="8080"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.1Connectoronport8443ThisconnectorusestheBIOimplementationthatrequirestheJSSEstyleconfiguration.WhenusingtheAPR/nativeimplementation,theOpenSSLstyleconfigurationisrequiredasdescribedintheAPR/nativedocumentation--><!--<Connectorport="8443"protocol="org.apache.coyote.http11.Http11Protocol"maxThreads="150"SSLEnabled="true"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"/>--><!--DefineanAJP1.3Connectoronport8009--><Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/><!--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesseseveryrequest.TheEngineimplementationforTomcatstandaloneanalyzestheHTTPheadersincludedwiththerequest,andpassesthemontotheappropriateHost(virtualhost).Documentationat/docs/config/engine.html--><!--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm1">--><Enginename="Catalina"defaultHost="localhost"><!--Forclustering,pleasetakealookatdocumentationat:/docs/cluster-howto.html(simplehowto)/docs/config/cluster.html(referencedocumentation)--><!--<ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>--><!--UsetheLockOutRealmtopreventattemptstoguessuserpasswordsviaabrute-forceattack--><RealmclassName="org.apache.catalina.realm.LockOutRealm"><!--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDIresourcesunderthekey"UserDatabase".AnyeditsthatareperformedagainstthisUserDatabaseareimmediatelyavailableforusebytheRealm.--><RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Hostname="localhost"appBase="webapps"unpackWARs="true"autoDeploy="true"><!--SingleSignOnvalve,shareauthenticationbetweenwebapplicationsDocumentationat:/docs/config/valve.html--><!--<ValveclassName="org.apache.catalina.authenticator.SingleSignOn"/>--><!--Accesslogprocessesallexample.Documentationat:/docs/config/valve.htmlNote:Thepatternusedisequivalenttousingpattern="common"--><ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"prefix="localhost_access_log."suffix=".txt"pattern="%h%l%u%t"%r"%s%b"/></Host></Engine></Service></Server>




    上面是主的tomcat  配置。

    后面的其他tomcat的 workers.properties就改成这个就行了

    workers.tomcat_home="G:\apache-tomcat-7.0.57\"#让mod_jk模块知道Tomcat的安装路径workers.java_home="C:\ProgramFiles\Java\jdk1.7.0_13\"#让mod_jk模块知道jdk路径worker.list=ajp13#这里是关键,名字要和httpd.conf的一致。如果这里改了httpd.conf也要改。worker.ajp13.port=8009#工作端口,tomcat的jk监听端口,可以查看Server.xml中有port="8009"worker.ajp13.host=127.0.0.1#Tomcat所在机器,如果安装在与apache不同的机器则需要设置IPworker.ajp13.type=ajp13#类型,好像不能改,会出问题worker.ajp13.lbfactor=1#负载平衡因子


    @红薯编辑器有点坑呀

    @红薯 看一下你的编辑器问题,看上面的截图http://tomcat.apache.org/tomcat-7.0-doc/virtual-hosting-howto.htmltomcat可以自己配置VirtualHosting和apacheHttpd有啥区别呢

    引用来自“梦想岛”的评论

    apache的httpd.conf


    <VirtualHost127.0.0.1:80>DocumentRoot"G:\apac he-tomcat-7.0.57\webapps"ServerNamewww.mysite.comJkMount/*/servlet/*controllerJkMount/*/openapi/*controllerJkMount/*.jspcontrollerJkMount/*.docontrollerJkMount/*controller</VirtualHost>


    #connecttomcat-7LoadModulejk_modulemodules/mod_jk.soJkWorkersFile"G:/apache-tomcat-7.0.57/conf/workers.properties"JkLogFile"G:/wamp/bin/apache/apache2.4.9/logs/mod_jk.log"


    G:/apache-tomcat-7.0.57/conf/workers.properties


    #serverworker.list=controller#========tomcat1========worker.tomcat2.port=8009worker.tomcat2.host=localhostworker.tomcat2.type=ajp13worker.tomcat2.lbfactor=1#========tomcat2========worker.tomcat1.port=9990worker.tomcat1.host=localhostworker.tomcat1.type=ajp13worker.tomcat1.lbfactor=1#========controller,负载均衡控制器========worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2worker.controller.sticky_session=falseworker.controller.sticky_session_force=1#worker.controller.sticky_session=1

    G:/apache-tomcat-7.0.57/conf/server.xml

    <?xmlversion='1.0'encoding='utf-8'?><!--LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements.SeetheNOTICEfiledistributedwiththisworkforadditionalinformationregardingcopyrightownership.TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththeLicense.YoumayobtainacopyoftheLicenseathttp://www.apache.org/licenses/LICENSE-2.0Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense.--><!--Note:A"Server"isnotitselfa"Container",soyoumaynotdefinesubcomponentssuchas"Valves"atthislevel.Documentationat/docs/config/server.html--><Serverport="8005"shutdown="SHUTDOWN"><ListenerclassName="org.apache.catalina.startup.VersionLoggerListener"/><!--Securitylistener.Documentationat/docs/config/listeners.html<ListenerclassName="org.apache.catalina.security.SecurityListener"/>--><!--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"/><!--Preventmemoryleaksduetouseofparticularjava/javaxAPIs--><ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener"/><ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/><ListenerclassName="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/><!--GlobalJNDIresourcesDocumentationat/docs/jndi-resources-howto.html--><GlobalNamingResources><!--EditableuserdatabasethatcanalsobeusedbyUserDatabaseRealmtoauthenticateusers--><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"thatshareasingle"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"representsanendpointbywhichrequestsarereceivedandresponsesarereturned.Documentationat:JavaHTTPConnector:/docs/config/http.html(blocking&non-blocking)JavaAJPConnector:/docs/config/ajp.htmlAPR(HTTP/AJP)Connector:/docs/apr.htmlDefineanon-SSLHTTP/1.1Connectoronport8080--><Connectorport="8080"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.1Connectoronport8443ThisconnectorusestheBIOimplementationthatrequirestheJSSEstyleconfiguration.WhenusingtheAPR/nativeimplementation,theOpenSSLstyleconfigurationisrequiredasdescribedintheAPR/nativedocumentation--><!--<Connectorport="8443"protocol="org.apache.coyote.http11.Http11Protocol"maxThreads="150"SSLEnabled="true"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"/>--><!--DefineanAJP1.3Connectoronport8009--><Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/><!--AnEnginerepresentstheentrypoint(withinCatalina)thatprocesseseveryrequest.TheEngineimplementationforTomcatstandaloneanalyzestheHTTPheadersincludedwiththerequest,andpassesthemontotheappropriateHost(virtualhost).Documentationat/docs/config/engine.html--><!--YoushouldsetjvmRoutetosupportload-balancingviaAJPie:<Enginename="Catalina"defaultHost="localhost"jvmRoute="jvm1">--><Enginename="Catalina"defaultHost="localhost"><!--Forclustering,pleasetakealookatdocumentationat:/docs/cluster-howto.html(simplehowto)/docs/config/cluster.html(referencedocumentation)--><!--<ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>--><!--UsetheLockOutRealmtopreventattemptstoguessuserpasswordsviaabrute-forceattack--><RealmclassName="org.apache.catalina.realm.LockOutRealm"><!--ThisRealmusestheUserDatabaseconfiguredintheglobalJNDIresourcesunderthekey"UserDatabase".AnyeditsthatareperformedagainstthisUserDatabaseareimmediatelyavailableforusebytheRealm.--><RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Hostname="localhost"appBase="webapps"unpackWARs="true"autoDeploy="true"><!--SingleSignOnvalve,shareauthenticationbetweenwebapplicationsDocumentationat:/docs/config/valve.html--><!--<ValveclassName="org.apache.catalina.authenticator.SingleSignOn"/>--><!--Accesslogprocessesallexample.Documentationat:/docs/config/valve.htmlNote:Thepatternusedisequivalenttousingpattern="common"--><ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"prefix="localhost_access_log."suffix=".txt"pattern="%h%l%u%t"%r"%s%b"/></Host></Engine></Service></Server>




    上面是主的tomcat  配置。

    后面的其他tomcat的 workers.properties就改成这个就行了

    workers.tomcat_home="G:\apache-tomcat-7.0.57\"#让mod_jk模块知道Tomcat的安装路径workers.java_home="C:\ProgramFiles\Java\jdk1.7.0_13\"#让mod_jk模块知道jdk路径worker.list=ajp13#这里是关键,名字要和httpd.conf的一致。如果这里改了httpd.conf也要改。worker.ajp13.port=8009#工作端口,tomcat的jk监听端口,可以查看Server.xml中有port="8009"worker.ajp13.host=127.0.0.1#Tomcat所在机器,如果安装在与apache不同的机器则需要设置IPworker.ajp13.type=ajp13#类型,好像不能改,会出问题worker.ajp13.lbfactor=1#负载平衡因子


    @红薯编辑器有点坑呀

    2020-06-14 15:49:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Apache Tomcat 的云原生演进 立即下载
The Avant-garde of Apache NiFi 立即下载
Apache NiFi 1.0 in Nutshell 立即下载

相关实验场景

更多

相关镜像