Redis-based CAS cluster configuration

Source: Internet
Author: User
Tags redis version

1, CAS ticket unified storage

As a CAS cluster, we first need to take ticket out and do the unified storage so that each node accesses the same data. The official offer is based on the memcached program, which needs to be counted into Redis due to project needs, and a Redis version based on the official example.

 Public classRedisticketregistryextendsabstractdistributedticketregistry{@NotNullPrivate FinalRedistemplate<string,object>reidstemplate; /*** TGT Cache entry timeout in seconds. */@Min (0)    Private Final inttgttimeout; /*** ST Cache entry timeout in seconds. */@Min (0)    Private Final intsttimeout;  PublicRedisticketregistry (redistemplate<string,object> reidstemplate,intTgttimeout,intsttimeout) {         This. reidstemplate=reidstemplate;  This. tgttimeout=tgttimeout;  This. sttimeout=sttimeout; } @Override Public voidAddticket (Ticket Ticket) {logger.debug ("Adding Ticket {}", ticket); Try{Reidstemplate.opsforvalue (). Set (Ticket.getid (), Ticket, GetTimeout (ticket), timeunit.seconds); } Catch(FinalException e) {Logger.error ("Failed Adding {}", ticket, E); }} @Override PublicTicket GetTicket (String ticketid) {Try {                FinalTicket t = (Ticket) This. Reidstemplate.opsforvalue (). get (Ticketid); if(t! =NULL) {                    returngetproxiedticketinstance (t); }            } Catch(FinalException e) {Logger.error ("Failed Fetching {}", Ticketid, E); }            return NULL; } @Override Public BooleanDeleteticket (String ticketid) {logger.debug ("Deleting Ticket {}", Ticketid); Try {                  This. Reidstemplate.delete (Ticketid); return true; } Catch(FinalException e) {Logger.error ("Failed Deleting {}", Ticketid, E); }            return false; } @Override PublicCollection<ticket>gettickets () {Throw NewUnsupportedoperationexception ("Gettickets not supported.")); } @Overrideprotected voidUpdateticket (Ticket Ticket) {logger.debug ("Updating Ticket {}", ticket); Try {               This. Reidstemplate.delete (Ticket.getid ());        Reidstemplate.opsforvalue (). Set (Ticket.getid (), Ticket, GetTimeout (ticket), timeunit.seconds); } Catch(FinalException e) {Logger.error ("Failed Updating {}", ticket, E); }} @Overrideprotected BooleanNeedscallback () {//TODO auto-generated Method Stub        return true; }   Private intGetTimeout (FinalTicket T) {        if(tinstanceofticketgrantingticket) {            return  This. Tgttimeout; } Else if(tinstanceofserviceticket) {            return  This. Sttimeout; }        Throw NewIllegalArgumentException ("Invalid Ticket type"); }}

The corresponding ticketregistry.xml are configured as follows:

 <BeanID= "Ticketregistry"class= "Com.test.cas.ticket.registry.RedisTicketRegistry">        <Constructor-argIndex= "0"ref= "Redistemplate" />        <Constructor-argIndex= "1"value= "1800" />        <Constructor-argIndex= "2"value= "Ten" />    </Bean>    <BeanID= "Poolconfig"class= "Redis.clients.jedis.JedisPoolConfig">          < Propertyname= "Maxidle"value= "$" />          < Propertyname= "Testonborrow"value= "true" />      </Bean>            <BeanID= "ConnectionFactory"class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory"P:host-name= "Redis_server_ip"P:port= "6379"P:pool-config-ref= "Poolconfig"/>      <BeanID= "Redistemplate"class= "Org.springframework.data.redis.core.RedisTemplate"P:connection-factory-ref= "ConnectionFactory">    </Bean>

Since Redis is used as ticket storage, it is necessary to comment out the original schema:

 <!--Ticket Registry <bean id= "Ticketregistry" class= "Org.jasig.cas.ticket.registry.DefaultTicketRegistry"/> /c0> -    <!--Quartz -    <!--TICKET REGISTRY CLEANER <bean id= "Ticketregistrycleaner" class= " Org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner "p:ticketregistry-ref=" Ticketregistry "P: logoutmanager-ref= "Logoutmanager"/> <bean id= "Jobdetailticketregistrycleaner" class= "Org.springframework.sc Heduling.quartz.MethodInvokingJobDetailFactoryBean "p:targetobject-ref=" Ticketregistrycleaner "P:targetmetho d= "clean"/> <bean id= "Triggerjobdetailticketregistrycleaner" class= "Org.springframework.scheduling.quartz.s Impletriggerbean "p:jobdetail-ref=" Jobdetailticketregistrycleaner "p:startdelay=" 20000 "p:repeatInter Val= "5000000"/> -

Here, the improvement of CAS is OK, the following will need to do the session cluster synchronization.

2. Tomcat Session cluster synchronization

Here the open source Tomcat-redis-session-manager,git hub address is: Https://github.com/jcoleman/tomcat-redis-session-manager

The only use here is that JDK1.7,TOMCAT7,TOMCAT6 needs to be recompiled as if.

1) Copy the Tomcat-redis-session-manager-version.jar,jedis-2.5.2.jar,commons-pool2-2.2.jar to the Tomcat/lib directory after the package is compiled

2) Modify the Tomcat context.xml (or the context block of the server.xml if applicable.)

<className= "Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"  /><className= " Com.orangefunction.tomcat.redissessions.RedisSessionManager "         host=" Redis_server_name "           port= "6379"         database= "0"          Maxinactiveinterval= "1800"/>

The CAS cluster configuration is now available.

Redis-based CAS cluster configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.