Terracotta为Ehcache实现应用支持分布式缓存和应用session共享

目录

 Terracotta产品介绍

Terracotta服务器的一些关键功能包括:

TC Server 4.3.x入门

下载并安装

1-下载Terracotta服务器。

2-更新类路径

3-配置Ehcache

注意

启动Terracotta服务器

1-配置Terracotta服务器

2-启动Terracotta服务器


 Terracotta产品介绍

https://github.com/terracotta-oss 

Terracotta服务器为Terracotta产品(例如Ehcache)提供了强大的分布式内存数据管理功能,并且是Terracotta集群的骨干。

Terracotta服务器阵列可以从基本的两节点串联到多节点阵列(Terracotta服务器阵列(TSA))不等,可提供可配置的规模,高性能和深层的故障转移范围。

立即为您的Ehcache部署添加分布式缓存功能!

Terracotta还提供了其他可能感兴趣的其他开源项目和代码库。


Terracotta服务器的一些关键功能包括:

  • 分布式内存中数据管理–与传统数据网格相比,管理内存中的数据多10到100倍-使用您想要的所有RAM。
  • 无复杂性的可伸缩性–配置简单即可添加服务器实例,以满足不断增长的需求并促进容量规划
  • 高可用性–即时故障转移,可实现连续的正常运行时间和服务
  • 可配置的运行状况监视–用于节点间监视的Terracotta HealthChecker
  • 自动节点重新连接–临时断开的服务器实例和客户端重新加入群集,而无需操作员干预

Software AG的 商业支持版本中提供了诸如快速重启持久性,高级管理功能和安全性之类的高级功能。

安装和使用Terracotta Server就像下载工具包一样简单,并确保正确的文件位于应用程序的类路径中。唯一的平台要求是使用JDK 1.6或更高版本。

TC Server 4.3.x入门

只需下载,更改一些配置项并启动,即可轻松启动Terracotta Server4.x。由于不使用服务器就不会很有趣,因此本指南将向您展示如何将Terracotta服务器置于其最常见的用途:群集Ehcache缓存。
 

下载并安装

安装和使用Terracotta Server就像下载工具包一样简单,并确保正确的文件位于应用程序的类路径中。唯一的平台要求是使用JDK 1.6或更高版本。
 

1-下载Terracotta服务器。

该工具包打包为tar.gz文件。下载它,然后在命令行或使用适当的解压缩应用程序将其解压缩。
 

2-更新类路径

将以下JAR从工具包中添加到应用程序的类路径(如果尚未存在):

  • apis/ehcache/lib/ehcache-<version>.jar –该文件包含Ehcache API。
  • apis/ehcache/lib/slf4j-api-<version>.jar –该文件是BigMemory Max日志记录框架的桥梁或日志记录外观。
  • apis/toolkit/lib/terracotta-toolkit-runtime-<version>.jar –此JAR包含用于将Ehcache连接到Terracotta Server的库。

3-配置Ehcache

配置Ehcache以使用Terracotta服务器。创建一个“ ehcache.xml”配置文件,或修改您自己的现有Ehcache配置,或更新已下载的Terracotta Server套件的config-samples /目录中提供的配置。例如:

<span style="color:#333333"><code><ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
     name="myBigMemoryMaxConfig">

  <!-- Tell BigMemory where to write its data to disk. -->
  <diskStore path="/path/to/my/disk/store/directory"/>

  <!-- Set 'maxBytesLocalOffHeap' to the amount of off-heap in-memory 
  storage you want to use. This memory is invisible to the Java garbage 
  collector, providing for gigabytes to terabytes of in-memory data without 
  garbage collection pauses. --> 
  <cache name="myBigMemoryMaxStore"
        maxBytesLocalHeap="512M"
        maxBytesLocalOffHeap="8G">

    <!-- Tell BigMemory to use the "localRestartable" persistence
    strategy for fast restart (optional). -->
    <persistence strategy="localRestartable"/>

    <!-- Include the terracotta element so that the data set will be 
    managed as a client of the Terracotta server array.  -->
    <terracotta/>
  </cache>

  <!-- Specify where to find the server array configuration. In this 
  case, the configuration is retrieved from the local server. --> 
  <terracottaConfig url="localhost:9510" />

</ehcache>
</code></span>

确保您的“ ehcache.xml”文件位于类路径的顶层。
 

注意

1-使用-XX:MaxDirectMemorySize Java选项在JVM中分配足够的直接内存以适应您在配置中指定的堆外存储,另外至少要有250MB的空间以允许应用程序中可能发生的其他直接内存使用。例如:-XX:MaxDirectMemorySize=9G将MaxDirectMemorySize设置为您拥有的BigMemory的数量。
2-此外,使用-Xmx Java选项分配至少足够的堆以容纳配置中指定的堆上存储,再加上足够的额外堆来运行应用程序的其余部分。例如:-Xmx1g
3-如有必要,定义JAVA_HOME环境变量。
 

启动Terracotta服务器

您应该能够在不更改配置的情况下运行服务器进行测试,但是在启动服务器之前,我们将为您提供在哪里可以找到配置文件的指针。
 

1-配置Terracotta服务器

要配置Terracotta服务器,请创建“ tc-config.xml”配置文件,或更新terracotta套件的“ config-samples /”目录中提供的文件。例如:

<span style="color:#333333"><code class="language-xml"><?xml version="1.0" encoding="UTF-8" ?>
<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-9.xsd">
  <servers>
    <server host="localhost" name="My Server Name">
       <!-- Specify the port clients will connect to the server on. -->
       <tsa-port>9510</tsa-port>
       <!-- Configure memory (off-heap) space to use on the server. -->
       <dataStorage size=”4g”>
       </dataStorage>
    </server>
  </servers>
  <clients>
    <logs>logs-%i</logs>
  </clients>
</tc:tc-config></code></span>

将您的`tc-config.xml`文件放置在Terracotta`server /`目录中。
 

2-启动Terracotta服务器

在终端中,转到您的Terracotta`server /`目录。然后执行start-tc-server命令。对于* nix系统:

%> cd /path/to/terracotta-<version>/server
%> ./bin/start-tc-server.sh

对于Windows系统:

> cd \path\to\terracotta-<version>\server
> .\bin\start-tc-server.bat

您应该在终端中看到服务器已启动的确认。

目前使用Terracotta的案例并未没有特别广泛,有关session共享的请参考如下两篇博客:

https://blog.51cto.com/icenycmh/1844360

http://www.360doc.com/content/13/0306/20/2569758_269723508.shtml

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值