Week11 - Selesfia/ComputerNetwork GitHub Wiki

Create VM without Public IP

  1. Go to google cloud console -> VM instances -> create new instance
  2. Give it a name "vm-no-publicip" -> Choose region "asia-east1(Taiwan)"
  3. Change to "N1" machine and change the boot disk to "Ubuntu"
  4. In the Network interfaces section, under the External IP column, select None.
  5. SSH and Ping 8.8.8.8

Collect Apache web server metrics with the Ops Agent

Reference

  1. Go to google cloud console -> VM instances -> create new instance
  2. Give it a name "vm1-tw" -> Choose region "asia-east1(Taiwan)"
  3. Change to "N1" machine and change the boot disk to "Ubuntu" -> Enable HTTP traffic
  4. Go to Advanced Option -> Management -> Automation -> and paste the below script -> Create
#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly. $(hostname -I) </p></body></html>
  1. Click your VM -> Observability -> install ops agent. PS: Make sure to enable the Compute Engine, Cloud Monitoring, and Cloud Logging APIs.
  2. Go to "Monitoring" -> Alerting -> Add your email address
  3. SSH -> paste the below script
# Configures Ops Agent to collect telemetry from the app and restart Ops Agent.

set -e

# Create a back up of the existing file so existing configurations are not lost.
sudo cp /etc/google-cloud-ops-agent/config.yaml /etc/google-cloud-ops-agent/config.yaml.bak

# Configure the Ops Agent.
sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
metrics:
  receivers:
    apache:
      type: apache
  service:
    pipelines:
      apache:
        receivers:
          - apache
logging:
  receivers:
    apache_access:
      type: apache_access
    apache_error:
      type: apache_error
  service:
    pipelines:
      apache:
        receivers:
          - apache_access
          - apache_error
EOF

sudo service google-cloud-ops-agent restart
sleep 60
  1. To test the traffic paste the following script to your VM. timeout 120 bash -c -- 'while true; do curl localhost; sleep $((RANDOM % 4)) ; done'
  2. Go to Alerting -> Create policy -> Select metric -> VM instance -> Apache -> Workload/apache.cpu.load -> Rolling window "1 minute" -> Threshold value "0.1" -> Choose your email -> Create
  3. If the traffic exceed the threshold that is configured then you will receive email

  1. Create new VM based on USA to compare the log time -> On cloud shell run curl -o /dev/null -s -w 'Total: %{time_total}\n' http://38.81.232.65/ , curl -o /dev/null -s -w 'Total: %{time_total}\n' http://34.57.50.150/ . Change the ip address to your VM external ip.

Create Instance Group (for VM at TW zone)

  1. Create new unmanaged instance group -> Set the location the same as your VM "asia-east1-a" -> Set network and instances "default" -> Select "vm1-tw" -> Click create

Create Load Balancing (for VM at TW zone)

  1. Type of load balancer "Application Load Balancer (HTTP/HTTPS)" -> Public facing or internal "Public facing (external)" -> Global or single region deployment "Best for global workloads" -> Load balancer generation "Global external Application Load Balancer" -> Configure
  2. Go here -> Sign In/Up -> Create new zone -> Give it a name "mygcp-huzhenen.dns.army"
  3. Give a name to load balancer "lbtw" -> Give a name to frontend "frontendtw" -> Protocol "HTTPS" -> Create new certificate "certtw-2" -> Create mode "Create Google-managed certificate" -> Paste the domain name that you just created "mygcp-huzhenen.dns.army"
  4. Create backend service -> Give a name "backendtw" -> Choose the instance group that you just created -> Set the port number to 80 -> Disable Cloud CDN -> Create health check "healthcheck-tw1" -> Save -> Create backend -> Create load balancer

  1. Go back to dynv6 website and paste the load balancer ip address at dynv6 website IPv4 Address slot "34.8.56.120" -> Create zone
  2. Open command prompt and try to ping the domain

Create Instance Group (for VM at Central zone)

  1. Create new unmanaged instance group -> Set the location the same as your VM "us-central1-a" -> Set network and instances "default" -> Select "vm-us" -> Click create

Create Load Balancing (for VM at Central zone)

  1. Type of load balancer "Application Load Balancer (HTTP/HTTPS)" -> Public facing or internal "Public facing (external)" -> Global or single region deployment "Best for global workloads" -> Load balancer generation "Classic Application Load Balancer" -> Configure
  2. Go here -> Sign In/Up -> Create new zone -> Give it a name "mygcp-huzhenen.dns.army"
  3. Give a name to load balancer "lbus" -> Give a name to frontend "frontendus" -> Protocol "HTTP"
  4. Create backend service -> Give a name "backendus" -> Choose the instance group that you just created -> Set the port number to 80 -> Enable Cloud CDN -> Create health check "healthcheck-tw1" -> Save -> Create backend -> Create load balancer

Command : cat /dev/zero > /dev/null to increase traffic

PS : Remember to delete the resources that you created if you don't use it anymore.

19/11/2024

⚠️ **GitHub.com Fallback** ⚠️