我在基于 Debian X64 的服务器上配置了负载平衡和故障转移设置。现在,我有 2 个 Tomcat 实例,它们处于负载平衡和故障转移状态,并且一直在运行。请求通过 Tomcat1(server1) 或 Tomcat2(server2) 提供服务。
在 Tomcat 前面有一个 Apache Web 服务器,它充当负载平衡器和故障转移,并使用 mod_jk 进行配置。两个 Tomcat 都通过AJP
.
现在,我想做的是,我不想运行 2 个 Tomcat 实例,而只想运行一个。当此实例死亡或崩溃时,第二个 Tomcat 实例将被激活并随之提供请求。
这是配置:
worker.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
站点启用/000-默认:
Listen 443
<VirtualHost _default_:443>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerName www.domain.com
ServerAlias *.domain.com domain.com
JkMount /* loadbalancer
SSLEngine on
SSLCertificateFile /path/to/.crt
SSLCertificateKeyFile /path/to/.key
SSLCertificateChainFile /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
JkMount /jkStatus jk-status
<IfModule mod_rewrite>
RewriteEngine On
</IfModule>
Tomcat1:
<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"
/>
<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"
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false"
keystoreFile="/path/to/keystore" keystorePass="PASS" URIEncoding="utf-8"/>
与上面相同,只是在 Tomcat2 中更改了端口号。
我希望有足够的信息来处理这个问题。请告诉我。谢谢你。
更新配置
worker.list=loadbalancer
worker.list=jk-status
worker.jk-status.type=status
worker.list=jk-manager
worker.jk-manager.type=status
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2
# Define the first member worker
worker.server1.type=ajp13
worker.server1.host=localhost
worker.server1.port=8010
# Define preferred failover node for worker1
worker.server1.redirect=server2
# Define the second member worker
worker.server2.type=ajp13
worker.server2.host=localhost
worker.server2.port=8011
# Disable worker2 for all requests except failover
worker.server2.activation=disabled
worker.loadbalancer.sticky_session=true
根据mod_jk 文档,您似乎可以
distance
通过将距离设置得更大来创建热备用:然而,在LoadBalancer Howto 文档中,给出了另一种方法: