JAVAWEB部署在Terracotta集群上

把web项目部署在Terracotta集群上时要考虑这个项目是否使用缓存。如果使用缓存了。就要先做好缓存跟Terracotta的集成。
          一般的缓存架构如Ehcache,Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。
          所以这里我先做Ehcache + Terracotta的集成。
          在这里要提到的就是由于我使用的框架是ssm里面已经集成了shiro权限框架。shiro里提供了使用缓存的接口。所以只要使用好spring配置文件就可以做好相关类的配置。
          在这里其实要实现的就是shiro的分布式缓存。在Shiro中使用Enchache+Terracotta提供分布式缓存解决方案已相当成熟。所以大家可以自行百度学习一下。在配置缓存时需要做一些Terracotta配置。
缓存配置文件如
<?xml version="1.0" encoding="UTF-8"?>
 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      
    xsi:noNamespaceSchemaLocation="ehcache.xsd">     
    <!--将内存放入缓存中-->
    <diskStore path="java.io.tmpdir" />

<cacheManagerEventListenerFactory class="" properties=""/>  
   <!--terracotta服务器配置,默认端口为9510,多个服务器用,分隔  -->  
   <terracottaConfig url="localhost:9510"/>   
    <!-- 默认缓存 -->
    <defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="true"
        diskSpoolBufferSizeMB="30"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU">  
    </defaultCache>

<!--正式的缓存配置-->
<!--     <cache name="cache_sacm"
        maxElementsInMemory="100000"
        eternal="false"  
        memoryStoreEvictionPolicy="LRU"
        timeToIdleSeconds="100000"
        timeToLiveSeconds="100000"
        overflowToDisk="false"
        maxElementsOnDisk="0">  
        <terracotta clustered="true"/> 开启集群  
    </cache> -->
   <!--  系统缓存 -->
    <cache name="sysCache"
        maxElementsInMemory="100000"
        eternal="false"  
        memoryStoreEvictionPolicy="LRU"
        timeToIdleSeconds="100000"
        timeToLiveSeconds="100000"
        overflowToDisk="false"
        maxElementsOnDisk="0">  
        <terracotta clustered="true"/> <!-- 开启集群 -->  
    </cache>
            <!--  用户缓存 -->
        <cache name="userCache"
        maxElementsInMemory="100000"
        eternal="false"  
        memoryStoreEvictionPolicy="LRU"
        timeToIdleSeconds="100000"
        timeToLiveSeconds="100000"
        overflowToDisk="false"
        maxElementsOnDisk="0">  
        <terracotta clustered="true"/> <!-- 开启集群 -->  
    </cache>

<!-- 工作流模块缓存 -->
        <cache name="actCache"
        maxElementsInMemory="100000"
        eternal="false"  
        memoryStoreEvictionPolicy="LRU"
        timeToIdleSeconds="100000"
        timeToLiveSeconds="100000"
        overflowToDisk="false"
        maxElementsOnDisk="0">  
        <terracotta clustered="true"/> <!-- 开启集群 -->  
    </cache>
    <!-- 内容管理模块缓存 -->
        <cache name="cmsCache"
        maxElementsInMemory="100000"
        eternal="false"  
        memoryStoreEvictionPolicy="LRU"
        timeToIdleSeconds="100000"
        timeToLiveSeconds="100000"
        overflowToDisk="false"
        maxElementsOnDisk="0">  
        <terracotta clustered="true"/> <!-- 开启集群 -->  
    </cache>
    <!-- 系统活动会话缓存 -->
        <cache name="activeSessionsCache" maxEntriesLocalHeap="10000"
        overflowToDisk="false" eternal="false" timeToLiveSeconds="100000"
        timeToIdleSeconds="0" diskPersistent="false"
        diskExpiryThreadIntervalSeconds="600">
         <terracotta clustered="true"/> <!-- 开启集群 -->
        </cache>
        <cache name="SimplePageCachingFilter" maxEntriesLocalHeap="100"
        eternal="false" overflowToDisk="false" timeToIdleSeconds="120" timeToLiveSeconds="120"
        memoryStoreEvictionPolicy="LFU">
        <terracotta clustered="true"/> <!-- 开启集群 -->
        </cache>
</ehcache>

如果你的Terracotta服务器端口不一样需要修改<terracottaConfig url="localhost:9510"/>的内容,写入相应的Terracotta服务器阵列的主机/端口。缓存参数里面如, activeSessionCache的diskPersistent或overflowToDisk属性都应该是false的,在群集配置中不支

持true。
相关spring配置文件如

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
    default-lazy-init="true">

<description>Spring Configuration</description>
    
    <!-- 加载配置属性文件 -->
    <context:property-placeholder ignore-unresolvable="true" location="classpath:jeesite.properties" />
    
    <!-- 加载应用属性实例,可通过  @Value("#{APP_PROP['jdbc.driver']}") String jdbcDriver 方式引用 -->
    <util:properties id="APP_PROP" location="classpath:jeesite.properties" local-override="true"/>
    
    <!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。  -->
    <context:component-scan base-package="com.thinkgem.jeesite"><!-- base-package 如果多个,用“,”分隔 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    
     <!-- MyBatis begin -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.thinkgem.jeesite"/>
        <property name="typeAliasesSuperType" value="com.thinkgem.jeesite.common.persistence.BaseEntity"/>
        <property name="mapperLocations" value="classpath:/mappings/**/*.xml"/>
        <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
    </bean>
    
    <!-- 扫描basePackage下所有以@MyBatisDao注解的接口 -->
    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        <property name="basePackage" value="com.thinkgem.jeesite"/>
        <property name="annotationClass" value="com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao"/>
    </bean>
    
    <!-- 定义事务 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    
    <!-- 配置 Annotation 驱动,扫描@Transactional注解的类定义事务  -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
    <!-- MyBatis end -->
    
    <!-- 配置 JSR303 Bean Validator 定义 -->
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />

<!-- 缓存配置 -->
     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:${ehcache.configFile}" />
    </bean>
    
        <!-- 缓存管理器 使用Ehcache实现 -->
  <!--   <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:${ehcache.configFile}"/>
    </bean> -->
    
    <!-- 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = "0 0 2 * * ?")标注方法 -->
    <task:executor id="executor" pool-size="10"/> <task:scheduler id="scheduler" pool-size="10"/>
    <task:annotation-driven scheduler="scheduler" executor="executor" proxy-target-class="true"/>
    
    <!-- 数据源配置, 使用 BoneCP 数据库连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
        <property name="driverClassName" value="${jdbc.driver}" />
        
        <!-- 基本属性 url、user、password -->
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${jdbc.pool.init}" />
        <property name="minIdle" value="${jdbc.pool.minIdle}" />
        <property name="maxActive" value="${jdbc.pool.maxActive}" />
        
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />
        
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />
        
        <property name="validationQuery" value="${jdbc.testSql}" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
        
        <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> -->
        
        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat" />
    </bean>
    
    <!-- 数据源配置, 使用应用服务器的数据库连接池
    <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/jeesite" />-->

<!-- 数据源配置, 不使用连接池
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>-->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">      
        <property name="messageConverters">      
            <list >      
                <ref bean="mappingJacksonHttpMessageConverter" />      
            </list>      
        </property>      
    </bean>
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">    
    <property name="supportedMediaTypes">    
        <list>    
            <value>application/json;charset=UTF-8</value>    
       </list>    
    </property>  
</bean>
</beans>

这里其实还有相关的shiro的配置文件。因为shiro也是pojo所以可以很好的支持spring。配置好相关的bena.就可以实现分布式缓存了。
这里主要是讲缓存跟Terracotta的集成。所以shiro相关内容请自行学习相关知识。以上经过实际测试的例子。

JAVAWEB部署在Terracotta集群上相关推荐

  1. 如何轻松地将可访问LAN的Pod部署到Kubernetes集群上

    撰者 | Jack Wallen 译者 | Katie,责编 | Jerry 来源 | CSDN云计算 封图 | CSDN 下载自视觉中国 想要在Kubernetes集群上部署可访问LAN的Pod来达 ...

  2. 想提高运维效率,那就把MySQL数据库部署到Kubernetes 集群中

    摘要:Kubernetes 很多看起来比较"繁琐"的设计的主要目的,都是希望为开发者提供更多的"可扩展性",给使用者带来更多的"稳定性"和& ...

  3. Docker-Compose一些常见的报错解决方法【部署微服务集群】

    部署微服务集群 ① 上传编写好了docker-compose文件 ② 启动nacos微服务 docker run --env MODE=standalone --name nacos -d -p 88 ...

  4. 在Kubernetes集群上部署高可用Harbor镜像仓库

    这里主要介绍使用kubectl部署Harbor镜像仓库到Kubernetes集群中. 使用Helm部署,参考: https://my.oschina.net/u/2306127/blog/181969 ...

  5. 在现有K8S集群上安装部署JenkinsX

    在2018年年初,Jenkins X首次发布,它由Apache Groovy语言的创建者Jame Strachan创建.Jenkins X 是一个高度集成化的 CI/CD 平台,基于 Jenkins ...

  6. 如何在tomcat下应用部署日志_如何在kubernete集群上部署springboot应用

    1.打包springboot镜像 2.在kubernete上发布镜像 3.测试 在之前的文章中,我讲了使用kubeadm从0到1搭建kubernete集群,今天我们来聊一下如何在这套k8s集群上部署s ...

  7. 在阿里云Serverless K8S集群上部署Spark任务并连接OSS(详细步骤)

    在阿里云ASK集群上部署Spark任务并连接OSS 简介 ASK是阿里云的一个产品,属于Serverless Kubernetes 集群,这次实验是要在ASK集群上运行Spark计算任务(以WordC ...

  8. 在Kubernetes集群上部署和管理JFrog Artifactory

    JFrog Artifactory是一个artifacts仓库管理平台,它支持所有的主流打包格式.构建工具和持续集成(CI)服务器.它将所有二进制内容保存在一个单一位置并提供一个接口,这使得用户在整个 ...

  9. 在Linux集群上部署Spark之前准备

    在Linux集群上部署Spark Spark安装部署比较简单, 用户可以登录其官方网站(http://spark.apache.org/downloads.html) 下载Spark最新版本或历史版本 ...

最新文章

  1. 【BZOJ-3262】陌上花开 CDQ分治(3维偏序)
  2. Docker:Docker的简介、安装、使用方法之详细攻略
  3. 破解百度翻译页面api参数加密
  4. 揭示垃圾收集暂停的时间长度
  5. php 根号2计算过程,根号2以及π的计算--关于无理数的畅想
  6. Android官方开发文档Training系列课程中文版:连接无线设备之通过P2P搜索网络服务
  7. 简单的python画图代码_python opencv如何实现简易画图板 python opencv实现简易画图板代码...
  8. Linux内核网络协议栈3-创建socket(1)
  9. 楼宇智能化工程设计、施工、验收规范目录
  10. 动手实验:使用 jstat 摸清线上系统的JVM运行状况
  11. 杭电Oj刷题(2027)
  12. 血浆/血清RNA提取试剂盒的功能和特色
  13. 电脑桌面图标DIY --- 制作透明的快捷图标
  14. 签证官的心思你不懂,所以才会被拒签
  15. 给你看个宝贝:GitHub 最野的开源库,把你拿捏的死死的。。。
  16. 前端工程的价值体现在哪里
  17. Processing基础——钟表(简单)
  18. 薄荷英语---《心理学》20180823
  19. 朱永官、张福锁 等:土壤微生物组与土壤健康
  20. 鸿蒙不替代安卓,华为鸿蒙2.0可以替代安卓吗,华为鸿蒙2.0优势在哪

热门文章

  1. Idea报错:@Override is not allowed when implementing interface method
  2. 信创云底座主流技术路线与厂商评估
  3. 【图像检测】基于LSD算法直线检测matlab代码
  4. 我整理的Java开源项目
  5. 百度地图的一些简单使用
  6. jedis:commons-pool-evictor-thread线程不能自动关闭?
  7. UV-VIS与DRS紫外漫反射
  8. Android如何获取当前连接wifi的信道?
  9. Android app专项测试之耗电量测试
  10. Python基础记录1