Redis-based CAs cluster configuration (RPM)

Source: Internet
Author: User
Tags redis version ticket

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 class Redisticketregistry extends abstractdistributedticketregistry{@NotNull private final redistemplate<    String,object> reidstemplate;     /** * TGT Cache entry timeout in seconds.    */@Min (0) private final int tgttimeout;     /** * ST Cache entry timeout in seconds.        */@Min (0) private final int sttimeout; Public Redisticketregistry (redistemplate<string,object> reidstemplate,int tgttimeout,int stTimeout) {This.rei        Dstemplate=reidstemplate;        This.tgttimeout=tgttimeout;    This.sttimeout=sttimeout;        } @Override public void Addticket (Ticket Ticket) {logger.debug ("Adding Ticket {}", Ticket);        try {reidstemplate.opsforvalue (). Set (Ticket.getid (), Ticket, GetTimeout (ticket), timeunit.seconds);        } catch (Final Exception e) {logger.error ("Failed Adding {}", ticket, E); }} @Override public Ticket getticket (String ticketid) {try {final Ticket t = (Ticket) this.reidsTemplate.opsForValue (). get (Ticketid);                if (t! = null) {return getproxiedticketinstance (t);            }} catch (Final Exception e) {logger.error ("Failed Fetching {}", Ticketid, E);    } return null;            } @Override public boolean deleteticket (String ticketid) {logger.debug ("Deleting Ticket {}", Ticketid);                 try {this.reidsTemplate.delete (ticketid);            return true;            } catch (Final Exception e) {logger.error ("Failed Deleting {}", Ticketid, E);    } return false; } @Override Public collection<ticket> gettickets () {throw new Unsupportedoperationexception ("Getticke    TS not supported. ");}        @Override protected void Updateticket (Ticket Ticket) {logger.debug ("Updating Ticket {}", Ticket); try {this.reidsTemplate.delete (TickeT.getid ());        Reidstemplate.opsforvalue (). Set (Ticket.getid (), Ticket, GetTimeout (ticket), timeunit.seconds);        } catch (Final Exception e) {logger.error ("Failed Updating {}", ticket, E);    }} @Override protected Boolean needscallback () {//TODO auto-generated method stub return true; } private int GetTimeout (final Ticket t) {if (T instanceof Ticketgrantingticket) {return THIS.TGTT        Imeout;        } else if (T instanceof Serviceticket) {return this.sttimeout;    } throw new IllegalArgumentException ("Invalid ticket type"); }}

The corresponding ticketregistry.xml are configured as follows:

<bean id= "Ticketregistry" class= "Com.test.cas.ticket.registry.RedisTicketRegistry" >        < Constructor-arg index= "0" ref= "redistemplate"/>        <constructor-arg index= "1" value= "1800"/>        < Constructor-arg index= "2" value= "/>    </bean>    <bean id=" Poolconfig "class=" Redis.clients.jedis.JedisPoolConfig ">          <property name=" Maxidle "value=" "/> <property          name=" Testonborrow "value=" true "/>      </bean>            <bean id=" ConnectionFactory "class=" Org.springframework.data.redis.connection.jedis.JedisConnectionFactory "          p:host-name=" Redis_server_ip "P: Port= "6379"   p:pool-config-ref= "Poolconfig"/>      <bean id= "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 "/>  -    <!--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.scheduling.quartz.MethodInvokingJobDetailFactoryBean "        p:targetobject-ref=" Ticketregistrycleaner "        p:targetmethod=" clean "/>        <bean id=" Triggerjobdetailticketregistrycleaner "Class=" Org.springframework.scheduling.quartz.SimpleTriggerBean "        p:jobdetail-ref=" Jobdetailticketregistrycleaner "        p:startdelay=" 20000 "        p:repeatinterval=" 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.)

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

The CAS cluster configuration is now available.

Http://www.cnblogs.com/lcxdever/p/4308759.html

Redis-based CAs cluster configuration (RPM)

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.