GCP Compute Engine tutorial: How to set up and configure your first virtual machine
If you 've just switched to Google Cloud Platform (GCP) from AWS, Azure or Aliyun, you're going to love it.
Compute Engine (GCE)
.
As one of the three giants in the cloud, GCP's virtual machine (VM) has a function that allows all operations and developers to call directly:
Silky smooth.
In other cloud vendors, changing the number of CPU cores or memory may take half a day or even buy a new machine, but in GCP, you can customize the configuration at will like pulling a slider, and its global backbone network (Premium Tier) is fast to fly up.
Today's tutorial does not move the official set of hard documentation. We use the most down-to-earth vernacular to take you out of the first GCP VM in your life and complete the most critical basic configuration!
Core concept: before the boot "save money and network" preventive needle
Before you start, there are two GCP unique "hidden rules" you must know first, can help you save a lot of money and time:
Network Service Class (Network Service Tiers): GCP will give you the Premium (high-quality) network by default. Although it is a little more expensive, it goes through Google's own global optical fiber backbone network and is directly connected to the local Google computer room with extremely low latency. If it is not purely to save money and play, it is strongly recommended to keep Premium.
Machine types support customization at any time (Custom Machine): other cloud vendors only have fixed packages (such as 2-core 4G, 4-core 8G). GCP allows you to add memory or CPU alone. Therefore, when you are not sure about the usage at the beginning, choose the smallest configuration first, and then you can "hot upgrade" at any time ".
Phase 1: Build your first VM
First, open and log in to the GCP Console. Click the navigation menu (three bars) in the upper left corner to find
Compute Engine -> VM Instance (VM instances)
. If you are using it for the first time, click Enable API and wait a minute.
Next, click above
Create Instance"
.
1. Basic identity and positioning
Name: Use only lowercase letters, numbers, and hyphens, such as my-first-gcp-vm.
Region (Region) and zone (Zone): * foreign trade/cross-border/European and American business: choose us-central1 (Iowa) or us-east1, because these two areas often have free quota and cheap bandwidth. Asian Business/Taiwan/Hong Kong: Choose asia-east1 with your eyes closed (Changhua, Taiwan). For users in Hong Kong, Taiwan and Asia Pacific, the delay is as low as reading local
Local area network.
2. Machine configuration (see your wallet)
Series (Series): * general test/lightweight web/personal blog: select E2. This is currently the most cost-effective universal series. High load/Large database: Select N2 or N2D.
Machine type (Machine type): The test can use e2-micro(0.25 vCPU, 1GB memory, which is usually within the free quota) or e2-medium(2 vCPU, 4GB memory, more than enough for a small WordPress).
3. Boot disk (boot disk)-easy to step on the pit
The default is usually a Debian system and a standard 10GB balanced permanent disk.
Click Change ".
Operating system: Ubuntu 22.04 LTS or CentOS is recommended for beginners according to habits. Microsoft users choose Windows Server.
Startup disk type: If the budget allows, be sure to change to "SSD persistent disk" or "balanced persistent disk". The default standard disk (HDD) performance is very card, boot or install software will be slow to you doubt life.
4. Firewall (Firewall)
At the bottom of the page, you will see the firewall check box:
Allow HTTP traffic
Allow HTTPS traffic (Allow HTTPS traffic)
💡Old Bird Tip: If this machine is used for source code construction websites (such as Nginx/Apache) or external Web services, tick both boxes. GCP will automatically help you establish the corresponding network security rules, saving you from waiting to manually configure the firewall.
After confirming that it is correct, click at the bottom
Create"
. About 30 seconds, see the green tick, your VM will come to life!
Stage 2: How do you connect to your virtual machine?
When the machine is on, how do you connect it? GCP provides the world's most stupid and powerful connection method.
Method 1: One-click connection of web browser (recommended, most convenient)
On the VM instance list page, find the machine you just built. There is one on the right.
“SSH”
Button.
Click it directly!
GCP will pop up a separate small window to automatically help you generate keys, transfer, and log in directly to the system. You don't need to download any PuTTY, Xshell, or configure SSH keys. As long as there is a browser, you can manage the server anywhere.
Method 2: Bind static IP and connect with your own terminal
If you want to use your own computer's Terminal, iTerm2 or SecureCRT connection, you will find a problem:
Default for GCP
The external IP is dynamic (Ephemeral) and changes as soon as the machine restarts.
We have to fix the IP first:
Click the VM name to enter the details page and find the NIC configuration (Network interfaces).
Click your external IP(External IP), or search for "external IP address (External IP addresses)" directly in the search bar at the top of GCP ".
Change the type of the IP from "temporary (Ephemeral)" to "static (Static)" and give it a name to save.
Now this IP will always belong to you. Next, you just need to use it on your local computer.
gcloud
command-line tool, entering
gcloud compute ssh your instance name
, can enjoy the local connection.
Phase Three: Connect the Network! How do I open a specific port (such as 8888 or 3000)?
The most common crash point for many novices is:
"I installed pagoda panel (8888 port) or Node.js application (3000 port) in the machine, why can't I open it with [external IP:3000] anyway?"
Because GCP blocks all inbound ports except 22, 80 and 443 by default. Want to open up? You need to match
VPC Firewall Rules"
.
Practical operation: release 8888 port
Enter Firewall (Firewall) in the search bar at the top of GCP.
Click Create Firewall Rule ".
Fill in the following golden parameters:
Name: allow-bt-8888 (just take it casually and remember it easily).
Traffic direction: Inbound (Ingress).
Strictly note: Target (Targets) -select "All instances in the network" (this is the most convenient, this rule applies to all your machines).
Source IPv4 ranges: Enter 0.0.0.0/0 (for anyone in the world to be allowed access).
Protocol and port (Protocols and ports): check "specified protocol and port"-> check tcp -> enter 8888 after.
4 clicks
"Create
After the establishment is completed, there is no need to restart the server, and the firewall rules will take effect in real time. At this time you go to the browser input
Http: // your external IP:8888, you can see the web page perfectly!
Summary: Your GCP first step is complete
Congratulations! At this point, you have successfully established your own on GCP
The first virtual machine fixed the public network IP and learned how to control the firewall to release traffic like an old hand.
GCP water is deep inside
Snapshot backups (Snapshots)
,
Instance Templates (Instance templates)
Also
Auto Elastic Expansion (Autoscaling)
They are all very interesting advanced functions after that. But for now, enjoy this high-performance virtual machine hosted by Google's top computer room for you!
