tags:

views:

171

answers:

6

currently we use dns polling for 4 web servers,

the problem we met is that:when user refreshes,he might go to other web servers.This feels

very bad when a user has already login.Because we use session to remember login status,but

when refreshing to another web servers,the session is lost.So the best solution should be

make the user still on the same web server when he refreshes.Is there any way out?

+1  A: 

Can the web servers use a common database server to store the session information?

RichieHindle
it'll be best if no code change is needed
Shore
A: 

Are the four web servers all on the same site and network, or are they distributed?

If the former, you can include a server ID somewhere in the HTTP response, such that a reverse proxy in front of the real servers can identify which server is responsible for the session.

Alnitak
+1  A: 

I know that certain hardware based load balancers will create a "sticky" relationship between a user and a server to avoid this type of problem.

Richard West
What about redundancy in this solution? Do those hardware boxes share information between them, or something?
Reef
could you please tell me what's that hardware plz?
Shore
Richard West
+2  A: 

Ok, I believe you mean "Round Robin DNS". Well, what you describe is a very common problem and there is no "right" solution for it, since the possible answers depend on many variables: are you trying to provide automatic failover or just load balancing? Are you willing to spend time and/or money in a load balancer? What technologies are you using? Java EE? PHP? Apache? IIS?

Having said that, if you're just after load balancing and failover is not much of an issue you may want to use different names for each server (www1,www2,www3 and so on) and redirect to them from your "main" web server (www) upon first access. It's simple (and simplistic) but practical in a few settings.

codehead
A: 

A DNS server that can respond based on the location of client could solve this problem. PowerDNS with the geoip module or GeoIPdns are some examples. You would need to make sure that the IP address sets were non-overlapping so a client always got the same response.

This would not provide any sort of fail over on its own.

EvilRyry
He would need to use f.e. wackamole to ensure something always is on the (single) IP that is in DNS. Also, this can not be good if his website would be mentioned in TV in some small country. Only one server could handle the requests.
Reef
+1  A: 

You have quite a few options.

  • You can store sessions in a key:value storage, f.e. memcached (my personal favorite)
  • You can store sessions in a database
  • You can put reverse-proxy loadbalancers like in DNS and Your servers in the back. Then set it to make all requests from the same IPs go to the same servers, regardless of which loadbalancer they go through. In HAProxy this option is called balance source. Beware: if the number of node changes, the sessions can be lost. You can use the cookie or url_param features to avoid this.

See the HAProxy documentation. It's worth reading, really.

Reef