Haproxy

From Notes_Wiki

Home > CentOS > CentOS 6.x > Network related tools > Haproxy

haproxy can be used for load-balancing among different backend servers. If servers are web-servers then haproxy can do more intelligent balancing based on sessions, etc. To configure haproxy for load-balancing requests to backend servers use following steps:

  1. Configure all repositories (rpmfusion, repoforge, epel, etc.)
  2. yum -y install haproxy
  3. Edit /etc/haproxy/haproxy.cfg and comment following lines
    option httplog
    option dontlognull
    option http-server-close
    option forwardfor except 127.0.0.0/8
    as these are related to http. Then remove or comment all existing lines for various frontend and backend servers. Then create simple configuration such as
    listen test1 192.168.122.103:8080
    mode tcp
    balance roundrobin
    server web1 192.168.122.104:80 weight 1 maxconn 512 check
    server web2 192.168.122.105:80 weight 1 maxconn 512 check
    Here the IP in first line should be IP address of haproxy server. The IPs in the server lines are the IP addresses of backend servers. This particular configuration load balances port 8080 of haproxy to port 80 of backend servers. The port numbers can be changed to some other suitable value based on the application. Apart from "mode tcp" other option is "mode http" for http servers. Apart from "balance roundrobin" other option is to use "balance source" so that same source IP is always sent to the same backend server.


Home > CentOS > CentOS 6.x > Network related tools > Haproxy