您的位置:首页 > 运维架构 > Tomcat

apache2.2+tomcat7.0.53+ehcache1.5分布式缓存集群配置完整版

2014-05-26 10:32 411 查看

一、环境:

web服务器:tomcat7.0.53

操作系统:window server2008

负载均衡:apache2.2(mod_jk模块)

缓存:ehcache1.5.0



二、安装:

1.先将apache2.2安装在31.0.240.54,下载好安装包后开始安装。

有疑问可以参考/article/10174687.html

2.准备好java运行环境后分别将tomcat7.0.53解压出来放在机器31.0.240.55和31.0.240.56磁盘固定位置,确保各自可以正常运行。

3.开始安装在apache上安装mod_jk模块,apache2.2默认已经有mod_jk.so模块了,但是不影响我们采用单独的模块tomcat-connectors-1.2.40-windows-i386-httpd-2.2.x.zip中的mod_jk来工作。可以去官网下载,目前可以到此处下载http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/

注释:在这里解释下,据我了解apache做负载均衡可以有两种方式:mod_proxy和mod_jk。其中mod_proxy是apache自己支持的方式,其中mod_jk分为1和2两个版本,据闻版本2不够稳定,问题多多,不建议使用。

mod_proxy

优势:

不需要编译和维护一个对立的模块。mod_proxy,mod_proxy_http,mod_proxy_ajp,mod_proxy_balancer已经是apache 2.2+的标准集成部分;

可以使用http、https和AJP协议,即便是在同一个balancer中。

劣势:

mod_proxy_ajp不支持大于8k的数据包;

只有最基本的负载均衡器;

不支持域模型集群(domain model clustering)

mod_jk

优势:

先进的负载均衡器;

先进的节点失败侦察功能;

支持大型AJP 数据包

劣势:

需要单独维护一个独立的模块;

4.将准备好的mod_jk.so文件改名为mod_jk_http2.so并复制到 Apache 安装目录下的 modules 子目录中。里面已经有了一个mod_jk.so,可以不予理睬,使用jk需要几个文件,分别是mod_jk.conf和workers.properties以及uriworkermap.properties。

先修改httpd.conf文件,进入 Apache 安装目录下的 conf 子目录中,打开 httpd.conf 配置文件,在最后插入以下一行: Include conf/mod_jk.conf。

下面介绍其他几个文件:

mod_jk.conf内容如下:

# Load mod_jk module. Specify the filename
# of the mod_jk lib you’ve downloaded and
# installed in the previous section
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk_http2.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
# Where to put jk logsJkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]JkLogLevel info
# Select the log format#JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE
# JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
#JkRequestLogFormat "%w %V %T"


workers.properties内容如下:

#========loadbalancer,负载均衡控制器========    
worker.list=loadbalancer

#========node1========    
worker.node1.port=8009          
#ajp13 端口号,在tomcat下server.xml配  置,默认8009    
worker.node1.host=31.0.240.55   
#tomcat的主机地址,如不为本机,请填写ip地址    
worker.node1.type=ajp13
worker.node1.connection_pool_size=400
worker.node1.connection_pool_minsize=100
worker.node1.lbfactor = 1     
#server的加权比重,值越高,分得的请求越多    
  
#========node2========    
worker.node2.port=8009         
#ajp13 端口号,在tomcat下server.xml配置,    
worker.node2.host=31.0.240.56   
#tomcat的主机地址,如不为本机,请填写ip地址    
worker.node2.type=ajp13   
worker.node2.connection_pool_size=400
worker.node2.connection_pool_minsize=100
worker.node2.lbfactor = 1     
#server的加权比重,值越高,分得的请求越多  

worker.loadbalancer.type=lb  
worker.loadbalancer.balance_workers=node1,node2 
#指定分担请求的tomcat
worker.loadbalancer.retries=3  
#重试次数 
worker.loadbalancer.sticky_session=false  
#配置session会话是否为粘性   
#此处指定集群是否需要会话复制,如果设为 true ,则表明为会话粘性,不进行会话复制,当某用户的请求第一次分发到哪台 Tomcat 后,后继的请求会一直分发到此 Tomcat 服务器上处理;如果设为 false ,则表明需求会话复制。
worker.loadbalancer.sticky_session_force=false 
#如果sticky_session设为true时,此处一般设为false 


uriworkermap.properties内容如下:

#所有请求都由LB_worker这个worker处理
/*=loadbalancer


5.开始配置tomcat集群以及session复制的功能,找到tomcat安装目录的conf目录下server.xml配置文件,31.0.240.55的tomcat修改为以下内容:

<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
 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.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note:  A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->

<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP  Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<!-- An Engine represents the entry point (within Catalina) that processes
every request.  The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html  (simple how to)
/docs/config/cluster.html (reference documentation) -->

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="4" channelStartOptions="3">

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

<Channel className="org.apache.catalina.tribes.group.GroupChannel">

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

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
<Member className="org.apache.catalina.tribes.membership.StaticMember"
port="5000"
host="31.0.240.55"
uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}"
/>
<Member className="org.apache.catalina.tribes.membership.StaticMember"
port="5000"
host="31.0.240.56"
uniqueId="{2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1}"
/>
</Interceptor>
</Channel>

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>

<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase".  Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm.  -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="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>


31.0.240.56的tomcat配置如下:

<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
 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.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note:  A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->

<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP  Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<!-- An Engine represents the entry point (within Catalina) that processes
every request.  The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node2">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html  (simple how to)
/docs/config/cluster.html (reference documentation) -->

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="4" channelStartOptions="3">

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

<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="31.0.240.56"
port="5000"
selectorTimeout="100"
maxThreads="6"/>

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
<Member className="org.apache.catalina.tribes.membership.StaticMember"
port="5000"
host="31.0.240.55"
uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}"
/>
<Member className="org.apache.catalina.tribes.membership.StaticMember"
port="5000"
host="31.0.240.56"
uniqueId="{2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1}"
/>
</Interceptor>
</Channel>

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>

<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase".  Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm.  -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="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>


注意:在这里我们使用ajp协议进行负载连接,tomcat的session同步功能默认是需要用到组播,windows默认情况下是开通组播服务,网上几乎都是基于这种默认的组播配置,我这里是基于点对点的单播配置,至于区别在这里不做说明。

到目前为止集群配置基本完成,可以启动运行去测试一下了,测试可以使用一个空白的web项目,然后更改index.jsp的内容即可,内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.SimpleDateFormat"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>TestCluster</title>
</head>
<body>
Server Info:
<%
String dtm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
System.out.println("["+request.getLocalAddr()+":"+ request.getLocalPort()+"]" + dtm);
out.println("<br>["+request.getLocalAddr()+":" +request.getLocalPort()+"]" + dtm+"<br>");
%>
Session Info:
<%
session.setAttribute("name","dennisit");
System.out.println("[Session Info] Session ID:"+session.getId());
out.println("<br>[Session Info] Session ID:" + session.getId()+"<br>");
%>
</body>
</html>


当我们打开浏览器查看的时候可以发现类似这样的结果:

Server Info:

[31.0.240.55:80]2014-05-26 09:36:14

Session Info:

[Session Info] Session ID:14C262DC317EBD7AD2F07C9B23DDFCAC.node1

以及

Server Info:

[31.0.240.55:80]2014-05-26 09:36:14

Session Info:

[Session Info] Session ID:14C262DC317EBD7AD2F07C9B23DDFCAC.node2

注意:如果后面的node1和node2始终不变需要确认下workers.properties中的session是否黏性。如果是非黏性可能还是会出现后面的node1和node2不变,但可以注意后台,其实已经是负载均衡了。至于要切换可能需要再做一些额外的配置,在tomcat的server.xml需要配置org.apache.catalina.ha.session.JvmRouteBinderValve这有可能会造成session有一定的问题,所以要慎用了。

6.下面进行ehcache分布式缓存配置:

在项目所在的class文件夹下找到ehcache.xml文件,(使用单播方式)示例如下:

31.0.240.55上应用的配置:

<ehcache>

<diskStore path="java.io.tmpdir"/>

<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />

<cache name="defaultCacheDefine" maxElementsInMemory="10000" eternal="false"
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=31.0.240.55,port=4080,socketTimeoutMillis=8000" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//31.0.240.56:4080/defaultCacheDefine|//31.0.240.56:4080/org.hibernate.cache.UpdateTimestampsCache|//31.0.240.56:4080/org.hibernate.cache.StandardQueryCache" />

<!--
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=31.0.240.55,
multicastGroupPort=40802, timeToLive=32" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=224.0.0.1, multicastGroupPort=4446,timeToLive=255"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost,socketTimeoutMillis=2000"/>-->

</ehcache>


31.0.240.56上应用配置如下:

<ehcache>

<diskStore path="java.io.tmpdir"/>

<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />

<cache name="defaultCacheDefine" maxElementsInMemory="10000" eternal="false"
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals=true"/>
</cache>

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=31.0.240.56,port=4080,socketTimeoutMillis=8000" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//31.0.240.55:4080/defaultCacheDefine|//31.0.240.55:4080/org.hibernate.cache.UpdateTimestampsCache|//31.0.240.55:4080/org.hibernate.cache.StandardQueryCache" />

<!--
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=31.0.240.55,
multicastGroupPort=40802, timeToLive=32" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=224.0.0.1, multicastGroupPort=4446,timeToLive=255"/>
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost,socketTimeoutMillis=2000"/>-->

</ehcache>


配置完成。

三、优化

1.ehcache缓存的配置也可以参考我的上一篇帖子:/article/10174686.html,在这里并没有关于性能参数的配置。包括apache和tomcat的连接数设置等,

2.关于apache的性能优化参考:/article/10174688.html

3.关于tomcat的性能优化参考:/article/10174690.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: