Open main menu

CDOT Wiki β

Changes

OPS345 Assignment 1

1,808 bytes added, 01:32, 26 January 2022
Part 1: first slave
** In ops345wwsg
** Make sure the second virtual drive is named www-data-slave1
* Add the appropriate iptables rule on router (don't forget to save the iptables rules) and ops345routersg rule to allow yourself to SSH to www-data-slave1 via port 2221.
* Don't change the hostname of www-data-slave1, leave it as "www".
*/5 * * * * rsync -e "ssh -i ~/.ssh/id_rsa_wwwsync" -au --exclude="nextcloud" /var/www/html/* asmith15@10.3.45.11:/var/www/html</source>
* Test that by creating some files on www, some other files on www-slave1, and waiting more than 5 minutes.
 
= Part 2: iptables load balancing =
 
You already have HTTP (port 80) traffic forwarded from router to www. That means you've already done most of the work to set up iptables to do the load balancing.
 
* Confirm that you will see your website by going to your router's public IP with a web browser. If it doesn't work: go back to lab 3 and figure out why.
* When you're sure it works: save a backup copy of your iptables rules just in case: <source>cp /etc/sysconfig/iptables /root/iptables-before-asg1</source>
You can restore the working set of rules if you make a big mess, but try not to: you may lock yourself out of router altogether, and then you won't be able to restore the original rules either.
* Remove the existing port 80 rule from your nat table. Find the rule number with:<source>iptables -L -n -t nat</source>
* Add two new rules to send 50% of the incoming requests for port 80 to www, and the rest to www-slave-1:<source>
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -m statistic --mode random --probability 0.5 -j DNAT --to-destination 10.3.45.11:80
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.3.45.21:80</source>
The two rules above are based on [https://scalingo.com/blog/iptables Yann Klis's blog post]. You should read that so you understand how they work.
* Test that your load balancer works by looking at the logs on both web servers and reloading your webpage in Firefox. After about 8 requests from Firefox the new requests will be directed to the other servers:<source>tail -f /var/log/httpd/access_log</source>
* You can also see the private IP address on your web page change: that's the actual IP address of the server processing the request, not the IP address of the load balancer.