Code Monkey home page Code Monkey logo

vagrant-haproxy's Introduction

vagrant-haproxy-demo

Demo of HAProxy using Vagrant

This is the toolset I used to present on load balancers at University of Nebraska at Kearney on 2/19/14.

What does the Vagrantfile do?

  • It sets up a 3 VM mini-network inside Virtualbox. The three hosts are haproxy (172.28.33.1), web1 (172.28.33.11), and web2 (172.28.33.12)
  • It sets up the following port forwards between your host's external interface and the internal VM's:
Host port Guest machine Guest port Notes
8080 haproxy 8080 HAProxy Admin Interface
8081 haproxy 80 Load Balanced Apache
  • It installs Apache on the two web servers, and configures it with a index page that identifies which host you're viewing the page on.
  • It installs HAProxy on the haproxy host, and drops a configuration file in place with the two webservers pre-configured. It doesn't require HAProxy to be the default gateway because it NAT's the source IP as well as the destination IP.

Prerequisites

  1. Install Vagrant
  2. Install Virtualbox
  3. Either clone this repo with git clone https://github.com/kserge2001/vagrant-haproxy.git or just download the current zip file and extract it in an empty directory.

Getting started

  1. Open 3 terminal windows -- one for each host. Change to the directory containing the Vagrantfile from step 3 above.
  2. In terminal #1, run vagrant up haproxy && vagrant ssh haproxy
  3. In terminal #2, run vagrant up web1 && vagrant ssh web1
  4. In terminal #3, run vagrant up web2 && vagrant ssh web2
  5. Open up http://localhost:8080/haproxy?stats in your host's browser. This is the HAProxy admin interface.
  6. Open up http://localhost:8081/ in your host's browser. This is the load balanced interface to the two web servers. Note this is port forwarded via your actual host, and will be accessible via your externally accessible IP address - you can access test the load balancer from another workstation if you wish.
  7. Open up http://172.28.33.11/ in a browser to see if web1's Apache is working.
  8. Open up http://172.28.33.12/ in a browser to see if web2's Apache is working.
  9. To see the Apache access logs on web1 and web2, run sudo tail -f /var/log/apache2/access.log If you'd like to filter out the "pings" from the load balancer, run sudo tail -f /var/log/apache2/access.log | grep -v OPTIONS
  10. To stop Apache on one of the webservers to simulate an outage, run sudo service apache2 stop To start it again, run sudo service apache2 start
  11. To make changes to haproxy, edit the config file with sudo nano /etc/haproxy/haproxy.cfg When you want to apply the changes, run sudo service haproxy reload If you break things and want to reset back, just run sudo cp /etc/haproxy/haproxy.cfg.orig /etc/haproxy/haproxy.cfg && sudo service haproxy reload
  12. When you're all done, type exit at the shell to get back to your local terminal.
  13. To shut down the VM's, run vagrant halt web1 web2 haproxy
  14. To remove the VM's from your hard drive, run vagrant destroy web1 web2 haproxy
  15. If you wish to remove the cached image file from which these machines were created, run vagrant box remove precise32

Reference material

vagrant-haproxy's People

Contributors

justintime avatar justinellison avatar root136 avatar kserge2001 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.