gpt4 book ai didi

java - Apache Tomcat 负载均衡集群

转载 作者:行者123 更新时间:2023-11-28 22:17:08 25 4
gpt4 key购买 nike

我有 3 台安装了 Ubuntu 的服务器,我想配置 Tomcat 负载平衡。

Server A = 10.0.0.1,
Server B = 10.0.0.2,
Server C = 10.0.0.3

我已将域指向安装了 Apache 和 Mod_JK 的服务器 A。而服务器 B 和 C 有 Apache Tomcat 8。下面是我的 workers.properties 文件的详细信息

workers.apache_log=/var/log/apache2 worker.list=tomcatlb,status
worker.stat1.type=status

worker.tomcat1.type=ajp13 worker.tomcat1.host=10.0.0.2 #put your app
host here worker.tomcat1.port=8009 worker.tomcat2.type=ajp13
worker.tomcat2.host=10.0.0.3 worker.tomcat2.port=8009

worker.tomcat1.lbfactor=1 worker.tomcat2.lbfactor=1

worker.tomcatlb.type=lb
worker.tomcatlb.balance_workers=tomcat1,tomcat2

worker.list=jkstatus worker.jkstatus.type=status

我还在 Apache Tomcat 的 server.xml 中使用 jvmRounte 名称作为 tomcat1 和 tomcat2。

我还在 server.xml 中添加了以下行

      <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">

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

<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564" frequency="500"
dropTime="3000"/>

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">

<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>

</Sender>

<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto" port="4001" autoBind="100"
selectorTimeout="5000" maxThreads="6"/>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interc eptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>


</Channel>

context.xml 如下所示

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>

<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->

<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->

<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Manager className="org.apache.catalina.ha.session.BackupManager" />

</Context>

apache 配置有以下几行

 RewriteEngine on
RewriteRule ^/$ /test [PT,L]
JkMount /* tomcatlb

apache 通过 mod_jk 将请求重定向到 Tomcat,它工作正常,但是当一个 tomcat 出现故障时,它应该将请求重定向到另一个 tomcat,而不是我必须重新登录,因为它没有复制 session 。

最佳答案

我发现你不见了stickysession=JSESSIONID|jsessionid lbmethod=byrequests nofailover=Off connectiontimeout=5 timeout=30

关于java - Apache Tomcat 负载均衡集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42003760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com