Table of Contents

, , , , , , , , ,

About the Club

Cloud Club Topics - Webserver & LoadBalancer

Install a webserver

  1. What is a webserver?
  2. What makes a server a webserver?
  3. What is a load balancer ( LB )?
  4. What does the load balancer do?

Understanding webservers

  1. A webserver is a computer ( any computer will do ) that has some webserver software installed on it.
    1. Examples of webserver software:
Name Supported OS
httpd/apache2 ( apache ) Runs on Linux, Windows, Mac
nginx Runs on Linux, windows, Mac
Internet Information Server ( IIS ) Windows ( server & workstation )
Tomcat ( Java ) Linux, Windows, Mac
Lighttpd Linux, Windows ( experimental ), Mac

Hands-on installing a webserver

  1. Create a debian server ( if you don't already have one )
    1. Assign an IP address from your range
    2. Install sudo ( elevated privileges for other commands ) - don't forget to replace <username> with your username
      su -
      apt install sudo -y
      usermod -aG sudo <username>
      exit
    3. Install httpd ( webserver software )
      sudo apt install apache2 -y
      sudo systemctl enable --now apache2
      sudo systemctl status apache2

Hands-on configure a webserver

  1. A default configuration is already setup
    1. Edit the default page ( /var/www/index.html )
      <html>
        <head>
          <title>My 1st Page!</title>
        </head>
        <body>
          <h1>Mike D</h1>
          <p><font size="5">This is awesome!</font></p>
        </body>
      </html>
    2. View your page in your browser
    3. View your page with curl ( replace <server_ip> with the IP of your server )
      curl http://<server_ip>/

Understanding Load Balancers ( LB )

  1. Load balancers are placed logically in front of the webservers
  2. They take the requests from the clients ( browsers ) and apply rules ( drop, redirect, forward, etc )
  3. A typical LB will have multiple webservers ( called “backends” or “real servers” ) as targets
  4. Techniques or methods of LBs
    1. Round robin
      1. Distributes requests sequentially to each server in a pool.
      2. Simple to implement and understand.
      3. Doesn't consider server load, so it might not be ideal for servers with varying capacities.
    2. Least connections
      1. Directs new connections to the server with the fewest active connections.
      2. Can improve response times by ensuring servers with fewer connections are utilized more effectively.
      3. Liquid Web notes that this approach is often the default and provides good performance.
    3. IP hash
      1. Routes requests to the same server based on the client's IP address.
      2. Useful for maintaining session affinity, where a client should always connect to the same server for their session.
    4. Weighted round robin
      1. Similar to Round Robin but assigns different weights to servers based on their capacity.
      2. Progress Software mentions that this is a good option when servers have varying capabilities.
    5. Least response time
      1. Chooses the server with the least average response time and the fewest active connections.
      2. Lavelle Networks notes that this method prioritizes both response time and server load.
    6. Random
      1. Distributes requests randomly across the available servers.
      2. F5 notes that it's a simple method but may lead to load imbalances.
    7. Resource-based ( adaptive )
      1. Makes load balancing decisions based on status indicators from each server, allowing for more detailed health checks.
      2. Kemp Technologies mentions that this method is suitable for applications with varied workloads.
    8. URL hash
      1. Routes requests to servers based on a hash of the requested URL.
      2. Lavelle Networks notes that this is used when servers serve content that is unique per server.
    9. Weighted least connections
      1. Combines server capacity and current connections when distributing traffic.
      2. Lavelle Networks notes that it prioritizes both factors for load distribution.
    10. DNS-based load balancing
      1. Uses DNS to route traffic to different servers.
      2. Multiple IP addresses are configured in DNS for a single hostname, and DNS alternates the IP address returned to clients.
    11. Geo-location based load balancing
      1. Routes traffic based on the geographic location of the client.

Hands-on Load Balancers ( LB )

  1. Create a Rocky Linux server ( if you don't already have one )
    1. Assign an IP address from your range
    2. Install haproxy
      sudo dnf install haproxy -y
  2. Add the following line to the bottom of /etc/haproxy/haproxy.cfg config file - ( replace <webserver_X_IP> with your server's IP address )
    #---------------------------------------------------------------------
    # Load balancer statistics ( stats ) 
    #---------------------------------------------------------------------
    listen stats
        bind :9000
        mode http
        stats enable
        stats uri /stats
    
    #---------------------------------------------------------------------
    # website frontend which proxys to the backends
    #---------------------------------------------------------------------
    frontend website-frontend
        bind *:8080
        default_backend website-backend
    
    #---------------------------------------------------------------------
    # website backend for serving up packages
    #---------------------------------------------------------------------
    backend website-backend
        balance     roundrobin
        server      website <webserver_1_IP>:80 check
        server      website <webserver_2_IP>:80 check
  3. View the website in your browser by going to the Load Balancer IP
  4. View the website with curl ( replace <lb_ip> with the IP of the LB )
    curl http://<lb_ip>/
  5. View the load balancer stats provided by HAProxy by going to the Load Balancer IP
    http://<lb_ip>:9000/stats
  6. The stats page will look similar to this.
  7. Optionally, you can install the Siege program to submit many requests. This will bump the numbers quickly
    # The 2 rpm files must be copied from the USB drive to the current directory
    sudo dnf install ./*.rpm -y
    siege -t1 http://<lb_ip>:8080