Vagrant HAProxy Demo using CentOS7

Posted on Posted in CentOS, Vagrant

I wanted to get a little more familiar with both HAProxy config and Vagrant so put the two together and bam, magic!  Sort of.  After trying multiple Vagrantfile config options to set a static IP I gave up; my custom CentOS7 network config would get wiped shortly after boot*.  I then began testing with ifcfg files and they did exactly what I needed along with a few well placed Vagrantfile options.  Sure, I could have used Vagrants internal network scheme but where is the fun in that?

*potential user error

Take that a step further and I threw together a package that that will create the interface configs, the Vagrantfile, the haproxy.cfg file, boot three CentOS7 VMs, configure NICs, and install the necessary components.  The existing package doesn’t have input validation, assumes a working Vagrant environment, you are deploying to a routable /24 network, have an internet connection, and are using CentOS as host – if everything goes well you’ll have the demo running in about 7 minutes.

Clone the repo, run bash, enter available IPs on a /24 subnet within your LAN, select the interface that should bridge with the VMs, and off ya go.

Customizations to the HAProxy VM will:
enable logging

enable the stats webpage

enable granular control of the HAProxy servers

and by default will send 66% of the traffic to NGINX2.  Remove the # and “weight x00” from the lines below, systemctl restart haproxy, and you’ll be back to standard round robin load balancing


Review HAProxy logs


Review HAProxy status and disable/enable servers from the HA pool


Silence the DUP! messages when pinging from inside a Vagrant VM