HAProxy is a free, reliable, high performance load balancing solution capable of proxying TCP and HTTP applications. This article will outline how to set up a simple HAProxy server to allow you to load balance web site requests to one or more back-end web servers. While this example may not be suitable for a production set up on the internet, its a good start if you just want to set up a simple load balanced web site. The following example is using Ubuntu, however the configuration will be the same regardless of the distribution. I want to run HAProxy on Windows Server 2012 R2 Base for production. I read this blog: and it conveys that HAProxy on. The steps to install HAProxy will vary depending on the distribution. It also assumes that the back end web servers are on different physical machines to the one running HAProxy. Installing HAProxy: $ sudo apt-get install haproxy On Ubuntu, by default the HAProxy service is disabled. To enable it you need to modify the /etc/default/haproxy file. $ sudo nano /etc/default/haproxy Modify the 'ENABLED=0' line to 'ENABLED=1' as shown below. Change this: # Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=0 # Add extra flags here. #EXTRAOPTS='-de -m 16' To this: # Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=1 # Add extra flags here. #EXTRAOPTS='-de -m 16' Save and exit the editor. The next step is to modify the HAProxy configuration file. $ sudo nano /etc/haproxy/haproxy.cfg In the default configuration file, there will likely be a number of 'listen' sections. These can be removed or commented out, as they wont be needed. You just want to keep the 'global' and 'defaults' sections for now. Add in the following 'frontend' and 'backend' sections: frontend http_in bind *:80 default_backend webservers backend webservers balance roundrobin server webserver1 192.168.50.11:80 server webserver2 192.168.50.12:80 What this does is sets up a proxy frontend called 'http_in', listening on port 80, on all IP addresses on the machine. This proxy frontend will pass all traffic through to the 'backend' which has been configured with the name 'webservers'. This is set with the 'default_backend' setting pointing to 'webservers'. THe 'backend' section is where we configure what servers will be avaliable to load balance between, and what type of load balancing model to use. This example uses the round robin model, which basically just rotates evenly between the servers listed. In this example, we have named the server running on 192.168.50.11 as 'webserver1' and the server running on 192.168.50.12 as 'webserver2'. These names dont have to resolve to anything as they are just used for identifiers within HAProxy. The configuration file should now look similar to this: global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn 4096 #chroot /usr/share/haproxy user haproxy group haproxy daemon #debug #quiet defaults log global mode http option httplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 frontend http_in bind *:80 default_backend webservers backend webservers balance roundrobin server webserver1 192.168.50.11:80 server webserver2 192.168.50.12:80 Save the configuration, and exit the editor.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2018
Categories |