Building an HA Virtual Infrastructure

This tutorial will use VirtualBox and Vagrant to create redundant components for an HA Infrastructure.  This includes using HAProxy as a load balancer, Apache webservers, and a MySQL master-master database cluster. The load-balancer will be configured with round robin, a scheduling algorithm that distributes work evenly.  The webservers will be identical Rocky Linux 8 servers running the Apache webserver. The database will be two MySQL servers in a master-master configuration.  Also known as “mirror” because both servers update the data in real-time to ensure that both servers have the latest data. All of this can be done on Mac, Windows and Linux.

 

Linux Bash Scripts

##### Apache Webserver memory usage #####
# Ubuntu
ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}'
# RHEL
ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'
##### mysqldump #####
mysqldump testdb $(mysql -Ne 'show tables' | grep -vP '^(history|sessions|watchdog|cache.*)$') | gzip > testdb.sql.gz