Step 1:
Install HAProxy. If you have not already done so, install the epel repository.
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm yum install haproxy
The configuration file is stored in /etc/haproxy/haproxy.cfg. You may want to back this file up as it will be modified in the next step. You can also set up the service to start at boot:
chkconfig haproxy on
Step 2:
Set up the haproxy.cfg file. There are a number of configuration options for haproxy, most of which can be found here. The below configuration is how this system will be set up.
global maxconn 2000 # this system only has 512MB of memory daemon nbproc 1 # specify the number of processors to use log 127.0.0.1 local2 user haproxy group haproxy defaults log global mode http option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 1900 listen webservice 0.0.0.0:80 mode http status enable stats uri /haproxy?stats stats realm Private stats auth admin:password balance roundrobin option httpclose option forwardfor server server2 10.0.0.2 check server server3 10.0.0.3 check
Once the configuration is set up, start the service:
service haproxy start
Step 3:
Set up the backend servers defined in haproxy.cfg. In this example, just the apache test page is being used. Apache can be installed with a simple
yum install httpd service httpd on
Step 4:
Verify functionality.
Upon the initial connection, the stats page already shows some data.
A couple of page refreshes shows the counters going up and the load being spread across the two servers.
To get a better sense of how the system will perform, the FreeBSD tool siege will be used with 1000 concurrent hits.
Shutting down apache on one of the servers shows that the web page remains reachable, but all of the connections go to the one remaining server.
No comments:
Post a Comment