Web Server Load Balancer


Published on

HAProxy Load Balancer,

Published in: Technology
1 Comment
  • tnx for thjis
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Web Server Load Balancer

  1. 1. HAProxy Load Balancer
  2. 2. Introduction <ul><li>Load Balancing is a technique to spread work between two or more computers, network links, CPUs, hard drives, or other resources, in order to get optimal resource utilization, maximize throughput, and minimize response time. </li></ul><ul><li>Load balancer is a tool that directs a client to the least busy or most appropriate Web server among several servers that contain mirrored contents. </li></ul>
  3. 3. Why is load balancing of servers needed? <ul><li>The web server may not be able to handle high volumes of incoming traffic. </li></ul><ul><li>The users will have to wait until the web server is free to process their requests. </li></ul><ul><li>There may be a situation where upgrading the server hardware will no longer be cost effective. </li></ul>
  4. 4. Load-balancing techniques <ul><li>Three types of load balancers exist: </li></ul><ul><ul><li>Hardware appliances </li></ul></ul><ul><ul><li>Network switches </li></ul></ul><ul><ul><li>Software </li></ul></ul>
  5. 5. Load-balancing techniques <ul><li>A hardware appliance-based load balancer is a closed box. </li></ul><ul><li>A network switch-based load balancer uses a Layer2 or Layer3 switch to integrate the load-balancing service. </li></ul><ul><li>A software load balancer is software which you can install on a dedicated server. </li></ul>
  6. 6. How to achive load balancing? <ul><li>More servers need to be added to distribute the load among the group of servers, which is also known as a server cluster. </li></ul><ul><li>The load distribution among these servers is known as load balancing. </li></ul><ul><li>Load balancing applies to all types of servers (application server, database server). </li></ul>
  7. 7. Software Load Balancers <ul><li>Haproxy </li></ul><ul><li>Pure Load Balancer (PLB)‏ </li></ul><ul><li>Perlbal </li></ul><ul><li>Pound </li></ul><ul><li>Pen </li></ul>
  8. 8. Haproxy Load Balancer <ul><li>HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. </li></ul>
  9. 9. Installation <ul><li>$ apt-get install haproxy </li></ul><ul><li>Download the HAProxy ( http://haproxy.1wt.eu/#down )‏ </li></ul><ul><li>Untar the downloaded file. </li></ul><ul><li>$ ./configure </li></ul><ul><li>$ make </li></ul><ul><li>$ make install </li></ul>
  10. 10. HAProxy Status
  11. 11. Examples http://www.mobshare.in
  12. 12. listen webfarm mode http balance roundrobin cookie SERVERID insert indirect option httpchk HEAD /index.html HTTP/1.0 server webA cookie A check server webB cookie B check port 81 inter 2000 server webC cookie C check server webD cookie D check server bkpA cookie A check backup server bkpB cookie B check backup http://www.mobshare.in
  13. 13. http://www.mobshare.in Updating... 503 Service Unavailable No server is available to handle this request.
  14. 14. Load balancing algorithms <ul><li>round-robin: requests are rotated among the servers. </li></ul><ul><li>leastconn: the request is sent to the server with the lowest number of connections. </li></ul><ul><li>source: a hash of the source IP is divided by the total weight of the running servers to determine which server will receive the request. </li></ul>
  15. 15. Load balancing algorithms... <ul><li>uri: the part of the URL up to a question mark is hashed and used to choose a server that will handle the request. </li></ul><ul><li>url_param: can be used to check certain parts of the URL, for example values sent via POST requests; for example a request which specifies a user_id parameter with a certain value can get directed to the same server using the url_param method. </li></ul>
  16. 16. Basic Configuration <ul><li>The configuration file haproxy.cfg is segmented in sections. </li></ul><ul><ul><li>global section </li></ul></ul><ul><ul><li>listen section </li></ul></ul><ul><ul><li>default section </li></ul></ul><ul><ul><ul><ul><ul><li>OR </li></ul></ul></ul></ul></ul><ul><ul><li>global section </li></ul></ul><ul><ul><li>default section </li></ul></ul><ul><ul><li>frontend section </li></ul></ul><ul><ul><li>backend sections </li></ul></ul>
  17. 17. Global Section Example global daemon quiet nbproc 2 pidfile /var/run/haproxy-private.pid user haproxy group public
  18. 18. Default Section Example defaults log global mode http option httplog option forwardfor
  19. 19. Listen Section Example listen webfarm mode http balance roundrobin cookie SERVERID insert indirect option httpchk HEAD /index.html HTTP/1.0 server webA cookie A check server webB cookie B check server webC cookie C check server webD cookie D check
  20. 20. Frontend Section Example frontend myfrontend *:80 log global maxconn 25000 option forwardfor acl acl_example1 url_sub example1 acl acl_example2 url_sub example2 use_backend example1_farm if acl_example1 use_backend example2_farm if acl_example2 default_backend default_farm
  21. 21. Backend Sections Example backend example1_farm mode http balance roundrobin server server1 check server server2 check backend example2_farm mode http balance roundrobin server server3 check server server4 check backend default_farm mode http balance roundrobin server server5 check server server6 check