Amazon EC2 Load Balancing Options
MWahl | March 21, 2010 | 4:03 pmI have been looking at different load balancers especially ones that support sticky sessions and that will work on Amazon EC2.
I tried mod_proxy installed on a Fedora 8 AMI using Apache as my front end and then passing sessions to a set of backend Tomcat 6 servers. This did work, but for some reason our application was getting network errors.
I next tried HAProxy installed on a Fedora 8 AMI using HAProxy as my front end and passing sticky sessions to a tomcat 6 server. DNS round robin distributes the visits to each front each server and the sticky session stays with the correct tomcat server. Also if one of the AMIs goes down you have a redundant front end and back end server to continue serving sessions.
HAProxy can be installed using the command Yum install HAProxy*
Using DNS Round Robin I have two separate A records pointing to a set of Elastic IP Addresses each associated to an AMI.
From each Fedora 8 AMI under /etc/haproxy here is my config files.
#Front End Server_Tomcat server 1
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 8192
daemon
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 8192
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen Front_End_Webfarm 0.0.0.0:80
stats enable
stats auth yourusername:yourpassword
balance roundrobin # Load Balancing algorithm
#balance url_param JSESSIONID check_post
option forwardfor # This sets X-Forwarded-For
cookie JSESSIONID
#appsession JSESSIONID prefix
option httpclose
server lb2 tomcatserverprivateipaddress:8080 weight 1 maxconn 150 cookie lb2 inter 10s check
option httpchk OPTIONS /website_path
#Front End Server_Tomcat server 2
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 8192
daemon
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
redispatch
maxconn 8192
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen Front_End_Webfarm 0.0.0.0:80
stats enable
stats auth yourusername:yourpassword
balance roundrobin # Load Balancing algorithm
#balance url_param JSESSIONID check_post
option forwardfor # This sets X-Forwarded-For
cookie JSESSIONID
#appsession JSESSIONID prefix
option httpclose
server lb2 tomcatserverprivateipaddress:8080 weight 1 maxconn 150 cookie lb2 inter 10s check
option httpchk OPTIONS /website_path
Don’t forget to run these commands so that haproxy and tomcat will startup after a reboot.
chkconfig --level 2345 tomcat on;
chkconfig --level 2345 haproxy on;
You can go to http://externaldsnname or elasticip/haproxy?stats this will give you some insight into what is happening with HAPROXY.
I am also looking at a product called RightScale which will add a lot of automation options.

lopsa




