Results 1 to 1 of 1
-
08-14-2007, 02:03 AM #1Problem Solver
- Join Date
- Mar 2003
- Location
- California USA
- Posts
- 13,681
HAproxy - Quick and Dirty HTTP Load balancing Tutorial on Redhat/Centos
This can be adapted to other operating systems, for the scope of this tutorial it will be designed for Redhat enterprise / Centos
Little info:
HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net
You will need a free ip, not binded to port 80, to begin this.
wget http://haproxy.1wt.eu/download/1.2/src/haproxy-1.2.17.tar.gz
tar -zxf haproxy-1.2.17.tar.gz
cd haproxy-1.2.17
make
cp haproxy /usr/sbin/haproxy
Lets grab the files:
wget http://layer1.rack911.com/haproxy/haproxy-standard.cfg -O /etc/haproxy.cfg
wget http://layer1.rack911.com/haproxy/haproxy.init -O /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
Open /etc/haproxy.cfg with your favorite editor and fine the line that says:
nbproc 4
Next, we need to set the listener:
listen http_proxy 4.0.0.0:80
listen http_proxy 55.55.55.55:80
Lets say you have the following servers:
web1 66.66.66.66
web2 77.77.77.77
web3 88.88.88.88
You would configure the rest like this. Take the part that looks like this:
server server1 4.1.1.1:80 weight 1 maxconn 512 check
server server2 4.2.2.2:80 weight 1 maxconn 512 check
server server3 4.3.3.3:80 weight 1 maxconn 512 check
server web1 66.66.66.66:80 weight 1 maxconn 512 check
server web2 77.77.77.77:80 weight 1 maxconn 512 check
server web3 88.88.88.88:80 weight 1 maxconn 512 check
The final configuration would look something like this
global
maxconn 4096 # Total Max Connections. This is dependent on ulimit
daemon
nbproc 4 # Number of processing cores. Dual Dual-core Opteron is 4 cores for example.
defaults
mode http
clitimeout 60000
srvtimeout 30000
contimeout 4000
option httpclose # Disable Keepalive
listen http_proxy 55.55.55.55:80
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor # This sets X-Forwarded-For
## Define your servers to balance
server web1 66.66.66.66:80 weight 1 maxconn 512 check
server web2 77.77.77.77:80 weight 1 maxconn 512 check
server web3 88.88.88.88:80 weight 1 maxconn 512 check
service haproxy start
chkconfig --add haproxy
This is a basic round robin style load balancer. It will remove servers it cannot connect to, and add them back to the pool once they are back online.
There is loads of configuration options you can use. More information can be found here:
http://haproxy.1wt.eu/download/1.2/doc/haproxy-en.txtSteven Ciaburri | Industry's Best Server Management - Rack911.com
Software Auditing - 400+ Vulnerabilities Found - Quote @ https://www.RACK911Labs.com
Fully Managed Dedicated Servers (Las Vegas, New York City, & Amsterdam) (AS62710)
FreeBSD & Linux Server Management, Security Auditing, Server Optimization, PCI Compliance