Deploy a Compute Instance
with a Remote Startup Script
Mahmmoud Mahdi
Your challenge
Configure a Linux Google Compute Engine instance that
installs the Apache web server software using a remote
startup script. In order to confirm that a compute
instance Apache has successfully installed, the
Compute Engine instance must be accessible via HTTP
from the internet.
Deploy an Instance with a Remote Startup Script
1.Create a Bucket & Upload startup script.
2.Create a Compute Instance & config metadata.
3.Enable Public Access to Instance.
4.Check executing the startup script.
5.Check the URL and address.
Architecture Needed
Requirement Steps
2. Create VM Instance and
configure metadata
1. Create Startup script
and upload to bucket
3. Open firewall port
4. Test Connectivity
Solution 1
Do it manually
Create a Bucket Storage and upload Script file
● Bucket Name: project_id
● File name: resource-install-web.sh
Create a Compute Instance
● Name: apache
● Zone: us-central1-a
● Access: Enable Http
● Metadata: startup-script-url
Test Your Server
● Browse the server External IP
● Make sure it response.
Solution 2
Automate Script
Tasks
1.Create a Bucket & Upload startup script.
2.Create a Compute Instance & config metadata.
3.Enable Public Access to Instance.
4.Check executing the startup script.
5.Check the URL and address.
echo '#!/bin/bash
apt-get update
apt-get install -y apache2' > resource-install-web.sh
Prepare Apache Installation Script
gsutil mb gs://BUCKET_NAME/
gsutil cp resources-install-web.sh gs://BUCKET_NAME
create bucket, Replace BUCKET_NAME with project Id
create script file contains installation commands
copy startup script to bucket
BUCKET_NAME must be the same as first line
Create Machine
gcloud compute instances create apache 
--zone=us-central1-a 
--tags=http-server 
--metadata=startup-script-url=gs://$BUCKET_NAME/resource-install-web.sh
Machine name
Machine location
Network tag used to open port later
Script location run once machine start
Tasks
1.Create a Bucket & Upload startup script.
2.Create a Compute Instance & config metadata.
3.Enable Public Access to Instance.
4.Check executing the startup script.
5.Check the URL and address.
Create Firewall
gcloud compute firewall-rules create default-allow-http 
--direction=INGRESS --priority=1000 --network=default 
--action=ALLOW --rules=tcp:80 
--source-ranges=0.0.0.0/0 
--target-tags=http-server
Firewall rule name
Allow http port
From public interent address
Network tag (Same as tag name in create machine command)
Tasks
1.Create a Bucket & Upload startup script.
2.Create a Compute Instance & config metadata.
3.Enable Public Access to Instance.
4.Check executing the startup script.
5.Check the URL and address.
Test Server
gcloud compute instances describe apache
Machine name
Show external Ip and use to browse
Tasks
1.Create a Bucket & Upload startup script.
2.Create a Compute Instance & config metadata.
3.Enable Public Access to Instance.
4.Check executing the startup script.
5.Check the URL and address.
Hope it help :)

Deploy a compute instance with a remote startup script

  • 1.
    Deploy a ComputeInstance with a Remote Startup Script Mahmmoud Mahdi
  • 2.
    Your challenge Configure aLinux Google Compute Engine instance that installs the Apache web server software using a remote startup script. In order to confirm that a compute instance Apache has successfully installed, the Compute Engine instance must be accessible via HTTP from the internet.
  • 3.
    Deploy an Instancewith a Remote Startup Script 1.Create a Bucket & Upload startup script. 2.Create a Compute Instance & config metadata. 3.Enable Public Access to Instance. 4.Check executing the startup script. 5.Check the URL and address.
  • 4.
  • 5.
    Requirement Steps 2. CreateVM Instance and configure metadata 1. Create Startup script and upload to bucket 3. Open firewall port 4. Test Connectivity
  • 6.
  • 7.
    Create a BucketStorage and upload Script file ● Bucket Name: project_id ● File name: resource-install-web.sh
  • 8.
    Create a ComputeInstance ● Name: apache ● Zone: us-central1-a ● Access: Enable Http ● Metadata: startup-script-url
  • 9.
    Test Your Server ●Browse the server External IP ● Make sure it response.
  • 10.
  • 11.
    Tasks 1.Create a Bucket& Upload startup script. 2.Create a Compute Instance & config metadata. 3.Enable Public Access to Instance. 4.Check executing the startup script. 5.Check the URL and address.
  • 12.
    echo '#!/bin/bash apt-get update apt-getinstall -y apache2' > resource-install-web.sh Prepare Apache Installation Script gsutil mb gs://BUCKET_NAME/ gsutil cp resources-install-web.sh gs://BUCKET_NAME create bucket, Replace BUCKET_NAME with project Id create script file contains installation commands copy startup script to bucket BUCKET_NAME must be the same as first line
  • 13.
    Create Machine gcloud computeinstances create apache --zone=us-central1-a --tags=http-server --metadata=startup-script-url=gs://$BUCKET_NAME/resource-install-web.sh Machine name Machine location Network tag used to open port later Script location run once machine start
  • 14.
    Tasks 1.Create a Bucket& Upload startup script. 2.Create a Compute Instance & config metadata. 3.Enable Public Access to Instance. 4.Check executing the startup script. 5.Check the URL and address.
  • 15.
    Create Firewall gcloud computefirewall-rules create default-allow-http --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:80 --source-ranges=0.0.0.0/0 --target-tags=http-server Firewall rule name Allow http port From public interent address Network tag (Same as tag name in create machine command)
  • 16.
    Tasks 1.Create a Bucket& Upload startup script. 2.Create a Compute Instance & config metadata. 3.Enable Public Access to Instance. 4.Check executing the startup script. 5.Check the URL and address.
  • 17.
    Test Server gcloud computeinstances describe apache Machine name Show external Ip and use to browse
  • 18.
    Tasks 1.Create a Bucket& Upload startup script. 2.Create a Compute Instance & config metadata. 3.Enable Public Access to Instance. 4.Check executing the startup script. 5.Check the URL and address.
  • 19.