Solutions for Session Consistency Problem in Web Cluster

eurt發表於2019-04-15

How to keep a session consistent across Web cluster?

Sol 1: ip_hash based load balance

The load balancing strategy of nginx can be configured to ip_hash.
The basic idea is Hash(client_ip)%nodes.
Sol 1 is easy to configure and can be adopted in middle-scale distributed environment,
no changing the code.

Sol 2: session synchronization among all web servers

Tomcat server supports cluster through modifying the two configuration files below:
a. server.xml, just opening the <Cluster> node.
b. web.xml, adding <distributable> node.
Sol 2 is applied in small-scale distributed environment, no changing the code.

Sol 3: concentrated cache for sessions

Redis is used as the concentrated cache to store the sessions from all web servers.
Sol 3 is the first choice in large-scale distributed application because it is scalable and robust,
but changing the code.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/32498/viewspace-2641474/,如需轉載,請註明出處,否則將追究法律責任。

相關文章