LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2014, 03:03 PM   #1
user41094
LQ Newbie
 
Registered: Mar 2014
Location: London, United Kingdom
Posts: 6

Rep: Reputation: Disabled
Please help, HAProxy keeps switching between servers


I'm building an application in PHP + MySQL Database that allows college students to register an account and build up their university schedule for the current semester.
- In page 1, students fill in their personal information
- In page 2, they choose the classes they want to sign-up for
- In page 3, they can see what their schedule will look like based on the classes they chose

I have a HAProxy that balances the requests using roundrobin algorithm to one of my two webservers.
E.g: When client1 connects to my application, his request will be sent to webserver1.
Afterwards, client2 connects to my application, his request will be sent to webserver2.
And so on..

My problem is the way that my HAProxy is switching between webservers, is messing with my users sessions.
Take this for example:
- Client1 connects to application. HAproxy sends his request to Webserver1
- Client1 fills in information, and clicks next
- HAProxy sends request to webserver 2 instead of 1!
And since all the information was passed in webserver 1, webserver 2 won't display any of it!

My question is:
If a client connects to webserver 1, how can I make it so HAProxy forces that client to stay always in webserver 1?
And vice-versa for webserver 2.


This is my HAProxy config file:
Code:
global
	log 127.0.0.1 local0
	log 127.0.0.1 local0 notice
	maxconn 2000
	user haproxy
	group haproxy
	daemon

defaults
	log global
	mode http
	option httplog
	option dontlognull
	retries 3
	option redispatch
	timeout connect 5000
	timeout client 10000
	timeout server 1000


listen haproxy001 192.168.1.100:80
	mode http
	stats enable
	stats uri /haproxy?stats
	stats realm Strictly\ Private
	stats auth admin:admin
	cookie JSESSIONID prefix
	balance roundrobin
	option httpclose
	option forwardfor
	option httpchk HEAD / HTTP/1.0
	server server1 192.168.1.93:80 cookie A weight 50 check
	server server2 192.168.1.94:80 cookie B weight 50 check

Last edited by user41094; 06-23-2014 at 03:06 PM.
 
Old 06-24-2014, 06:20 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
And since all the information was passed in webserver 1, webserver 2 won't display any of it!
If the pages were being populated from a centralized database, then it wouldn't really matter which webserver you were reaching, the page information would be pulled from the database based on the users index entry.
If you're counting on stored information on the web server to populate the pages, on the other hand, you'd have to point the "next" page to a one that can only be reached on the same webserver they started the process on.

Server A
Index -->next=nexta
Server B
Index -->next=nextb

Though I'd go with the database solution, for ease of maintenance if for no other reason.

Last edited by dijetlo; 06-24-2014 at 06:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
haproxy config for multiple physical servers without load balance Train Linux - Server 6 05-27-2014 08:19 AM
haproxy question cbtshare Linux - Server 1 11-07-2010 02:44 PM
stunnel with haproxy 1.4.6 cbtshare Linux - Software 6 08-09-2010 01:35 PM
haproxy agarwalpranay Linux - Newbie 4 06-19-2010 01:31 AM
Haproxy by host guruyaya Linux - Server 0 08-26-2008 08:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration