Week11 - Selesfia/ComputerNetwork GitHub Wiki
- Go to google cloud console -> VM instances -> create new instance
- Give it a name "vm-no-publicip" -> Choose region "asia-east1(Taiwan)"
- Change to "N1" machine and change the boot disk to "Ubuntu"
- In the Network interfaces section, under the External IP column, select None.
- SSH and Ping 8.8.8.8
- Go to google cloud console -> VM instances -> create new instance
- Give it a name "vm1-tw" -> Choose region "asia-east1(Taiwan)"
- Change to "N1" machine and change the boot disk to "Ubuntu" -> Enable HTTP traffic
- 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>
- Click your VM -> Observability -> install ops agent. PS: Make sure to enable the Compute Engine, Cloud Monitoring, and Cloud Logging APIs.
- Go to "Monitoring" -> Alerting -> Add your email address
- 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
- To test the traffic paste the following script to your VM.
timeout 120 bash -c -- 'while true; do curl localhost; sleep $((RANDOM % 4)) ; done'
- 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
- If the traffic exceed the threshold that is configured then you will receive email
- 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 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
- 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
- Go here -> Sign In/Up -> Create new zone -> Give it a name "mygcp-huzhenen.dns.army"
- 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"
- 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
- Go back to dynv6 website and paste the load balancer ip address at dynv6 website IPv4 Address slot "34.8.56.120" -> Create zone
- Open command prompt and try to ping the domain
- 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
- 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
- Go here -> Sign In/Up -> Create new zone -> Give it a name "mygcp-huzhenen.dns.army"
- Give a name to load balancer "lbus" -> Give a name to frontend "frontendus" -> Protocol "HTTP"
- 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