Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis - Handling Failover and Load Balancing?

I have an application that uses Redis Tomcat Session Manager in order to connect to the Redis Server in order to externalize the sessions. Since we are targeting high availability, we wanted to run Redis Master-Slave configuration in a distributed manner. We are successfully able to achieve it in a single server with multiple Master-Slave configuration and we use sentinal to do so.

Our problem starts when we move from a single server to multiple server environment, i.e Consider we have servers s1,s2,s3 and Master runs in s1 whereas s2 and s3 runs slave processes. Sentinal easily does a switch over whenever the s1 master dies but our application is totally unaware of the switch over and keeps on pointing to the IP of s1 server whereas the master now is s2. How to address this problem and how can we increase the availability.

The configuration changes that we do in the Apache Tomcat is in the Server.xml file and is as follows :-

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
         host="localhost" <!-- optional: defaults to "localhost" -->
         port="6379" <!-- optional: defaults to "6379" -->
         database="0" <!-- optional: defaults to "0" -->
         maxInactiveInterval="60" <!-- optional: defaults to "60" (in seconds) --> />

How to get along with this situation and increase the availability. I read some plugins with zookeeper but none for Java and dont even know how would we implement the same.

Please feel free to ask any clarification if required.

like image 858
Shiv Kumar Ganesh Avatar asked Jan 13 '14 12:01

Shiv Kumar Ganesh


2 Answers

You'll probably want to have a look at HAProxy. I had a similar situation a few days ago setting up a high availability Redis service in Windows Azure. I documented how to do this here:

http://robertianhawdon.me.uk/2014/02/11/sysops-installing-a-high-availability-redis-service-on-centos-6-x-in-windows-azure/

Cheers

like image 55
Robert Ian Hawdon Avatar answered Oct 19 '22 09:10

Robert Ian Hawdon


Sentinal easily does a switch over whenever the s1 master dies but our application is totally unaware of the switch over and keeps on pointing to the IP of s1 server whereas the master now is s2

Try Redisson it automatically updates Redis topology, in particular handles master change as in your case. It also supports Single/Sentinel/Cluster and AWS Elasticache modes and of course implements Tomcat Session Manager.

like image 27
Nikita Koksharov Avatar answered Oct 19 '22 08:10

Nikita Koksharov