{"id":18837330,"url":"https://github.com/clarenceb/haproxy-keepalived-demo","last_synced_at":"2026-01-28T02:30:18.199Z","repository":{"id":33033630,"uuid":"36669295","full_name":"clarenceb/haproxy-keepalived-demo","owner":"clarenceb","description":"Demo showing how to setup redundant HAProxy servers to load-balance traffic between web servers.","archived":false,"fork":false,"pushed_at":"2015-06-01T15:36:11.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-30T08:41:11.452Z","etag":null,"topics":["haproxy","keepalived"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarenceb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-01T15:18:28.000Z","updated_at":"2015-06-01T15:31:36.000Z","dependencies_parsed_at":"2022-08-17T18:15:18.714Z","dependency_job_id":null,"html_url":"https://github.com/clarenceb/haproxy-keepalived-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Fhaproxy-keepalived-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Fhaproxy-keepalived-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Fhaproxy-keepalived-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarenceb%2Fhaproxy-keepalived-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarenceb","download_url":"https://codeload.github.com/clarenceb/haproxy-keepalived-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239774324,"owners_count":19694700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haproxy","keepalived"],"created_at":"2024-11-08T02:34:47.727Z","updated_at":"2026-01-28T02:30:18.147Z","avatar_url":"https://github.com/clarenceb.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"HAProxy and Keepalived Demo\n===========================\n\nDemo showing how to setup redundant HAProxy servers to load-balance traffic between web servers.\n\nMost of the setup is based on this blog post: [HAProxy and Keepalived: Example Configuration](http://andyleonard.com/2011/02/01/haproxy-and-keepalived-example-configuration/)\n\nPre-requisites:\n---------------\n\n* [Vagrant](https://www.vagrantup.com/) - 1.6.5+\n* [vagrant-cachier](https://github.com/fgrehm/vagrant-cachier) plugin (optional install)\n  * `vagrant plugin install vagrant-cachier`\n\nSetup:\n------\n\nThere will be two load-balancer servers running [HAProxy](http://www.haproxy.org/) and [keepalived](http://keepalived.org/).\n\n* **LB1** will have VRRP priority 101 and is the **master** load-balancer\n* **LB2** will have VRRP priority 100 and is the **backup** load-balancer\n\nBoth LBs use round-robin algorithm to route traffic to Web1 and Web2 servers which run Nginx on port 80.\n\nSteps:\n-----\n\nCreate the 4 VMs:\n\n    vagrant up\n\nTest it out:\n\n    # Hit web1-box directly\n    curl http://192.168.33.68\n\n    # Hit web2-box directly\n    curl http://192.168.33.68\n\n    # Hit vip\n    curl http://192.168.33.84\n\nSee the HAProxy stats:\n\n    LB 1: http://192.168.33.80/stats\n    LB 2: http://192.168.33.81/stats\n\n**In one terminal:**\n\n    while true; do curl -sI http://192.168.33.84 | head -n 1; sleep 1; done\n    # ==\u003e HTTP/1.1 200 OK\n\n**In a second terminal:**\n\n    vagrant ssh lb-box1\n    sudo tcpdump -i eth1\n\n    # Look for VRRP advertisements.\n    # Press CTRL+C\n\n    sudo su\n    watch -n 2 \"echo show stat | socat /var/lib/haproxy/stats.sock stdio | grep http,BACKEND\"\n\n    # Observe the http backend bytes out (column 10)\n    # It should be going up\n\n**In a third terminal:**\n\n    vagrant ssh lb-box2\n    sudo tcpdump -i eth1\n\n    # Look for VRRP advertisements.\n    # Press CTRL+C\n\n    sudo su\n    watch -n 2 \"echo show stat | socat /var/lib/haproxy/stats.sock stdio | grep http,BACKEND\"\n\n    # Observe the http backend bytes out (column 10)\n    # It should be going not be going up\n\n**In a fourth terminal:**\n\n    vagrant halt lb-box1\n\nThe `curl` requests should continue via the vip but be routed to LB2.\n\nObserve the http backend bytes out (column 10) in third terminal (lb-box2) - it should now be going up.\n\n    vagrant up lb-box1\n\nThe `curl` requests should continue via the vip but be routed back to LB1.\n\nLearning Resources:\n-------------------\n\n* [HAProxy and Keepalived: Example Configuration](http://andyleonard.com/2011/02/01/haproxy-and-keepalived-example-configuration/)\n* [Keepalived and HAProxy in AWS: An Exploratory Guide]( https://blog.logentries.com/2014/12/keepalived-and-haproxy-in-aws-an-exploratory-guide/)\n* [Making HAProxy High Available For MySQL Galera Cluster](http://www.fromdual.com/making-haproxy-high-available-for-mysql-galera-cluster)\n* [Redundant Load Balancers – HAProxy and Keepalived](http://behindtheracks.com/2014/04/redundant-load-balancers-haproxy-and-keepalived/)\n* [How To Use HAProxy to Set Up HTTP Load Balancing on an Ubuntu VPS]( https://www.digitalocean.com/community/tutorials/how-to-use-haproxy-to-set-up-http-load-balancing-on-an-ubuntu-vps)\n* [Virtual Router Redundancy Protocol (VRRP)](http://en.wikipedia.org/wiki/Virtual_Router_Redundancy_Protocol)\n* [HAProxy Architecture  Guide](http://www.haproxy.org/download/1.3/doc/architecture.txt)\n* [keepalived User Guide](http://www.keepalived.org/pdf/UserGuide.pdf) [PDF]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Fhaproxy-keepalived-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarenceb%2Fhaproxy-keepalived-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarenceb%2Fhaproxy-keepalived-demo/lists"}