`
woshizn
  • 浏览: 206875 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Terracotta集群快速安装

    博客分类:
  • Java
阅读更多

这个文档告诉你怎样为一个用Ehcache cache的应用添加Terracotta 集群。

 

快速安装 与定制安装

有2种方法来安装Terracotta分布cache:快速与定制。快速安装适用于只需要一个cache的集群。定制安装适用于需要一个cache集群和 其他java对象,例如sessions和定制POJOs,或者使用Terracotta应用,或者使用Terracotta整合模块 (Terracotta integration Modules:TIMs)整合其他技术。

如果你使用Ehcache在一个单独的JVM上,或者使用一个集群响应,可以考虑快速安装(在这里 )。如果你是一个前沿的Terracotta使用者,而且想要添加一个分布caching,可以考虑使用定制安装。

如果你不确定用哪种方式安装,请阅读2中安装方法,然后找到适合你的安装方法。这2中安装方法不兼容,也不能被兼容使用。


前提是这个应用运行在:
1、    在一个单独的jvm上
2、    一个用Ehcache 响应的集群
步骤如下:
一、    需要条件
JDK1.5及以上版本
Terracotta 3.1.1及以上版本
所有被集群的对象是可串行化的

二、    安装分布cache
添加以下JAR文件到你项目的CLASSPATH中

  • ${TERRACOTTA_HOME}/distributed-cache/ehcache-terracotta-<version>.jar
  • ${TERRACOTTA_HOME}/distributed-cache/ehcache-core-<version>.jar

如果你用的是WAR文件,将这些JAR文件添加到WEB-INF/lib 文件夹中。

三、    配置分布式cache
Ehcache的配置文件,默认为ehcache.xml,需要在你项目的classpath中。如果你用的是WAR文件,需要将Ehcache配置文件放入WEB-INF/lib 文件夹中。

添加Terracotta配置文件
为需要用Terracotta实现集群的cache,在ehcache.xml添加sub-element<terracotta/>到cache的<cache>块中。举例如下:

<cache name="foo" maxElementsInMemory="1000"
       maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600"
       timeToLiveSeconds="0" memoryStoreEvictionPolicy="LFU">
  <!-- Adding the element <terracotta /> turns on Terracotta clustering for the cache foo. -->
  <terracotta />
</cache>
 


你还需要用<terracottaConfig>为应用服务器指出terracotta的位置。
客户端需要加载配置从一个文件或者Terracotta服务器中。下面的例子展示了一个加载于本地主机上的Terracotta服务器的配置文件。

<ehcache name="myCache">
...
<terracottaConfig url="localhost:9510" />
...
</ehcache>
 


url属性的值需要包含Terracotta服务器的主机名和它的DSO端口号(默认为9510)。

编辑不相容的配置
对于任何被集群的cache,你必须删除、disable、或者编辑那些在Terracotta集群时不相容的配置元素。被集群的caches有个<terracotta>或者<terracotta clustered=”true”>元素。
下面这些Ehcache配置属性或者元素需要删除或者disable。

  •   DiskStore-related attributes overflowToDisk and diskPersistent .

Terracotta 服务器自动提供一个磁盘储存。

  •   Replication-related configuration elements, such as <cacheManagerPeerProviderFactory>, <cacheManagerPeerListenerFactory>, <bootstrapCacheLoaderFactory>, <cacheEventListenerFactory>.

当一个变化发生在Terracotta集群的时候,所以包含变化元素和对象的节点都会更新。 Unlike the replication methods used to cluster Ehcache, cache event listeners are not (and do not need to be) notified of remote changes. Listeners are still aware of local changes.

  • Replication-related attributes such as replicateAsynchronously and replicatePuts .

MemoryStoreEvictionPolicy属性需要被设置成LFU或者LRU。设置MemoryStoreEvictionPolicy为FIFO将会引起IllegalArgumentException错误。

四、    启动集群
1、启动Terracotta服务

  • UNIX/Linux
  • [PROMPT] ${TERRACOTTA_HOME}/bin/start-tc-server.sh &
  • Microsoft Windows
  • [PROMPT] ${TERRACOTTA_HOME}\bin\start-tc-server.bat

2、启动应用服务器
3、启动Terracotta开发控制台

  • UNIX/Linux
  • [PROMPT] ${TERRACOTTA_HOME}/bin/dev-console.sh &
  • Microsoft Windows
  • [PROMPT] ${TERRACOTTA_HOME}\bin\dev-console.bat

4、连接Terracotta集训
点击Terracotta开发控制台中的Connect…
5、点击集群导航窗口中的Ehcache节点查看Terracotta集群中的caches。

五、编辑Terracotta配置
这一步告诉你如何在不同的机器上启动客户端和服务器,和故障转移(高效)。你可以扩展Terracotta集群和添加高效性,通过做以下的事情:
1、    将Terracotta服务器转移到单独的机器上。
2、    部署一个由多个Terracotta服务器组织的集群器。
3、    部署多个应用节点。

操作程序:
1、    关闭Terracotta集群器。
2、    建立Terracotta配置文件tc-config.xml包含像下面这样的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!-- All content copyright Terracotta, Inc., unless otherwise indicated.
     All rights reserved.
-->
<tc:tc-config xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd" xmlns:tc="http://www.terracotta.org/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
  <servers>
    <!-- Sets where the Terracotta server can be found. Replace the value of
         host with the server's IP address. -->
    <server host="server.1.ip.address" name="Server1">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
    </server>
    <!-- If using a standby Terracotta server, also referred to as an ACTIVE-
         PASSIVE configuration, add the second server here. -->
    <server host="server.2.ip.address" name="Server2">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
    </server>
  </servers>
  <!-- Sets where the generated client logs are saved on clients. -->  
  <clients>
    <logs>%(user.home)/terracotta/client-logs</logs>
  </clients>
</tc:tc-config>
 



3、    安装Terracotta3.1.1在每一台你在tc-config.xml中配置的服务器上。
4、    复制tc-config.xml文件到一个Terracotta服务器们可以进入的位置。
5、    执行二、安装分布cache 和 三、配置分布式cache 在每一个你想要集群的应用节点上。
确定你安装了你的应用或者任何应用服务器在那些节点上。
6、    添加以下语句到Ehcache配置文件ehcache.xml中:

<!-- Add the servers that are configured in tc-config.xml. -->
<terracottaConfig url="server.1.ip.address:9510,server.2.ip.address:9510" />
 


7、    复制ehcache.xml到每一个应用节点,确保它在你应用的classpath中。如果你用的是WAR文件,将这些JAR文件添加到WEB-INF/lib 文件夹中。
8、    启动Terracotta服务以下面的方法,将tc-config.xml中的’Server1’换成任意你取的名字。

  • UNIX/Linux
  •  [PROMPT] ${TERRACOTTA_HOME}/bin/start-tc-server.sh -f <path/to/tc-config.xml> -n Server1 &
  • Microsoft Windows
  •  [PROMPT] ${TERRACOTTA_HOME}\bin\start-tc-server.bat -f <path\to\tc-config.xml> -n Server1 &


如果你配置了第2台服务器,启动那个服务用同样的方法在那台机器上,在 –n 标记后输入它的名字。第2台服务器成为热备份。任何你配置的其他服务器都可以开启变成备份服务器。
9、    打开所有的应用服务器。
10、打开Terracotta开发终端,监视集群器。


六、了解更多


http://www.terracotta.org/documentation/ga/product-documentation-2.html#50552833_Step%202


http://www.terracotta.org/documentation/ga/product-documentation-13.html#50552839_38131


http://www.terracotta.org/documentation/ga/product-documentation-4.html#50552833_53258


http://ehcache.org/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics