Apache,Tomcat:不使用公共会话ID的负载平衡

时间:2016-01-19 08:23:36

标签: java spring apache tomcat cometd

我正在开发一个部署在2个Tomcat实例上的Spring-MVC应用程序。使用mod_jk在前面的Apache实例实现负载平衡和故障转移。现在,除了我们的PUSH技术,一切都运作良好。

我们使用的PUSH技术是基于Cometd(Bayeux API规范),如果我登录,那么我登录到一台服务器,但我看不到在线登录第二台服务器的用户。我已经在使用sticky sessions了。我认为他们有责任管理这个。

Apache配置:

workers.properties:

worker.list=loadbalancer
worker.list=jk-status
worker.jk-status.type=status
worker.jk-status.read_only=true

worker.list=jk-manager
worker.jk-manager.type=status

worker.server1.port=8010
worker.server1.host=localhost
worker.server1.lbfactor=1
worker.server1.type=ajp13


worker.server2.port=8011
worker.server2.host=localhost
worker.server2.type=ajp13
worker.server2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2

worker.loadbalancer.sticky_session=true
worker.myworker.sticky_session_force=True

/ 000-默认启用位点-

Listen 443
<VirtualHost _default_:443>
ServerName www.domain.com
ServerAlias *.domain.com domain.com
JkMount /* loadbalancer
SSLEngine on
SSLCertificateFile /home/path/to/.crt
SSLCertificateKeyFile /home//path/to/.key
SSLCertificateChainFile /home/path/to/.ca-bundle
</VirtualHost>

apache2.conf:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/apache2/workers.properties
JkLogFile   /etc/apache2/mod_jk.log
JkMount /* loadbalancer

Tomcat只有一个变化,即jvmRoute。如果有必要,我可以补充一点。请告诉我为什么会发生这种情况以及如何解决这个问题。非常感谢。 : - )

TomcatFirst'server.xml:

<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8443" enableLookups="true" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="200" 
compression="off" sslProtocols="TLS" sslEnabledProtocols="TLSv1+TLSv1.1+TLSv1.2" 
ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,
TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" 
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" 
keystoreFile="/path/to/.keystore" keystorePass="PASSWORD" URIEncoding="utf-8"/>
 <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8"
 compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="server1">
<Host name="www.domain.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <Alias>domain.com</Alias>
</Engine>

TomcatSecond的server.xml:

 <Server port="8006" shutdown="SHUTDOWN">
    <Connector port="8444" enableLookups="true" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="200" 
    compression="off" sslProtocols="TLS" sslEnabledProtocols="TLSv1+TLSv1.1+TLSv1.2" 
    ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
     TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,
    TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" 
    compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" 
    keystoreFile="/path/to/.keystore" keystorePass="PASSWORD" URIEncoding="utf-8"/>
     <Connector port="8011" protocol="AJP/1.3" redirectPort="8444" URIEncoding="utf-8"
     compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
    />
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="server2">
    <Host name="www.domain.com"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">

            <Alias>domain.com</Alias>
    </Engine>

修改

刚刚发现了一个要在web.xml中添加的新元素distributable。这会有帮助吗?尝试需要2次部署,这就是为什么我认为我可能会问。

1 个答案:

答案 0 :(得分:1)

你能改变这样的工人文件吗?

worker.list=loadbalancer,jk-status

worker.jk-status.type=status
worker.jk-status.read_only=true

worker.server1.port=8010
worker.server1.host=localhost
worker.server1.lbfactor=1
worker.server1.type=ajp13

worker.server2.port=8011
worker.server2.host=localhost
worker.server2.type=ajp13
worker.server2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.sticky_session=true
worker.loadbalancer.balance_workers=server1,server2

JvmRoute设置正确,但我在server.xml文件(引擎或主机级别)中找不到集群元素?

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

您可能想要禁用Tomcats中的ssl连接器并在您的网络服务器中启用它?

映射应如下所示:

JkMount /appName     loadbalancer
JkMount /appName/*   loadbalancer

JkMount /jkStatus    jk-status

检查http://example.com/jkstatus以查看节点确实找到了对方。

一旦设置了集群并且DeltaManager(传播会话)正在运行,会话ID就会将节点名称作为后缀:ANYSESSIONID.server1